Mcp Notion Server

Mcp Notion Server

🚀 Notion MCP 服务器

Notion MCP 服务器是一个用于与 Notion 进行交互的工具,它提供了丰富的功能,如页面管理、数据库交互等,方便用户对 Notion 数据进行操作。

🚀 快速开始

安装指南

安装依赖

运行以下命令安装所需的依赖项:

pip install python-dotenv requests

克隆仓库

使用 Git 克隆此仓库:

git clone https://github.com/your-username/notion-mcp.git
cd notion-mcp

配置

获取配置文件

创建一个名为 config.env 的新文件,并添加以下内容:

NOTION_TOKEN=你的Notion令牌
PORT=指定的端口(默认为5000)

运行服务器

运行主脚本以启动 MCP 服务器:

python3 mcp_server.py

注意事项

⚠️ 重要提示

  • 确保你拥有有效的 Notion 令牌。
  • 配置文件中的 PORT 可以根据需要进行调整。
  • 确保服务器运行时网络连接正常。
  • 定期检查依赖库的更新,以保持最佳性能和安全性。
  • 确保你拥有正确的权限来执行这些操作。
  • 遵守 Notion 的 API 使用政策和限制。
  • 定期检查和更新依赖库以保持安全性和兼容性。

✨ 主要特性

基本功能

  1. 页面管理

    • 创建新页面
    • 更新现有页面
    • 删除指定页面
  2. 数据库交互

    • 查询数据库项
    • 创建新数据库项
    • 更新数据库项
    • 删除数据库项
  3. 用户操作

    • 获取当前用户信息
    • 获取所有用户信息
    • 获取当前 bot 用户信息
  4. 评论处理

    • 在页面或块中创建评论
    • 查询指定页面的评论
    • 更新或删除评论

扩展功能

  1. 批量操作

    • 批量创建页面或数据库项
    • 批量更新属性
    • 批量删除操作
  2. 高级查询

    • 复杂条件过滤
    • 排序和分页
    • 关联查询(如通过数据库关系)
  3. 事件监听

    • 监听页面或数据库变化的实时事件
    • 自动触发预设操作
  4. 日志记录

    • 记录所有 API 调用的日志
    • 提供详细的错误报告

💻 使用示例

基础用法

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-d9e6b534a7cd

4. 查询数据库

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_info

7. 创建评论

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

高级用法

由于原文档未明确高级用法相关代码示例,此处暂不提供。

📄 许可证

本项目遵循 MIT 协议。请查阅 LICENSE 文件获取详细信息。


感谢使用我们的 MCP 服务器!如有任何问题,请随时联系支持团队。

  • 0 关注
  • 0 收藏,7 浏览
  • system 提出于 2025-09-18 06:27

相似服务问题