Notion MCP Server 是一个用于 Notion API 的服务器,它能让大语言模型(LLM)与 Notion 工作空间进行交互。此外,该服务器采用 Markdown 转换技术,在与大语言模型通信时减少上下文大小,优化令牌使用,使交互更加高效。
以下文章详细解释了上述步骤:
该项目有以下特性:
claude_desktop_config.json
文件中添加以下内容:{
"mcpServers": {
"notion": {
"command": "npx",
"args": ["-y", "@kimjungyeol/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
{
"mcpServers": {
"notion": {
"command": "npx",
"args": ["-y", "@kimjungyeol/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_MARKDOWN_CONVERSION": "true"
}
}
}
}
当 NOTION_MARKDOWN_CONVERSION
设置为 "true"
时,响应将转换为 Markdown 格式(当 format
参数设置为 "markdown"
时),这使得响应更易于阅读,并显著减少令牌消耗。但是,由于此功能是实验性的,在尝试编辑页面内容时可能会导致问题,因为转换过程中会丢失原始结构。
你可以在每次请求时通过将 format
参数设置为 "json"
或 "markdown"
来控制格式:
"markdown"
以获得更好的可读性。"json"
。如果你遇到权限错误:
claude_desktop_config.json
中正确设置。项目采用模块化方式组织,以提高可维护性和可读性:
./
├── src/
│ ├── index.ts # 入口点和命令行处理
│ ├── client/
│ │ └── index.ts # 用于 API 交互的 NotionClientWrapper 类
│ ├── server/
│ │ └── index.ts # MCP 服务器设置和请求处理
│ ├── types/
│ │ ├── index.ts # 类型导出
│ │ ├── args.ts # 工具参数接口
│ │ ├── common.ts # 通用模式定义
│ │ ├── responses.ts # API 响应类型定义
│ │ └── schemas.ts # 工具模式定义
│ ├── utils/
│ │ └── index.ts # 实用函数
│ └── markdown/
│ └── index.ts # Markdown 转换实用工具
所有工具都支持以下可选参数:
format
(字符串,"json" 或 "markdown",默认:"markdown"):控制响应格式。使用 "markdown" 以获得人类可读的输出,使用 "json" 以编程方式访问原始数据结构。注意:Markdown 转换仅在 NOTION_MARKDOWN_CONVERSION
环境变量设置为 "true" 时有效。notion_append_block_children
block_id
(字符串):父块的 ID。children
(数组):要追加的块对象数组。notion_retrieve_block
block_id
(字符串):要检索的块的 ID。notion_retrieve_block_children
block_id
(字符串):父块的 ID。start_cursor
(字符串):下一页结果的游标。page_size
(数字,默认:100,最大:100):要检索的块数。notion_delete_block
block_id
(字符串):要删除的块的 ID。notion_retrieve_page
page_id
(字符串):要检索的页面的 ID。notion_update_page_properties
page_id
(字符串):要更新的页面的 ID。properties
(对象):要更新的属性。notion_create_database
parent
(对象):数据库的父对象。properties
(对象):数据库的属性模式。title
(数组):数据库的标题,以富文本数组形式表示。notion_query_database
database_id
(字符串):要查询的数据库的 ID。filter
(对象):过滤条件。sorts
(数组):排序条件。start_cursor
(字符串):下一页结果的游标。page_size
(数字,默认:100,最大:100):要检索的结果数。notion_retrieve_database
database_id
(字符串):要检索的数据库的 ID。notion_update_database
database_id
(字符串):要更新的数据库的 ID。title
(数组):数据库的新标题。description
(数组):数据库的新描述。properties
(对象):更新后的属性模式。notion_create_database_item
database_id
(字符串):要添加项的数据库的 ID。properties
(对象):新项的属性。这些属性应与数据库模式匹配。notion_search
query
(字符串):在页面或数据库标题中搜索的文本。filter
(对象):将结果限制为仅页面或仅数据库的条件。sort
(对象):对结果进行排序的条件。start_cursor
(字符串):分页起始游标。page_size
(数字,默认:100,最大:100):要检索的结果数。notion_list_all_users
notion_retrieve_user
notion_retrieve_bot_user
notion_create_comment
page_id
的 parent
对象,要么指定 discussion_id
,但不能同时指定两者。rich_text
(数组):表示评论内容的富文本对象数组。parent
(对象):如果使用,必须包含 page_id
。discussion_id
(字符串):现有的讨论线程 ID。notion_retrieve_comments
block_id
(字符串):要检索其评论的块或页面的 ID。start_cursor
(字符串):分页起始游标。page_size
(数字,最大:100):要检索的评论数。此 MCP 服务器采用 MIT 许可证。这意味着你可以自由使用、修改和分发该软件,但需遵守 MIT 许可证的条款和条件。有关更多详细信息,请参阅项目仓库中的 LICENSE 文件。