这是一个高性能的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
cd mcpbook
npm install
npm run build
npm start
npm install -g .
# 然后使用package.json中的二进制名称
your-mcp-server-name
{
"mcpServers": {
"gitbook": {
"command": "node",
"args": ["/absolute/path/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 # 自定义端口
虽然该MCP服务器最初是为GitBook设计的,但它已经证明了与许多文档平台的兼容性:
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:3000/api/search?q=authentication"
# 获取特定页面
curl "http://localhost:3000/api/page/api/authentication"
# 获取页面的Markdown格式
curl "http://localhost:3000/api/page/api/authentication/markdown"
# 获取代码块
curl "http://localhost:3000/api/page/api/authentication/code"
# 列出部分
curl "http://localhost:3000/api/sections"
# 获取部分中的页面
curl "http://localhost:3000/api/sections/API/pages"
# 服务器状态
curl "http://localhost:3000/api/status"
# 刷新缓存
curl -X POST "http://localhost:3000/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 authentication"}}
# 获取特定页面
{"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文档 或提交一个问题。