Notion模型上下文协议服务器

Notion MCP Server是一个基于Python和FastMCP构建的模型上下文协议服务器,用于与Notion工作空间进行交互,提供搜索、数据库操作、页面管理等功能。

  • by Nexauraholding
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Billythek/notion-mcp

使用说明

MCP服务器概念

用于与Notion工作区交互的模型上下文协议(MCP)服务器。使用Python和FastMCP构建。

特征

  • 搜索:跨页面和数据库的全局搜索
  • 数据库:查询、创建条目、获取架构
  • 页面:创建、读取、更新、存档页面
  • 积木:读取并附加内容块
  • 用户:列出工作区用户

安装

pip install -r requirements.txt

配置

  1. 在以下位置创建Notion集成 developers.notion.com
  2. 复制API密钥
  3. 设置环境变量:
export NOTION_API_KEY=secret_xxxxx

或者创建一个 .env 文件:

NOTION_API_KEY=secret_xxxxx
  1. 在Notion中与您的集成共享页面/数据库(设置>连接)

用法

作为MCP服务器

python server.py

Claude桌面配置

增添 claude_desktop_config.json:

{
  "mcpServers": {
    "notion": {
      "command": "python",
      "args": ["/path/to/notion-mcp/server.py"],
      "env": {
        "NOTION_API_KEY": "secret_xxxxx"
      }
    }
  }
}

可用工具

工具 说明
notion_search 搜索页面和数据库
notion_list_databases 列出所有可访问的数据库
notion_get_database_schema 获取数据库属性
notion_query_database 使用筛选器和排序进行查询
notion_create_database_entry 创建新条目
notion_get_page 获取页面属性
notion_get_page_content 获取页面块
notion_create_page 创建新页面
notion_update_page 更新页面属性
notion_archive_page 存档页面
notion_append_blocks 添加内容块
notion_append_text 简单文本附加
notion_get_users 列出工作区用户
notion_whoami 获取机器人信息
notion_build_filter 构建JSON过滤器的助手

例子

查询数据库

# Using the MCP tool
notion_query_database(
    database_id="abc123...",
    filter_json='{"property": "Status", "status": {"equals": "Done"}}',
    limit=10
)

创建页面

notion_create_page(
    parent_id="abc123...",
    title="My New Page",
    parent_type="page_id"
)

附加内容

notion_append_text(
    page_id="abc123...",
    text="Hello World!",
    block_type="paragraph"
)

许可证

麻省理工学院