Notion API 服务器
参考视频
为了方便使用 Notion API,自定义服务器。它使用 Express.js 实现,并将 Notion API 的各种功能作为 REST API 公开。
Related MCP server: SystemPrompt MCP Notion Server
如何安装
安装所需的软件包:
npm install express cors @notionhq/client swagger-jsdoc swagger-ui-express运行服务器:
node server.js服务器在http://localhost:3000运行。
如何设置
在 server.js 文件中的
NOTION_TOKEN变量中设置 Notion API 令牌:
const NOTION_TOKEN = '여기에_노션_API_토큰_입력';如果需要,您可以通过修改 PORT 变量在不同的端口上运行它。
API 功能
搜索 API
POST /api/search:搜索 Notion 工作区内的页面和数据库。
数据库 API
POST /api/databases:创建数据库GET /api/databases/:id:查询数据库PATCH /api/databases/:id: 更新数据库POST /api/databases/:id/query:数据库查询
页面 API
POST /api/pages:创建页面GET /api/pages/:id:查看页面信息PATCH /api/pages/:id: 更新页面GET /api/pages/:page_id/properties/:property_id:查看页面属性
块 API
GET /api/blocks/:id: 区块查询GET /api/blocks/:id/children:查看区块内容PATCH /api/blocks/:id: 更新区块PATCH /api/blocks/:id/children: 添加块内容DELETE /api/blocks/:id:删除块
用户 API
GET /api/users:查看用户列表GET /api/users/:id:用户搜索GET /api/users/me:查看自己的用户信息
评论API
POST /api/comments:创建评论GET /api/comments?block_id=...: 查看评论
光标 MCP 集成
将以下设置添加到
.cursor/mcp.json文件:
{
"mcpServers": {
"customApi": {
"url": "http://localhost:3000",
"toolNameStrategy": "url-path-segments"
}
}
}您可以在服务器运行时使用 Cursor 中的 MCP 函数访问 Notion API。
使用示例
示例搜索请求
// 페이지 검색
fetch('http://localhost:3000/api/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
filter: {
value: "page",
property: "object"
}
})
})
.then(response => response.json())
.then(data => console.log(data));页面创建示例
// 새 페이지 생성
fetch('http://localhost:3000/api/pages', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
parent: {
page_id: "페이지_ID"
},
properties: {
title: {
title: [
{
text: {
content: "새 페이지 제목"
}
}
]
}
}
})
})
.then(response => response.json())
.then(data => console.log(data));创建数据库的示例
// 데이터베이스 생성
fetch('http://localhost:3000/api/databases', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
parent: {
type: "page_id",
page_id: "페이지_ID"
},
title: [
{
text: {
content: "테스트 데이터베이스"
}
}
],
properties: {
"이름": {
"title": {},
"description": "제목 항목"
},
"상태": {
"description": "작업 상태",
"select": {
"options": [
{
"name": "진행 중",
"color": "blue"
},
{
"name": "완료",
"color": "green"
}
]
}
}
}
})
})
.then(response => response.json())
.then(data => console.log(data));API 文档
运行服务器时,可以在以下 URL 上获取 API 文档:
Swagger 用户界面: http://localhost:3000/api-docs
OpenAPI 模式: http://localhost:3000/openapi.json
This server cannot be installed
Resources
Looking for Admin?
Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to access the admin panel.