Notion MCP服务器

为Notion API实现的MCP服务器,支持通过Server-Sent Events (SSE)进行通信,用于管理和操作Notion内容。

  • by ContexaAI
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 ContexaAI/Notion-MCP-Server-SSE

使用说明

在ContexaAI上部署并在几分钟内开始

重要提示

This repository is a fork of the official Notion MCP server available on NPM.
The primary modification is the replacement of the transport mechanism from Stdio to Server-Sent Events (SSE).

MCP服务器概念

该项目实现了 MCP服务器 为了 API通知.

安装

1.在理念上建立一体化:

首选 https://www.notion.so/profile/integrations 并创建一个新的 内部的 集成或选择一个现有的。

虽然我们限制了Notion API暴露的范围(例如,您将无法通过MCP删除数据库),但将工作空间数据暴露给LLM会带来非零风险。有安全意识的用户可能希望进一步配置集成 能力.

例如,您可以通过仅从“配置”选项卡授予“读取内容”访问权限来创建只读集成令牌:

2.将内容连接到集成:

确保相关页面和数据库已连接到您的集成。

为此,您需要访问该页面,单击3个点,然后选择“连接到集成”。

3.将MCP配置添加到您的客户端:

使用npm:

将以下内容添加到您的 .cursor/mcp.json 或 claude_desktop_config.json (MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json)

{
  "mcpServers": {
    "notionApi": {
      "command": "npx",
      "args": ["-y", "@notionhq/notion-mcp-server"],
      "env": {
        "OPENAPI_MCP_HEADERS": "{\"Authorization\": \"Bearer ntn_****\", \"Notion-Version\": \"2022-06-28\" }"
      }
    }
  }
}
使用Docker:

使用Docker运行MCP服务器有两种选择:

选项1:使用官方Docker Hub镜像:

将以下内容添加到您的 .cursor/mcp.json 或 claude_desktop_config.json:

{
  "mcpServers": {
    "notionApi": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e", "OPENAPI_MCP_HEADERS",
        "mcp/notion"
      ],
      "env": {
        "OPENAPI_MCP_HEADERS": "{\"Authorization\":\"Bearer ntn_****\",\"Notion-Version\":\"2022-06-28\"}"
      }
    }
  }
}

这种方法:

  • 使用官方Docker Hub镜像
  • 通过环境变量正确处理JSON转义
  • 提供更可靠的配置方法
选项2:在本地构建Docker镜像:

您还可以在本地构建和运行Docker镜像。首先,构建Docker镜像:

docker-compose build

然后,将以下内容添加到您的 .cursor/mcp.json 或 claude_desktop_config.json:

{
  "mcpServers": {
    "notionApi": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e",
        "OPENAPI_MCP_HEADERS={\"Authorization\": \"Bearer ntn_****\", \"Notion-Version\": \"2022-06-28\"}",
        "notion-mcp-server"
      ]
    }
  }
}

别忘了更换 ntn_**** 与您的集成秘密。从您的集成配置选项卡中找到它:

例子

  1. 使用以下说明
Comment "Hello MCP" on page "Getting started"

AI将正确地规划两个API调用, v1/search 和 v1/comments,以完成任务

  1. 同样,以下指令将导致一个名为“Notion MCP”的新页面添加到父页面“Development”中
Add a page titled "Notion MCP" to page "Development"
  1. 您也可以直接引用内容ID
Get the content of page 1a6b35e6e67f802fa7e1d27686f017f2

发展

构建

npm run build

执行

npx -y --prefix /path/to/local/notion-mcp-server @notionhq/notion-mcp-server

发布

npm publish --access public