使用说明
通用文档MCP服务器
一个高性能的MCP(模型上下文协议)服务器,用于转换 任何文档网站 进入人工智能可访问的知识库。最初为GitBook构建,但与 Vercel文档、Next.js网站、Docusaurus和许多其他文档平台。具有即时启动、智能缓存和自动域检测功能。
✨ 主要特点
- ⚡ 即时启动 -具有亚秒级服务器初始化的SQLite存储
- 🔍 高级搜索 -基于模糊匹配和排名的FTS5全文搜索
- 🧠 智能自动检测 -自动检测域名、关键字和品牌
- 📝 Markdown完美 -使用语法突出显示的代码块保留格式
- 🔄 后台更新 -非阻塞更改检测和缓存刷新
- 🌐 通用载体 -适用于GitBook、Vercel文档、Next.js网站和许多其他文档平台
- 📡 双接口 -MCP工具和REST API端点
- 🚀 生产就绪 -速率限制、错误处理和强大的缓存
🚀 快速开始
💡 推荐:使用交互式创建者获得最佳体验!
🎨 Web UI管理仪表板
# Clone this repo (once)
git clone https://github.com/tcsenpai/mcpbook/
cd mcpbook
# Build the UI
npm run ui:build
# Start the web interface
npm run ui
Web UI提供:
- 🚀 可视化服务器创建 -带有实时URL验证的分步向导
- 📊 服务器管理 -启动/停止/删除具有实时状态的服务器
- 📋 Claude桌面集成 -一键复制配置或通过CLI添加
- 🖥️ 直播终端 -实时反馈和命令执行
- ⚠️ 安全功能 -确认对话框和取消功能
⭐ 一个命令设置
# Clone this repo (once)
git clone https://github.com/tcsenpai/mcpbook/
cd mcpbook
# Create MCP server for any documentation site instantly
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 # Automatically detects and configures your domain -
启动服务器
npm start # Instant startup with SQLite cache -
使用MCP检查员进行测试
npx @modelcontextprotocol/inspector node dist/index.js
📦 安装选项
方案1:地方发展
git clone <repository>
cd mcpbook
npm install
npm run build
npm start
选项2:全局安装
npm install -g .
# Then use the binary name from package.json
your-mcp-server-name
选项3:Claude桌面集成
{
"mcpServers": {
"gitbook": {
"command": "node",
"args": ["/absolute/path/to/dist/index.js"],
"env": {
"GITBOOK_URL": "https://docs.yoursite.com"
}
}
}
}
配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 视窗:
%APPDATA%\\Claude\\claude_desktop_config.json
选项4:流式HTTP传输
npm run start:http # StreamableHTTP on port 3001
node dist/index.js --streamable-http --port=3002 # Custom port
选项5:REST API服务器
npm run start:api # HTTP server on port 3000
PORT=8080 npm run start:api # Custom port
🌐 平台兼容性
虽然最初是为GitBook设计的,但此MCP服务器具有 经过验证的兼容性 有许多文档平台:
✅ 保证工作
- GitBook (原始目标平台)
- 自定义GitBook实例
🎯 已成功测试
- Vercel托管文档 (
docs.vercel.com,aptos.dev) - Next.js文档网站
- 静态现场发电机 导航一致
- 大多数基于HTML的文档平台
🔧 运作原理
刮板智能化:
- 发现导航 通过链接爬行
- 提取内容 从任何HTML结构
- 适应不同的布局 自动地
- 处理各种身份验证 以及路由模式
💡 专业提示:如果一个网站有一致的导航和可访问的内容,我们的抓取器可能会工作!自动检测功能会自动适应不同的站点结构。
⚙️ 配置
自动检测(推荐)
GITBOOK_URL=https://docs.yoursite.com
AUTO_DETECT_DOMAIN=true
AUTO_DETECT_KEYWORDS=true
服务器将自动:
- 生成特定于域的工具名称(
stripe_docs_search,api_docs_get_page) - 从内容中提取相关关键字
- 创建上下文描述以实现更好的AI集成
手动配置
# Target GitBook (required)
GITBOOK_URL=https://docs.yoursite.com
# Custom branding (optional)
SERVER_NAME=my-api-docs
SERVER_DESCRIPTION=API documentation and guides
DOMAIN_KEYWORDS=api,rest,graphql,endpoints
TOOL_PREFIX=api_
# Performance tuning
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 |
获取格式化标记 | path:页面路径 |
MCP提示
explain_section-生成全面的教程summarize_page-创建简明摘要compare_sections-比较文档部分api_reference-格式为API文档quick_start_guide-生成快速入门指南
🌐 HTTP接口
服务器同时支持MCP StreamableHTTP和传统的REST API:
流式HTTP MCP协议:
# Health check
curl http://localhost:3001/health
# MCP requests (requires MCP client)
curl -X POST http://localhost:3001/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'
REST API(独立服务器):
# Search content
curl "http://localhost:3000/api/search?q=authentication"
# Get specific page
curl "http://localhost:3000/api/page/api/authentication"
# Get page as markdown
curl "http://localhost:3000/api/page/api/authentication/markdown"
# Get code blocks
curl "http://localhost:3000/api/page/api/authentication/code"
# List sections
curl "http://localhost:3000/api/sections"
# Get section pages
curl "http://localhost:3000/api/sections/API/pages"
# Server status
curl "http://localhost:3000/api/status"
# Refresh cache
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_page- 通用网站→
docs_search_content,docs_get_page
MCP工具使用
# Search for authentication docs
{"tool": "api_search_content", "arguments": {"query": "oauth authentication"}}
# Get specific page
{"tool": "api_get_page", "arguments": {"path": "/auth/oauth"}}
# Get code examples
{"tool": "api_get_code_blocks", "arguments": {"path": "/sdk/quickstart"}}
# Refresh content
{"tool": "api_refresh_content", "arguments": {}}
🏗️ 建筑
- SQLite存储 -使用FTS5全文搜索快速启动
- 后台更新 -非阻塞变化检测
- 自动检测 -域名和关键字提取
- 平行刮擦 -可配置的并发性
- 智能缓存 -仅更新更改的内容
关键组件
GitBookScraper-网络抓取和内容提取SQLiteStore-具有FTS5搜索功能的高性能存储DomainDetector-自动域和关键字检测GitBookMCPServer-带工具处理程序的MCP服务器GitBookRestAPI-用于web集成的HTTP端点
🔧 发展
# Development mode with auto-reload
npm run dev
# Build with auto-detection
npm run build
# Run manual auto-detection
npm run auto-detect
# Clean build (no auto-detection)
npm run build:clean
# Test with MCP Inspector
npx @modelcontextprotocol/inspector node dist/index.js
🌍 通用GitBook支持
适用于任何公共GitBook,包括:
- API文档 -条纹、斜纹布等。
- 框架文档 -React、Vue、Angular
- 产品指南 -帮助中心和教程
- 开发人员资源 -SDK和参考
- 公司维基 -内部文件
⚡ 演出
- 即时启动:使用SQLite缓存进行亚秒级初始化
- 后台更新:非阻塞变化检测
- 智能索引:FTS5全文搜索,带排名
- 高效存储SQLite取代了缓慢的JSON解析
- 内存优化:按需加载而不是全内存缓存
🚧 局限性
- 仅限公共GitBooks -需要可公开访问的网站
- 静态内容 -抓取已发布的HTML,而不是基于API的
- 手动刷新 -无实时更新(使用刷新工具)
- 以文本为中心 -提取文本内容,而不是交互式元素
📄 许可证
麻省理工学院
需要帮助? 检查 MCP文件 或者打开一个问题。
