详细介绍
Notion MCP 服务器是一个连接语言模型(LLM)与Notion工作区的中间件服务,通过Markdown转换显著减少与LLM交互时的令牌消耗。它支持页面管理、数据库查询、评论创建等核心功能,适用于需要高效操作Notion数据库、页面、评论等内容的开发者和团队。
核心功能
Notion MCP 服务器提供了丰富的功能,涵盖Notion API的多个方面,包括:
- 页面管理:支持创建、更新、删除Notion页面。
- 数据库交互:支持查询、创建、更新、删除数据库项,并支持复杂条件过滤、排序和分页。
- 用户操作:可获取当前用户、所有用户及bot用户信息。
- 评论处理:支持在页面或块中创建、查询、更新和删除评论。
- 批量操作:支持批量创建、更新和删除页面或数据库项。
- 事件监听:可监听页面或数据库的变化并触发预设操作。
- 日志记录:记录所有API调用日志,提供详细的错误报告。
安装方法
安装Notion MCP 服务器需要先安装依赖项,并克隆仓库到本地。
pip install python-dotenv requestsgit clone https://github.com/your-username/notion-mcp.git
cd notion-mcp配置说明
配置文件为 `config.env`,需包含以下内容:
NOTI
PORT=指定的端口(默认为5000)使用方法
启动服务器后,可通过HTTP API调用Notion功能。以下是一些常见用法示例:
1. 创建页面
POST /api/create_page
Content-Type: application/json
{
"parent": {
"database_id": "09d4db7b-xxxx-xxxx-xxxx-c86ab25ef5cf"
},
"properties": {
"Name": {
"title": [
{
"text": {
"content": "新页面标题"
}
}
]
}
},
"children": []
}2. 更新页面
PUT /api/update_page?id=14f5d08c-xxxx-xxxx-xxxx-d9e6b534a7cd
Content-Type: application/json
{
"properties": {
"Name": {
"title": [
{
"text": {
"content": "更新后的页面标题"
}
}
]
}
},
"children": []
}3. 删除页面
DELETE /api/delete_page?id=14f5d08c-xxxx-xxxx-xxxx-d9e6b534a7cd4. 查询数据库
POST /api/query_database?database_id=09d4db7b-xxxx-xxxx-xxxx-c86ab25ef5cf
Content-Type: application/json
{
"filter": {
"property": "Status",
"value": {
"status": {
"equals": "完成"
}
}
},
"sorts": [
{
"property": "创建时间",
"direction": "descending"
}
],
"start_cursor": "",
"page_size": 10
}5. 创建数据库项
POST /api/create_database_item?database_id=09d4db7b-xxxx-xxxx-xxxx-c86ab25ef5cf
Content-Type: application/json
{
"properties": {
"Name": {
"title": [
{
"text": {
"content": "新数据库项"
}
}
]
},
"Status": {
"select": {
"name": "完成"
}
}
},
"children": []
}6. 获取用户信息
GET /api/get_user_info7. 创建评论
POST /api/create_comment
Content-Type: application/json
{
"parent": {
"page_id": "14f5d08c-xxxx-xxxx-xxxx-d9e6b534a7cd"
},
"properties": {},
"children": [
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{
"type": "text",
"text": {
"content": "这是一个新评论。"
}
}
]
}
}
]
}8. 获取评论
GET /api/get_comments?page_id=14f5d08c-xxxx-xxxx-xxxx-d9e6b534a7cd注意事项
使用Notion MCP 服务器时,请注意以下事项:
- 确保你拥有有效的Notion令牌。
- 配置文件中的PORT可以根据需要进行调整。
- 确保服务器运行时网络连接正常。
- 定期检查依赖库的更新,以保持最佳性能和安全性。
- 确保你拥有正确的权限来执行这些操作。
- 遵守Notion的API使用政策和限制。
- 定期检查和更新依赖库以保持安全性和兼容性。
Notion MCP 服务器通过Markdown转换优化LLM交互效率,同时提供丰富的API接口,使开发者能够高效管理Notion内容。