文档生成数据服务

一个为LLM文档生成提供GitHub PR/issue数据和文档模板的MCP服务器。

  • by RandellB-Ritense
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 RandellB-Ritense/Documentation-mcp-server

使用说明

文档MCP服务器

一个模型上下文协议(MCP)服务器,提供GitHub PR/问题数据以及基于LLM的文档生成的文档指南。

概述

此MCP服务器是 数据提供程序 即:

  • 获取GitHub PR并在服务器端发布数据
  • 加载静态文档模板
  • 向客户端LLM返回格式化的上下文
  • 让客户端LLM生成实际文档
  • 作为HTTP服务运行 -可以在本地或远程部署

架构流程:

User → Client LLM → HTTP → MCP Server
                              ↓
                       Fetches GitHub data
                              ↓
                       Returns guide + context
                              ↓
              Client LLM generates documentation
                              ↓
                      User receives documentation

服务器不包含自己的LLM,它聚合数据供客户端的LLM处理。

特性

  • HTTP传输:使用StreamableHTTP进行MCP通信
  • 无状态:支持多个并发客户端,没有会话冲突
  • 远程部署:在与MCP客户端不同的机器上运行
  • 单一工具: writeDocumentation -使用文档指南聚合GitHub数据
  • 服务器端获取:自动检索PR详细信息、链接问题和差异
  • 静态模板:使用启动时加载的固定文档指南
  • 没有LLM电话:返回客户端LLM要处理的原始上下文
  • 健康检查:内置 /health 监控端点

快速开始

1.安装和构建

npm install
npm run build

2.设置GitHub Token

export GITHUB_TOKEN="ghp_your_github_token_here"

在以下地址获取您的代币:https://github.com/settings/tokens

3.启动服务器

npm start

您应该看到:

Documentation MCP Server running on http://0.0.0.0:3000
MCP endpoint: http://0.0.0.0:3000/mcp
Health check: http://0.0.0.0:3000/health
Mode: HTTP (stateless, multiple clients supported)

配置

环境变量

变量 描述 默认值 必填
GITHUB_TOKEN GitHub个人访问令牌 - 是
PORT HTTP服务器端口 3000 没有
HOST HTTP服务器主机 0.0.0.0 没有

例子

# Custom port
PORT=8080 npm start

# Specific interface
HOST=127.0.0.1 npm start

# Both
PORT=8080 HOST=127.0.0.1 GITHUB_TOKEN=your_token npm start

用法

健康检查

测试服务器是否正在运行:

curl http://localhost:3000/health
# Response: {"status":"ok","service":"documentation-mcp-server"}

MCP客户端配置

配置您的MCP客户端以连接到服务器:

{
  "mcpServers": {
    "documentation": {
      "url": "http://localhost:3000/mcp",
      "transport": "http"
    }
  }
}

对于远程服务器:

{
  "mcpServers": {
    "documentation": {
      "url": "https://your-server.com/mcp",
      "transport": "http"
    }
  }
}

工具:writeDocumentation

输入参数:

  • prUrl (字符串,可选):GitHub拉取请求URL
  • issueUrl (字符串,可选):GitHub问题URL
  • notes (字符串,可选):附加上下文或注释

至少一个 prUrl 或 issueUrl 是必需的。

示例用法:

User: "Write documentation for https://github.com/owner/repo/pull/123"

Client LLM: [Calls writeDocumentation tool via HTTP]

MCP Server: [Fetches GitHub data, returns guide + context]

Client LLM: [Generates documentation following the guide]

User: [Receives completed documentation]

输出:

返回一个格式化的提示,其中包含:

  1. 文档指南(结构、规则、必填部分)
  2. GitHub PR/问题数据(标题、描述、文件、差异)
  3. 提供的任何其他注释
  4. 客户LLM生成文档的说明

部署

码头工人

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
ENV PORT=3000
ENV HOST=0.0.0.0
CMD ["npm", "start"]

构建并运行:

docker build -t documentation-mcp-server .
docker run -d -p 3000:3000 \
  -e GITHUB_TOKEN=your_token \
  --name mcp-server \
  documentation-mcp-server

Docker Compose

version: '3.8'

services:
  mcp-server:
    build: .
    ports:
      - "3000:3000"
    environment:
      - GITHUB_TOKEN=${GITHUB_TOKEN}
      - PORT=3000
      - HOST=0.0.0.0
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000/health"]
      interval: 30s
      timeout: 10s
      retries: 3

流程经理(PM2)

npm install -g pm2
pm2 start dist/index.js --name mcp-server
pm2 save
pm2 startup

云平台

部署到Railway、Render、Fly.io或任何支持Node.js的平台:

  1. 将代码推送到GitHub
  2. 将存储库连接到平台
  3. 集 GITHUB_TOKEN 环境变量
  4. 平台将自动部署

测试

卷曲测试

# Initialize
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
      "protocolVersion": "2024-11-05",
      "capabilities": {},
      "clientInfo": {"name": "test", "version": "1.0.0"}
    }
  }'

# List tools
curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/list"
  }'

建筑

src/
├── index.ts           # MCP server with HTTP transport
└── github-client.ts   # GitHub API integration

documentation-guide.md # Static documentation template

运作原理

  1. 服务器启动:加载文档指南,启动HTTP服务器
  2. 客户端连接:MCP客户端连接到 /mcp 端点
  3. 工具调用:客户电话 writeDocumentation 使用GitHub URL
  4. 数据获取:服务器从GitHub API获取PR/问题数据
  5. 上下文构建:服务器将指南+GitHub数据组合成格式化的提示
  6. 响应:服务器通过HTTP返回完整的上下文
  7. 生成:客户端LLM根据指南生成文档

运输详情

  • 协议:流式HTTP(MCP规范)
  • MCP端点: GET/POST /mcp -主MCP通信
  • 健康端点: GET /health -状态检查
  • 跨域资源共享:为所有来源启用(配置为生产)
  • 会话模式:无状态(支持多个并发客户端)

安全

对于生产部署:

  1. 配置CORS:限制允许的来源
  2. 使用HTTPS:部署在反向代理(nginx、Caddy)后面
  3. 速率限制:添加限速中间件
  4. 认证:如果需要,添加身份验证令牌
  5. GitHub 令牌:保持安全,使用环境变量
  6. 网络:使用防火墙规则限制访问

故障排除

看 故障排除.md 详细的解决方案。

常见问题:

  • “服务器已初始化”:已在最新版本中修复(无状态模式)
  • 连接被拒绝:服务器未运行或端口错误
  • CORS错误:为您的客户端源配置CORS
  • GitHub速率限制:使用GitHub令牌

需求

  • Node.js 18+
  • TypeScript 5+
  • GitHub令牌(可选,但推荐)

许可证

麻省理工学院