Notion API MCP Server

by pbohannon
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Provides advanced todo list management and content organization capabilities through Notion's API, including task management, database operations, content structuring, and real-time integration with Notion's workspace, pages, and databases.

Notion API MCP

模型上下文协议 (MCP) 服务器,通过 Notion 的 API 提供高级待办事项列表管理和内容组织功能。MCP 使 AI 模型能够与外部工具和服务交互,从而实现与 Notion 强大功能的无缝集成。

MCP 概述

基于 Python 的 MCP 服务器,使 AI 模型能够与 Notion 的 API 进行交互,提供:

  • 待办事项管理:使用富文本、截止日期、优先级和嵌套子任务创建、更新和跟踪任务
  • 数据库操作:使用自定义属性、过滤器和视图创建和管理 Notion 数据库
  • 内容组织:使用 Markdown 支持、分层列表和块操作来构建和格式化内容
  • 实时集成:通过干净的异步实现与 Notion 的工作区、页面和数据库直接交互

完整功能列表 →

快速入门

# Clone and setup git clone https://github.com/yourusername/notion-api-mcp.git cd notion-api-mcp uv venv && source .venv/bin/activate # Install and configure uv pip install -e . cp .env.integration.template .env # Add your Notion credentials to .env: # NOTION_API_KEY=ntn_your_integration_token_here # NOTION_PARENT_PAGE_ID=your_page_id_here # For new databases # NOTION_DATABASE_ID=your_database_id_here # For existing databases # Run the server python -m notion_api_mcp

入门

1. 创建 Notion 集成

  1. 前往https://www.notion.so/my-integrations
  2. 点击“新集成”
  3. 为您的集成命名(例如,“我的 MCP 集成”)
  4. 选择您将使用集成的工作区
  5. 复制“内部集成令牌” - 这将是您的NOTION_API_KEY
    • 应以“ntn_”开头

2. 设置 Notion Access

您需要一个父页面(用于创建新数据库)或一个现有的数据库 ID:

选项 A:新数据库的父页面

  1. 在浏览器中打开 Notion
  2. 创建新页面或打开现有页面以创建数据库
  3. 点击右上角的•••菜单
  4. 选择“添加连接”并选择您的集成
  5. 从 URL 中复制页面 ID - 它是最后一个斜杠之后和问号之前的字符串
    • 例如:在https://notion.so/myworkspace/123456abcdef...中,ID 为123456abcdef...
    • 这将是您的NOTION_PARENT_PAGE_ID

选项 B:现有数据库

  1. 打开您现有的 Notion 数据库
  2. 确保它已连接到您的集成(••• 菜单 > 添加连接)
  3. 从 URL 复制数据库 ID
    • 例如:在https://notion.so/myworkspace/123456abcdef...?v=...中,ID 为123456abcdef...
    • 这将是您的NOTION_DATABASE_ID

3. 安装 MCP 服务器

  1. 创建虚拟环境:
cd notion-api-mcp uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
  1. 安装依赖项:
uv pip install -e .
  1. 配置环境:
cp .env.integration.template .env
  1. 使用您的 Notion 凭证编辑 .env:
NOTION_API_KEY=ntn_your_integration_token_here # Choose one or both of these depending on your needs: NOTION_PARENT_PAGE_ID=your_page_id_here # For creating new databases NOTION_DATABASE_ID=your_database_id_here # For working with existing databases

4.配置Claude桌面

重要提示:虽然服务器支持 .env 文件和环境变量,但 Claude Desktop 特别要求在其配置文件中进行配置才能使用 MCP。

添加到 Claude Desktop 的配置( ~/Library/Application Support/Claude/claude_desktop_config.json ):

{ "mcpServers": { "notion-api": { "command": "/path/to/your/.venv/bin/python", "args": ["-m", "notion_api_mcp"], "env": { "NOTION_API_KEY": "ntn_your_integration_token_here", // Choose one or both: "NOTION_PARENT_PAGE_ID": "your_page_id_here", "NOTION_DATABASE_ID": "your_database_id_here" } } } }

注意:即使您已配置 .env 文件,也必须将这些环境变量添加到 Claude Desktop 配置中,以便 Claude 使用 MCP。.env 文件主要用于本地开发和测试。

文档

发展

该服务器始终使用现代 Python 异步功能:

  • 使用 Pydantic 模型进行类型安全配置
  • 使用 httpx 异步 HTTP 以获得更好的性能
  • 清洁 MCP 集成以公开 Notion 功能
  • 正确的资源清理和错误处理

调试

该服务器包括全面的日志记录:

  • 用于开发的控制台输出
  • 作为服务运行时的文件日志记录
  • 详细错误消息
  • 调试级别的请求/响应日志记录

直接运行时设置PYTHONPATH以包含项目根目录:

PYTHONPATH=/path/to/project python -m notion_api_mcp

未来发展

计划增强的功能:

  1. 性能优化
    • 添加请求缓存
    • 优化数据库查询
    • 实现连接池
  2. 高级功能
    • 多工作区支持
    • 批量操作
    • 实时更新
    • 高级搜索功能
  3. 开发者体验
    • 交互式 API 文档
    • 用于常见操作的 CLI 工具
    • 其他代码示例
    • 性能监控
  4. 测试增强功能
    • 性能基准
    • 负载测试
    • 其他边缘情况
    • 扩展集成测试
-
security - not tested
A
license - permissive license
-
quality - not tested

使用 Notion 的 API 实现高级待办事项列表管理和内容组织,支持创建数据库、动态过滤和协作任务跟踪等功能。

  1. MCP Overview
    1. Quick Start
      1. Getting Started
        1. 1. Create a Notion Integration
        2. 2. Set Up Notion Access
        3. 3. Install the MCP Server
        4. 4. Configure Claude Desktop
      2. Documentation
        1. Development
          1. Debugging
        2. Future Development
          ID: s5mm9e0sr5