这是一个高性能的 MCP(模型上下文协议)服务器,可以将任何文档网站转换成一个可由AI访问的知识库。最初是为 GitBook 构建的,但也可以与Vercel 文档、Next.js 站点、Docusaurus 和许多其他文档平台一起使用。具有即时启动、智能缓存和自动域名检测等功能。
💡 推荐:使用交互式创建器以获得最佳体验!
# 克隆此仓库(一次)
git clone https://github.com/tcsenpai/mcpbook/
cd mcpbook
# 构建 UI
npm run ui:build
# 启动 Web 界面
npm run ui
Web UI 提供:
# 克隆此仓库(一次)
git clone https://github.com/tcsenpai/mcpbook/
cd mcpbook
# 即刻为任何文档站点创建 MCP 服务器
npm exec create-gitbook-mcp
就这样! 🎉 交互式向导会:
~/.config/mcpbooks/servers/[name])your-server-name 命令访问)安装和配置
npm install
echo "GITBOOK_URL=https://docs.yoursite.com" > .env
构建与自动检测
npm run build # 自动检测并配置您的域名
启动服务器
npm start # 使用 SQLite 缓存即时启动
使用 MCP 检查器测试
npx @modelcontextprotocol/inspector node dist/index.js
git clone <repository>
cd mcpbook
npm install
npm run build
npm start
npm install -g .
# 然后使用 package.json 中的二进制名称
your-mcp-server-name
{
"mcpServers": {
"gitbook": {
"command": "node",
"args": ["/绝对路径/to/dist/index.js"],
"env": {
"GITBOOK_URL": "https://docs.yoursite.com"
}
}
}
}
配置文件位置:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\\Claude\\claude_desktop_config.jsonnpm run start:http # 在端口 3001 上运行 StreamableHTTP
node dist/index.js --streamable-http --port=3002 # 自定义端口
npm run start:api # 在端口 3000 上运行 HTTP 服务器
PORT=8080 npm run start:api # 自定义端口
虽然最初设计用于 GitBook,但这个 MCP 服务器已经证明与许多文档平台兼容:
docs.vercel.com, aptos.dev)爬虫程序智能地:
💡 小贴士:如果站点具有一致的导航和可访问的内容,我们的爬虫很可能有效!自动检测功能会自动适应不同站点结构。
GITBOOK_URL=https://docs.yoursite.com
AUTO_DETECT_DOMAIN=true
AUTO_DETECT_KEYWORDS=true
服务器将自动:
stripe_docs_search,api_docs_get_page)# 目标 GitBook(必需)
GITBOOK_URL=https://docs.yoursite.com
# 自定义品牌(可选)
SERVER_NAME=my-api-docs
SERVER_DESCRIPTION=API 文档和指南
DOMAIN_KEYWORDS=api,rest,graphql,endpoints
TOOL_PREFIX=api_
# 性能调整
CACHE_TTL_HOURS=1
MAX_CONCURRENT_REQUESTS=5
SCRAPING_DELAY_MS=100
API 文档:
GITBOOK_URL=https://api-docs.yourservice.com
TOOL_PREFIX=api_
DOMAIN_KEYWORDS=api,rest,endpoints,authentication
→ 结果为:api_search_content,api_get_page 等。
产品文档:
GITBOOK_URL=https://help.yourproduct.com
TOOL_PREFIX=help_
DOMAIN_KEYWORDS=tutorial,guide,troubleshooting
→ 结果为:help_search_content,help_get_page 等。
服务器暴露了 7 个 MCP 工具,并自动添加前缀:
| 工具 | 描述 | 参数 |
|---|---|---|
{prefix}_search_content | 带排名的高级搜索 | query: 搜索词 |
{prefix}_get_page | 获取特定页面内容 | path: 页面路径(例如,“/api/auth”) |
{prefix}_list_sections | 获取目录 | 无 |
{prefix}_get_section_pages | 获取章节中的所有页面 | section: 章节名称 |
{prefix}_refresh_content | 强制缓存刷新 | 无 |
{prefix}_get_code_blocks | 提取带语法高亮的代码 | path: 页面路径 |
{prefix}_get_markdown | 获取格式化的 Markdown | path: 页面路径 |
explain_section - 生成综合教程summarize_page - 创建简洁摘要compare_sections - 对比文档章节api_reference - 格式化为 API 文档quick_start_guide - 生成快速入门指南服务器支持 MCP StreamableHTTP 和传统的 REST API:
StreamableHTTP MCP 协议:
# 健康检查
curl http://localhost:3001/health
# MCP 请求(需要 MCP 客户端)
curl -X POST http://localhost:3001/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'
REST API(单独服务器):
# 搜索内容
curl "http://localhost:3_000/api/search?q=authentication"
# 获取特定页面
curl "http://localhost:3_000/api/page/api/authentication"
# 获取页面作为 Markdown
curl "http://localhost:3_000/api/page/api/authentication/markdown"
# 获取代码块
curl "http://localhost:3_000/api/page/api/authentication/code"
# 列出章节
curl "http://localhost:3_000/api/sections"
# 获取章节页面
curl "http://localhost:3_000/api/sections/API/pages"
# 服务器状态
curl "http://localhost:3_000/api/status"
# 刷新缓存
curl -X POST "http://localhost:3_000/api/refresh"
docs.stripe.com → stripe_search_content,stripe_get_pagedocs.react.dev → react_search_content,react_get_pageapi.yourcompany.com → api_search_content,api_get_pagedocs_search_content,docs_get_page# 搜索认证文档
{"tool": "api_search_content", "arguments": {"query": "oauth 认证"}}
# 获取特定页面
{"tool": "api_get_page", "arguments": {"path": "/auth/oauth"}}
# 获取代码示例
{"tool": "api_get_code_blocks", "arguments": {"path": "/sdk/quickstart"}}
# 刷新内容
{"tool": "api_refresh_content", "arguments": {}}
GitBookScraper - 网页爬取和内容提取SQLiteStore - 高性能存储,带 FTS5 搜索DomainDetector - 自动域名和关键词检测GitBookMCPServer - 带工具处理器的 MCP 服务器GitBookRestAPI - 用于 Web 集成的 HTTP 端点# 开发模式,自动重载
npm run dev
# 构建,自动检测
npm run build
# 手动自动检测
npm run auto-detect
# 清洁构建(无自动检测)
npm run build:clean
# 使用 MCP 检查器测试
npx @modelcontextprotocol/inspector node dist/index.js
适用于任何公开的 GitBook,包括:
MIT
需要帮助? 查看 MCP 文档 或打开问题。