ThinMCP
ThinMCP是一个MCP网关,通过稳定的双工具接口暴露了许多上游MCP服务器:
search()execute()
ThinMCP没有将每个上游工具定义加载到模型上下文中,而是保留了一个本地目录,让模型按需发现工具,并仅转发它需要进行的调用。
为什么选择ThinMCP
随着工具数量的增长,将多个MCP服务器直接连接到模型会增加上下文大小。ThinMCP保持面向模型的表面积固定,同时仍然允许访问大型工具生态系统。
其结果是为客户端提供了一个更简单的集成点,并为生产部署提供了更可预测的运行时形状。
建筑
flowchart LR
A["LLM or MCP Client"] --> B["ThinMCP Gateway"]
B --> C["Local Catalog"]
B --> D["Execution Layer"]
D --> E["Schema Validation"]
E --> F["Upstream MCP Servers"]
G["Sync Process"] --> F
G --> C
G --> H["Snapshots"]关键能力
- 修复了模型的双工具界面
- 支持HTTP和stdio上游服务器
- 本地SQLite支持的目录用于查找
- 上游执行前的输入验证
- 网关工具调用的沙盒执行
- 具有健康和指标端点的HTTP传输
- 定期同步上游工具元数据
快速开始
npm install
npm run build
cp config/mcp-sources.example.yaml config/mcp-sources.yaml编辑 config/mcp-sources.yaml,然后同步并启动:
npm run sync
npm startHTTP模式:
npm start -- --transport http --port 8787验证设置:
npm run doctor配置
ThinMCP读取 config/mcp-sources.yaml。每个上游服务器可以使用 http 或 stdio 运输。
最小示例:
servers:
- id: exa
name: Exa MCP
transport: http
url: https://mcp.exa.ai/mcp
auth:
type: bearer_env
env: EXA_API_KEY
allowTools: ["*"]
- id: local-fs
name: Local Filesystem MCP
transport: stdio
command: npx
args:
- -y
- "@modelcontextprotocol/server-filesystem"
- /tmp
cwd: .
allowTools:
- "filesystem.*"
sync:
intervalSeconds: 300
onStart: true
runtime:
codeTimeoutMs: 15000
maxCodeLength: 20000
maxResultChars: 60000
catalog:
dbPath: ../data/thinmcp.db
snapshotDir: ../snapshots使用 allowTools 以使每个上游服务器的作用域仅限于您实际希望通过网关公开的工具。
运行ThinMCP
发展:
npm run dev生产建设:
npm run build
npm startHTTP模式:
npm start -- --transport http --host 127.0.0.1 --port 8787可用HTTP端点:
/mcp/healthz/metrics
运营
常用命令:
npm run build
npm run sync
npm run doctor
npm test
THINMCP_RUN_E2E=1 npm run test:e2e操作指南:
- 将上游凭据保存在环境变量中
- 限制
allowTools以最小的有效表面积 - 在本地开发之外公开网关时启用HTTP身份验证和速率限制
- 跑
npm run sync如果目录新鲜度很重要,则作为部署或启动验证的一部分
客户端集成
客户示例记录在 docs/CLIENT_INTEGRATIONS.md.
许可证
国际学生中心
