Notion MCP 服务器
一个 Notion API 的 MCP 服务器,实现 LLM 与 Notion 工作区的交互。此外,它采用 Markdown 转换来减少与 LLM 通信时的上下文大小,优化令牌使用,使交互更高效。
设置
详细步骤见以下文章:
- 英文版:https://dev.to/suekou/operating-notion-via-claude-desktop-using-mcp-c0h
- 日文版:https://qiita.com/suekou/items/44c864583f5e3e6325d9
-
创建 Notion 集成:
- 访问 Notion 集成页面。
- 点击 "新建集成"。
- 为集成命名并选择适当权限(例如:"读取内容"、"更新内容")。
-
获取密钥:
- 从集成页面复制 "内部集成令牌"。
- 该令牌用于身份验证。
-
将集成添加到工作区:
- 打开 Notion 中需要集成访问的页面或数据库。
- 点击页面右上角的 "···" 按钮。
- 点击 "连接" 按钮,并选择你在第 1 步创建的集成。
-
配置 Claude Desktop: 将以下内容添加到
claude_desktop_config.json
:
{
"mcpServers": {
"notion": {
"command": "npx",
"args": ["-y", "@suekou/mcp-notion-server"],
"env": {
"NOTION_API_TOKEN": "your-integration-token"
}
}
}
}
或者
{
"mcpServers": {
"notion": {
"command": "node",
"args": ["your-built-file-path"],
"env": {
"NOTION_API_TOKEN": "your-integration-token"
}
}
}
}
环境变量
NOTION_API_TOKEN
(必需):你的 Notion API 集成令牌。NOTION_MARKDOWN_CONVERSION
:设置为 "true" 启用实验性的 Markdown 转换,这可以显著减少查看内容时的令牌消耗,但在编辑页面内容时可能会出现问题。
命令行参数
--enabledTools
:启用工具的逗号分隔列表(例如:"notion_retrieve_page,notion_query_database")。指定时,仅列出的工具可用。如果未指定,则启用所有工具。
只读工具示例(可复制粘贴):
node build/index.js --enabledTools=notion_retrieve_block,notion_retrieve_block_children,notion_retrieve_page,notion_query_database,notion_retrieve_database,notion_search,notion_list_all_users,notion_retrieve_user,notion_retrieve_bot_user,notion_retrieve_comments
高级配置
Markdown 转换
默认情况下,所有响应都以 JSON 格式返回。你可以启用实验性的 Markdown 转换来减少令牌消耗:
{
"mcpServers": {
"notion": {
"command": "npx",
"args": ["-y", "@suekou/mcp-notion-server"],
"env": {
"NOTION_API_TOKEN": "your-integration-token",
"NOTION_MARKDOWN_CONVERSION": "true"
}
}
}
}
或者
{
"mcpServers": {
"notion": {
"command": "node",
"args": ["your-built-file-path"],
"env": {
"NOTION_API_TOKEN": "your-integration-token",
"NOTION_MARKDOWN_CONVERSION": "true"
}
}
}
}
当
NOTION_MARKDOWN_CONVERSION
设置为 "true" 时,响应将转换为 Markdown 格式(当 format
参数设置为 "markdown" 时),使其更易读并显著减少令牌消耗。然而,由于此功能为实验性,尝试编辑页面内容时可能会出现问题。你可以按请求设置
format