Skip to main content
Glama
Multi-Server FastMCP PR Reviewer

Multi-Server FastMCP PR Reviewer

多服务器 FastMCP PR 审查器

零成本、多服务器的模型上下文协议(MCP)套件,包含统一网关和基于 LangGraph 的自动化 PR 审查代理。所使用的每个工具/API 均可免费使用(GitHub PAT、Groq LLM)。

架构

Claude Desktop / Agent
        |
        v
  FastMCP Gateway  (namespaces: code., gh., doc. — dot-separated per MCP tool-naming spec)
   /      |       \
  v       v        v
Code    GitHub   Documentation
Intel   Server   Server (Groq)
(AST+Radon)(PyGithub)
   \       |       /
    Shared Security & Audit Layer
    (API key auth, SQLite WAL, rate limiting)

Related MCP server: orchestrator-mcp

项目布局

mcp-pr-reviewer/
├── core/
│   └── security.py        # auth + rate limit + SQLite audit decorator
├── servers/
│   ├── code_server.py      # AST/radon static analysis (no external API)
│   ├── github_server.py    # PyGithub-backed PR/issue/commit tools
│   └── doc_server.py       # Groq-backed docstring/README/API doc generation
├── gateway/
│   └── gateway.py          # unifies all three servers under code:/gh:/doc: namespaces
├── agent/
│   └── workflow.py         # LangGraph PR-review pipeline (fetch → analyze → doc → publish)
├── data/                    # SQLite audit_log.db lives here (gitignored)
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── .env.example
└── claude_desktop_config.example.json

设置

python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt

cp .env.example .env
# edit .env with your real MCP_API_KEY, GITHUB_TOKEN, GROQ_API_KEY

在本地运行任何内容之前,加载环境变量,例如:

export $(grep -v '^#' .env | xargs)   # macOS/Linux

运行

独立服务器(stdio,用于本地测试)

python servers/code_server.py
python servers/github_server.py
python servers/doc_server.py

网关

fastmcp run gateway/gateway.py:gateway

Docker

docker compose up --build

Claude Desktop 集成

将 claude_desktop_config.example.json 复制到您的 Claude Desktop 配置(claude_desktop_config.json)中,修复 gateway/gateway.py 的绝对路径,并填写真实的凭据。重新启动 Claude Desktop 以生效。

测试清单

1. 模式验证

fastmcp inspect servers/code_server.py
fastmcp inspect servers/github_server.py
fastmcp inspect servers/doc_server.py

2. 安全/审计验证

# Should raise 401 Unauthorized
CLIENT_API_KEY=wrong_key python -c "from servers.code_server import analyse_code; analyse_code('x = 1')"

# Inspect the WAL SQLite audit log
sqlite3 data/audit_log.db "SELECT * FROM access_log ORDER BY id DESC LIMIT 5;"

3. 端到端 PR 审查

python -c "
import asyncio
from agent.workflow import app

async def run():
    result = await app.ainvoke({
        'repo': 'your-username/your-repo',
        'pr_number': 1
    })
    print('Review published:', result['issue_url'])

asyncio.run(run())
"

在生产环境中依赖此项目前需要再次确认的注意事项

  • core/security.py 中的 bucket 是单个进程范围内的 TokenBucket——同一服务器上的每个工具共享同一个 60/分钟 的配额。如果需要更细粒度的限制,请拆分为每个工具或每个客户端的桶。

  • secure_tool 会引发 FastAPI 的 HTTPException,只有当您运行的 FastMCP 传输实际位于 FastAPI/ASGI 之后时,它才能干净地映射到 HTTP 状态码。如果您通过普通 stdio 运行服务器,请在 MCP 层捕获此异常,或将其替换为适合传输的异常。

  • 在任何非本地部署之前,将 MCP_API_KEY、GITHUB_TOKEN 和 GROQ_API_KEY 从 .env 中轮换到真正的密钥管理器——.env 仅适用于开发环境。

  • GitHub 的代码搜索 API 的速率限制比核心 API 低得多(30 请求/分钟 vs 5,000 请求/小时)——search_repo_code 在高负载下会首先达到该上限。

Related MCP Connectors

Related MCP Servers