Notion集成服务器

一个用于Notion集成的模型上下文协议服务器,允许Claude和其他LLM与您的Notion工作区进行交互。

  • by SAhmadUmass
  • TypeScript
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 SAhmadUmass/notion-mcp-server

使用说明

MCP服务器概念

用于Notion集成的模型上下文协议服务器,允许Claude和其他LLM与您的Notion工作区进行交互。

特性

  • 搜索理念:在整个Notion工作区中搜索
  • 获取页面:从特定的Notion页面检索内容
  • 创建页面:在Notion工作区中创建新页面
  • 更新页面:用新内容或标题更新现有页面
  • 创建数据库:创建具有自定义属性的新数据库
  • 查询数据库:使用筛选器和排序查询数据库
  • 更新数据库条目:更新数据库条目的属性
  • 创建数据库行:使用自定义属性向现有数据库添加新行

设置

  1. 克隆此存储库

  2. 安装依赖项

    npm install
    
  3. 配置您的Notion API密钥

    • 在中创建集成 Notion开发者门户
    • 复制API密钥
    • 您可以:
      • 编辑 .env 归档并替换 your_notion_api_key_here 使用您的实际API密钥,或
      • 直接在Claude中进行桌面配置(推荐,见下文)
  4. 构建服务器

    npm run build
    
  5. 运行服务器

    npm start
    

使用Claude进行桌面设置

  1. 安装Claude for Desktop(如果尚未安装)

  2. 打开Claude进行桌面应用程序配置:

    • 在 macOS 上: ~/Library/Application Support/Claude/claude_desktop_config.json
    • 如果文件不存在,则创建该文件
  3. 将Notion服务器添加到您的配置中:

    {
      "mcpServers": {
        "notion": {
          "command": "node",
          "args": [
            "/Users/shaheerahmad/Documents/notion-mcp-server/dist/index.js",
            "--notion-api-key=YOUR_ACTUAL_API_KEY_HERE"
          ]
        }
      }
    }
    

    替换:

    • /Users/shaheerahmad/Documents/notion-mcp-server 包含项目目录的完整路径
    • YOUR_ACTUAL_API_KEY_HERE 使用您的实际Notion API密钥
  4. 重新启动桌面版的Claude

使用服务器

连接到Claude for Desktop后,您可以通过向Claude提出以下问题来使用服务器:

  • “在我的Notion工作区中搜索会议笔记”
  • “获取我的项目规划页面的内容”(您需要页面ID)
  • “在Notion中创建一个包含任务列表的新页面”
  • “将ID为1aaada269d1b8003adceda69cf7bcd97的Notion页面更新为内容‘这是要添加到页面的一些新内容。’”
  • “在我的Notion页面中创建ID为1aaada269d1b8003adceda69cf7bcd97的新数据库”
  • “查询ID为1aaada269d1b8003adceda69cf7bcd97的Notion数据库,查找状态为“已完成”的项目”

Claude将根据您的要求自动使用适当的工具。

工具使用示例

搜索理念

Search for "meeting notes" in my Notion workspace

获取页面内容

Get the content of my Notion page with ID 1aaada269d1b8003adceda69cf7bcd97

创建新页面

Create a new page in Notion with title "Weekly Report" and content "This week we accomplished the following tasks..."

更新现有页面

Update my Notion page with ID 1aaada269d1b8003adceda69cf7bcd97 with content "Adding this new information to the page."

您还可以更新标题:

Update my Notion page with ID 1aaada269d1b8003adceda69cf7bcd97 with title "New Title" and content "New content to add."

创建一个新数据库

Create a new database in my Notion page with ID 1aaada269d1b8003adceda69cf7bcd97 with title "Task Tracker" and properties {
  "Task Name": { "title": {} },
  "Status": {
    "select": {
      "options": [
        { "name": "Not Started", "color": "red" },
        { "name": "In Progress", "color": "yellow" },
        { "name": "Completed", "color": "green" }
      ]
    }
  },
  "Priority": {
    "select": {
      "options": [
        { "name": "Low", "color": "blue" },
        { "name": "Medium", "color": "yellow" },
        { "name": "High", "color": "red" }
      ]
    }
  },
  "Due Date": { "date": {} }
}

查询数据库

Query my Notion database with ID 1aaada269d1b8003adceda69cf7bcd97 with filter {
  "property": "Status",
  "select": {
    "equals": "Completed"
  }
}

您还可以添加排序:

Query my Notion database with ID 1aaada269d1b8003adceda69cf7bcd97 with sort {
  "property": "Due Date",
  "direction": "ascending"
}

更新数据库条目

更新现有数据库条目的属性(数据库中的页面)。

{
  "tool_name": "update-database-entry",
  "tool_params": {
    "pageId": "page_id_of_database_entry",
    "properties": {
      "Status": {
        "select": {
          "name": "Completed"
        }
      },
      "Priority": {
        "select": {
          "name": "High"
        }
      },
      "Due Date": {
        "date": {
          "start": "2023-12-31"
        }
      }
    }
  }
}

这 properties 参数应与Notion API为数据库中的特定属性类型所期望的结构匹配。不同的属性类型(文本、选择、日期等)需要不同的格式。

创建数据库行

向具有自定义属性的现有数据库添加新行。

{
  "tool_name": "create-database-row",
  "tool_params": {
    "databaseId": "your_database_id_here",
    "properties": {
      "Name": {
        "title": [
          {
            "text": {
              "content": "New Task"
            }
          }
        ]
      },
      "Status": {
        "select": {
          "name": "Not Started"
        }
      },
      "Priority": {
        "select": {
          "name": "Medium"
        }
      },
      "Due Date": {
        "date": {
          "start": "2023-12-15"
        }
      },
      "Notes": {
        "rich_text": [
          {
            "text": {
              "content": "This is a new task created via the API"
            }
          }
        ]
      }
    }
  }
}

这 properties 参数必须包括数据库所需的所有属性,并遵循每个属性类型的Notion API结构。

故障排除

  • 如果工具未显示,请检查Claude的桌面日志:

    tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
    
  • 请确保您的Notion API密钥设置正确,并且您的集成已被授予访问要交互的页面的权限。

  • 如果您在日志中看到“意外令牌”错误,则很可能是console.log语句干扰了MCP协议。此版本的服务器已更新以避免这些问题。

未来改进

  • 添加数据库查询功能
  • 实现更好的内容格式
  • 添加对更多块类型的支持