内容
# Notion MCP 服务器
一款提供与 Notion 无缝集成的模型上下文协议(MCP)服务器。该服务器使语言模型能够通过标准化的工具与您的 Notion 工作空间交互,用于搜索、读取、创建和更新页面和数据库。
## 🌟 主要功能
### 页面操作
- 🔍 搜索您的 Notion 工作空间
- 📝 创建包含丰富 Markdown 内容的新页面
- 📖 读取页面内容,格式清晰
- 🔄 更新现有页面
- 💬 添加和检索评论
- 🧱 块级操作(更新、删除)
### 增强的 Markdown 支持
- 多个标题级别(H1-H3)
- 支持语言的代码块
- 带有复选框状态的交互式待办事项
- 支持多行的块引用
- 水平分隔符
- 带标题的图像
- 嵌套的项目符号
### 数据库操作
- 创建和管理数据库
- 添加和更新数据库项目
- 使用筛选器和排序查询
- 支持各种属性类型:
- 标题、富文本、数字
- 选择、多选
- 日期、复选框
- 更多!
## 🚀 快速入门
### 先决条件
- Node.js(v16 或更高版本)
- Notion API 密钥
- MCP 兼容的客户端(例如 Claude Desktop)
### 安装
1. 克隆仓库:
```bash
git clone https://github.com/v-3/notion-server.git
cd notion-server
```
2. 安装依赖项:
```bash
npm install
```
3. 设置环境:
```bash
# 创建 .env 文件
echo "NOTION_API_KEY=您的 Notion API 密钥" > .env
# 或直接导出
export NOTION_API_KEY=您的 Notion API 密钥
```
4. 构建服务器:
```bash
npm run build
```
## 🔧 配置
### Claude Desktop 设置
1. 更新您的 Claude Desktop 配置(`claude_desktop_config.json`):
```json
{
"mcpServers": {
"notion": {
"command": "node",
"args": ["/绝对路径/to/notion-server/build/index.js"],
"env": {
"NOTION_API_KEY": "您的 Notion API 密钥"
}
}
}
}
```
2. 重启 Claude Desktop 以应用更改
## 🛠️ 可用工具
### 页面操作
```typescript
// 搜索页面
{
query: string // 搜索查询
}
// 读取页面
{
pageId: string // 要读取的页面 ID
}
// 创建页面
{
title?: string, // 页面标题
content?: string, // Markdown 页面内容
parentPageId: string // 父页面 ID
properties?: object // 用于数据库项目
}
// 更新页面
{
pageId: string, // 要更新的页面 ID
content: string, // 新内容
type?: string // 内容类型
}
```
### 数据库操作
```typescript
// 创建数据库
{
parentPageId: string,
title: string,
properties: object
}
// 查询数据库
{
databaseId: string,
filter?: object,
sort?: object
}
```
## 🔐 设置 Notion 访问权限
### 创建集成
1. 访问 [Notion 集成](https://www.notion.so/my-integrations)
2. 点击“新建集成”
3. 配置权限:
- 内容:读取、更新、插入
- 评论:读取、创建
- 用户信息:读取
### 连接页面
1. 打开您的 Notion 页面
2. 点击“…“菜单 → “连接”
3. 添加您的集成
4. 根据需要为其他页面重复此操作
## 📝 使用示例
### 创建页面
```typescript
const result = await notion.create_page({
parentPageId: "页面 ID",
title: "我的页面",
content: "# 欢迎\n这是一个测试页面。",
});
```
### 查询数据库
```typescript
const result = await notion.query_database({
databaseId: "数据库 ID",
filter: {
property: "状态",
select: {
equals: "进行中"
}
}
});
```
## 🤝 贡献
欢迎贡献!请:
1. 分叉仓库
2. 创建一个功能分支
3. 提交拉取请求
## 📜 许可证
该项目在 MIT 许可证下许可 - 参见 [LICENSE](LICENSE) 文件了解详情。
## 🙏 致谢
该项目得到了 [sweir1/notion-server](https://github.com/sweir1/notion-server) 的显著改进,他们做出了以下更新:
- 增强了对更多块类型的 Markdown 支持
- 全面的数据库操作
- 改进的错误处理和调试
- 更好的数据库项目属性处理
- 更干净的页面输出格式
要使用 sweir1 的版本,您可以克隆他们的仓库:
```bash
git clone https://github.com/sweir1/notion-server.git
```