这是一个通过 GraphQL API 与 Wiki.js 集成的 Model Context Protocol (MCP) 服务器。MCP 是由 Anthropic 开发的一个开放协议,使 AI 模型能够安全地与外部服务和工具交互。
该服务器提供了一个统一的接口,用于与 Wiki.js 进行交互,可以被支持 MCP 的各种 AI 代理和工具使用。
⚡ 现在就开始? 请参阅 五分钟指南
git clone https://github.com/heAdz0r/wikijs-mcp-server.git
cd wikijs-mcp-server
npm run setup
此脚本会自动:
example.env 创建 .env 文件.env 文件 并指定您的 Wiki.js 设置:# HTTP MCP 服务器端口
PORT=3200
# Wiki.js 的基础 URL(不带 /graphql)
WIKIJS_BASE_URL=http://localhost:3000
# Wiki.js API 令牌
WIKIJS_TOKEN=your_wikijs_api_token_here
.cursor/mcp.json 文件 并替换 your_wikijs_api_token_here 为您真实的令牌如何获取 Wiki.js API 令牌:
- 登录到 Wiki.js 管理面板
- 前往“API”部分
- 创建一个具有必要权限的新 API 密钥
- 将令牌复制到
.env和.cursor/mcp.json
# 启动主要 HTTP 服务器,支持 Cursor MCP
npm start
# 或
npm run start:http
# 停止服务器
npm run stop
npm run start:typescript
npm run server:stdio
npm run dev
npm test
⚠️ 重要提示: 没有
.cursor/mcp.json文件,Cursor 集成将无法工作!
npm start
npm run setup:cursor
.cursor/mcp.json 并指定您真实的令牌:{
"mcpServers": {
"wikijs": {
"transport": "http",
"url": "http://localhost:3200/mcp",
"events": "http://localhost:3200/mcp/events",
"cwd": ".",
"env": {
"WIKIJS_BASE_URL": "http://localhost:3000",
"WIKIJS_TOKEN": "your_real_wiki_js_token_here"
}
}
}
}
transport: "http" - 必须的 HTTP 传输方式url: "http://localhost:3200/mcp" - JSON-RPC 的确切 URLevents: "http://localhost:3200/mcp/events" - Server-Sent Events 的 URLWIKIJS_TOKEN - 真实的 Wiki.js API 令牌(不是占位符!)设置完成后,带有 mcp_wikijs_* 前缀的工具应出现在 Cursor 中:
mcp_wikijs_list_pages()mcp_wikijs_search_pages()mcp_wikijs_get_page()添加到 VS Code 设置:
{
"mcp.servers": {
"wikijs": {
"command": "node",
"args": ["lib/mcp_wikijs_stdin.js"],
"cwd": "/path/to/wikijs-mcp"
}
}
}
wikijs-mcp-server/
├── src/ # TypeScript 源代码
│ ├── server.ts # HTTP 服务器
│ ├── tools.ts # 工具定义
│ ├── api.ts # Wiki.js API 客户端
│ ├── types.ts # 数据类型
│ ├── schemas.ts # Zod 验证模式
│ └── README.md # 源代码文档
├── lib/ # JavaScript 库文件
│ ├── fixed_mcp_http_server.js # 主要 HTTP 服务器(已编译)
│ ├── mcp_wikijs_stdin.js # 编辑器直接集成的 STDIN 服务器
│ ├── mcp_client.js # 示例 MCP 客户端
│ ├── mcp_wrapper.js # MCP 协议实用工具
│ └── README.md # 库文档
├── scripts/ # 管理脚本
│ ├── setup.sh # 初始设置
│ ├── start_http.sh # 启动 HTTP 服务器
│ ├── stop_server.sh # 停止服务器
│ ├── start_typescript.sh # 启动 TypeScript 版本
│ ├── setup_cursor_mcp.sh # Cursor 设置
│ ├── test.sh # 运行测试
│ ├── test_mcp.js # 测试 HTTP 服务器
│ ├── test_m_ cp_stdin.js # 测试 STDIN 服务器
│ └── README.md # 脚本文档
├── .cursor/ # Cursor MCP 配置
│ └── mcp.json # MCP 配置文件(极其重要!)
├── dist/ # 编译后的 TypeScript 代码
├── package.json # 项目元数据
└── README.md # 主文档
🚨 极其重要: Cursor 集成需要
.cursor/mcp.json文件!
npm run setup - 项目的初始设置npm run build - 构建 TypeScript 项目npm run setup:cursor - 设置 Cursor 集成npm start / npm run start:http - HTTP MCP 服务器(端口 3200)npm run stop - 停止所有 MCP 服务器npm run start:typescript - TypeScript 版本的服务器(端口 8000)npm run server:stdio - 直接集成的 STDIO 版本npm run dev - 开发模式,支持热重载npm run demo - 功能演示npm test - 运行测试npm run client - 运行示例客户端GET /tools - 可用工具列表GET /health - 服务器健康检查POST /mcp - MCP JSON-RPC 端点// 获取页面列表
{
"method": "list_pages",
"params": {
"limit": 10,
"orderBy": "TITLE"
}
}
// 创建新页面
{
"method": "create_page",
"params": {
"title": "新页面",
"content": "# 标题\n\n内容...",
"path": "文件夹/新页面"
}
}
### 搜索页面:
```python
# 在所有内容和元数据中搜索
结果 = await mcp_client.call_tool("search_pages", {
"query": "魔法系统",
"limit": 5
})
# 获取所有页面(包括未发布的)
所有页面 = await mcp_client.call_tool("list_all_pages", {
"limit": 100,
"includeUnpublished": True
})
# 仅搜索未发布的页面
未发布 = await mcp_client.call_tool("search_unpublished_pages", {
"query": "草稿",
"limit": 10
})
# 检查页面发布状态
状态 = await mcp_client.call_tool("get_page_status", {
"id": 42
})
# 发布未发布的页面
结果 = await mcp_client.call_tool("publish_page", {
"id": 42
})
# 强制删除页面(适用于未发布的页面)
结果 = await mcp_client.call_tool("force_delete_page", {
"id": 42
})
# 列出所有用户
用户 = await mcp_client.call_tool("list_users")
# 根据查询搜索用户
搜索结果 = await mcp_client.call_tool("search_users", {
"query": "John"
})
# 创建新用户
新用户 = await mcp_client.call_tool("create_user", {
"email": "john@example.com",
"name": "John Doe",
"passwordRaw": "password123",
"providerKey": "local",
"groups": [1],
"mustChangePassword": False,
"sendWelcomeEmail": True
})
# 更新用户信息
更新用户 = await mcp_client.call_tool("update_user", {
"id": 1,
"name": "John Doe 更新"
})
git checkout -b feature/amazing-feature)git commit -m '添加神奇功能')git push origin feature/amazing-feature)本项目根据 MIT 许可证分发。详情见 LICENSE 文件。
如果这个项目帮助了您,请在 GitHub 上给它一个 ⭐!
有任何疑问?创建一个 Issue 或参考文档。
搜索分为四个阶段:
{
"method": "search_pages",
"params": {
"query": "ZELEBOBA",
"limit": 5
}
}
结果:
[
{
"id": 103,
"path": "test/test-page",
"title": "测试页面",
"description": "用于展示 Wiki.js API 功能的测试页面",
"url": "http://localhost:8080/en/test/test-page"
}
]
{
"method": "search_pages",
"params": {
"query": "找到我",
"limit": 3
}
}
结果:
[
{
"id": 108,
"path": "test/test-gemini-mcp",
"title": "测试 Gemini MCP 页面(找到我)",
"url": "http://localhost:8080/en/test/test-gemini-mcp"
}
]
系统会自动从 HTML 中提取文本:
<template slot="contents"> 块当 GraphQL API 权限时,系统:
list_all_pages - 获取所有页面(包括未发布的)search_unpublished_pages - 专门搜索未发布的页面force_delete_page - 增强的删除操作,适用于未发布的页面get_page_status - 检查任何页面的发布状态publish_page - 程序化发布未发布的页面lib/ 目录,以便更好地组织| 工具名称 | 描述 | 参数 |
|---|---|---|
get_page | 根据ID获取页面信息 | id: number |
get_page_content | 根据ID获取页面内容 | id: number |
list_pages | 列出页面并带有排序 | limit?: number, orderBy?: string |
search_pages | 根据查询搜索页面 | query: string, limit?: number |
create_page | 创建新页面 | title: string, content: string, path: string, description?: string, tags?: string[] |
update_page | 更新现有页面 | id: number, content: string |
delete_page | 删除页面 | id: number |
list_all_pages | 🆕 列出所有页面(包括未发布的) | limit?: number, orderBy?: string, includeUnpublished?: boolean |
search_unpublished_pages | 🆕 仅搜索未发布的页面 | query: string, limit?: number |
force_delete_page | 🆕 强制删除页面(适用于未发布的) | id: number |
get_page_status | 🆕 获取页面发布状态 | id: number |
**publish_page |