使用说明
MCP服务器概念
[!注意] 对于本地使用Cursor、Claude Desktop等,最好使用 官方公告MCP服务器。但截至2025年5月,它目前不支持SSE和可流式传输的HTTP。此仓库旨在为mcp服务器提供SSE和可流式传输的HTTP。
该项目为Notion API实现了一个模型上下文协议(MCP)服务器,支持服务器-事件(SSE)和流式HTTP传输机制。它允许AI助手和其他应用程序以标准化的方式与Notion工作区进行交互。
特性
- 实施模型上下文协议(MCP)版本2024-11-05
- 服务器发送事件(SSE):
/sse - 流式HTTP:
/mcp
- 服务器发送事件(SSE):
- 通过MCP工具提供对Notion API功能的访问
- 与Claude、Cursor和其他MCP客户端兼容
可用工具:服务器将以下Notion API功能作为MCP工具公开:
notion_retrieve_page:按ID检索通知页面notion_search:在Notion中搜索页面notion_create_page:在Notion中创建新页面notion_update_page:更新Notion中的现有页面notion_create_comment:在页面或块上创建评论
用法
使用Docker镜像
您可以快速开始使用预构建的Docker镜像:
-
创建一个
.env使用您的Notion凭据文件:NOTION_TOKEN=your_notion_integration_token NOTION_VERSION=2022-06-28 -
运行Docker容器:
docker run -p 3000:3000 --env-file .env nakamasato/notion-mcp-server:0.1.3 -
配置您的MCP客户端以连接到服务器:
例子: 光标AI:
{ "mcpServers": { "notion": { "url": "http://localhost:3000/sse" } } }有关Claude Desktop、Zed和其他客户端的更详细配置说明,请参阅 客户端配置示例.md 文件。
本地跑
先决条件
- Node.js 20或更高版本
- Notion集成令牌(从以下位置获取 概念整合)
- 与您的Notion集成共享的页面或数据库
安装
-
克隆此存储库:
git clone https://github.com/nakamasato/notion-mcp-server.git cd notion-mcp-server -
安装依赖项:
npm install -
将您的Notion API凭据设置为环境变量:
export NOTION_TOKEN="your_notion_integration_token" export NOTION_VERSION="2022-06-28"
运行服务器
对于自动重新加载的开发:
npm run dev
对于直接执行TypeScript(建议用于本地开发):
npx tsx src/index.ts
默认情况下,服务器在端口3000上运行。您可以通过以下方式对此进行自定义 PORT 环境变量。
使用Docker运行
- 启动服务器:
docker compose up
要停止服务器,请执行以下操作:
docker compose down
除非明确停止,否则服务器将自动重新启动。
客户端配置
光标
集 .cursor/mcp.json
{
"mcpServers": {
"notion": {
"url": "http://localhost:3000/sse"
}
}
}
python
import asyncio
from mcp import ClientSession
from mcp.client.sse import sse_client
async def list_tools_with_sse():
async with sse_client(url="http://localhost:3000/sse", timeout=10, sse_read_timeout=10) as (read_stream, write_stream):
async with ClientSession(read_stream, write_stream) as session:
await session.initialize()
tools = await session.list_tools()
print(f"Available tools ({len(tools.tools)}):")
for tool in tools.tools:
print(f"- name: {tool.name}, description: {tool.description}, schema: {tool.inputSchema}")
if __name__ == "__main__":
asyncio.run(list_tools_with_sse())
uv run python tools/mcp_client.py
Available tools (5):
- name: notion_retrieve_page, description: Retrieves a Notion page by its ID, schema: {'type': 'object', 'properties': {'page_id': {'type': 'string', 'description': 'The ID of the page to retrieve'}}, 'required': ['page_id'], 'additionalProperties': False, '$schema': 'http://json-schema.org/draft-07/schema#'}
- name: notion_search, description: Searches for pages in Notion, schema: {'type': 'object', 'properties': {'query': {'type': 'string', 'description': 'The search query'}, 'filter': {'type': 'object', 'properties': {}, 'additionalProperties': False, 'description': 'Optional filter for search results'}, 'sort': {'type': 'object', 'properties': {}, 'additionalProperties': False, 'description': 'Optional sort for search results'}}, 'required': ['query'], 'additionalProperties': False, '$schema': 'http://json-schema.org/draft-07/schema#'}
- name: notion_create_page, description: Creates a new page in Notion, schema: {'type': 'object', 'properties': {'parent': {'type': 'object', 'properties': {}, 'additionalProperties': False, 'description': 'The parent of the page'}, 'properties': {'type': 'object', 'properties': {}, 'additionalProperties': False, 'description': 'The properties of the page'}, 'children': {'type': 'array', 'description': 'The content of the page'}}, 'required': ['parent'], 'additionalProperties': False, '$schema': 'http://json-schema.org/draft-07/schema#'}
- name: notion_update_page, description: Updates a page in Notion, schema: {'type': 'object', 'properties': {'page_id': {'type': 'string', 'description': 'The ID of the page to update'}, 'properties': {'type': 'object', 'properties': {}, 'additionalProperties': False, 'description': 'The properties to update'}}, 'required': ['page_id', 'properties'], 'additionalProperties': False, '$schema': 'http://json-schema.org/draft-07/schema#'}
- name: notion_create_comment, description: Creates a comment in Notion, schema: {'type': 'object', 'properties': {'parent': {'type': 'object', 'properties': {}, 'additionalProperties': False, 'description': 'The parent of the comment'}, 'rich_text': {'type': 'array', 'description': 'The content of the comment'}}, 'required': ['parent', 'rich_text'], 'additionalProperties': False, '$schema': 'http://json-schema.org/draft-07/schema#'}
阅读更多: 客户端配置示例
参考文献
- https://www.npmjs.com/package/@模型上下文协议/sdk
- https://modelcontextprotocol.io/quickstart/server#node
- https://github.com/modelcontextprotocol/quickstart-resources/tree/main/weather-server-typescript
- https://azukiazusa.dev/blog/mcp-server-streamable-http-transport/
- https://github.com/modelcontextprotocol/typescript-sdk/tree/main/src/examples
许可证
麻省理工学院
