Notion API 集成工具

一个用于设置和管理Notion API密钥、权限及Python脚本运行的工具,适用于开发者和团队协作场景。

  • by grainne-b
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 grainne-b/notion_mcp_server

使用说明

设置通知API密钥和权限

创建Notion API密钥

  1. 转到Notion集成:

  2. 创建新集成:

    • 单击“新建集成”,填写集成名称等必填字段,然后选择要连接的工作区。
  3. 保存集成:

    • 填写详细信息后,单击“提交”以创建集成。将为您提供一个API密钥。
  4. 复制API密钥:

    • 复制API密钥并将其安全存储。您将使用此密钥对Notion API的请求进行身份验证。

授予页面使用集成的权限

  1. 开放理念:

    • 导航到要授予权限的页面。
  2. 分享页面:

    • 点击页面右上角的“分享”按钮。
  3. 邀请集成:

    • 在“邀请”字段中,键入集成的名称,然后从下拉列表中选择它。这将使集成人员能够访问该页面。
  4. 设置权限:

    • 确保集成具有执行所需操作所需的权限(例如读取、写入)。

代码更新

在……里面 notion_sdk.py ,用上面创建的页面的PAGE_ID更新PAGE_ID。 可以通过复制页面链接来检索页面id

设置 uv 对于Python

  1. 安装 uv 使用Homebrew:

    • 确保您的系统上安装了Homebrew。
    • 运行以下命令进行安装 uv:
      brew install uv
      
  2. 验证安装:

    • 检查是否 uv 通过运行以下命令正确安装:
      uv --version
      
  3. 基本用法:

    • 您可以使用以下命令运行Python脚本 uv 与:
      uv run <your_script.py>
      

通知父页面id

https://www.notion.so/MCP-Parent-Page-1d21f7216bdb80789f88fccd964b5031

卷曲示例

curl --location --request POST 'https://api.notion.com/v1/pages' \
--header 'Authorization: Bearer $NOTION_API_KEY' \
--header 'Content-Type: application/json' \
--header 'Notion-Version: 2021-05-13' \
--data '{
"parent": { "page_id": "1d21f7216bdb80789f88fccd964b5031" },
"properties": {
    "title": [
        {
            "text": {
                "content": "Curl example"
            }
        }
    ]
}
}'

备注

在Claude中安装时,需要对密钥进行硬编码

如何跑步

uv run mcp dev server.py

在Claude中使用

uv run mcp install server.py

将添加到 claude_desktop_config.json

{
  "mcpServers": {
    "Notion MCP Server": {
      "command": "uv",
      "args": [
        "run",
        "mcp",
        "run",
        "/Users/UBHREGR/Documents/repos/experiments/notion_mcp_server/server.py"
      ],
      "env": {
        "NOTION_API_KEY": "REPLACE_ME"
      }
    }
  }
}
{
  "mcpServers": {
    "Notion MCP Server": {
"command": "bash",
"args": [
  "-c",
  "source /Users/UBHREGR/Documents/repos/experiments/notion_mcp_server/.venv/bin/activate && uv run mcp run /Users/UBHREGR/Documents/repos/experiments/notion_mcp_server/server.py"
      ],
      "env": {
        "NOTION_API_KEY": "TODO"
      }
    }
  }
}

Notion软件包

notion-client

提示LLM创建文档字符串

I am building an MCP (Model Context Protocol) server in Python.
The functions I provide will be registered as tools using @mcp.tool() from FastMCP.

Please generate a concise and informative docstring for each function I give you, following this structure:
	•	A one-line summary describing the function’s purpose.
	•	A section called Args: listing each argument with its type and purpose.
	•	A section called Returns: describing the return value and its type.

The docstring should help both humans and LLMs understand how and when to use the tool.