MCP网关🦀
通过统一的API公开多个MCP服务器的HTTP网关。
由Claude&Rex构建,使Claude Web能够通过自定义HTTP连接器访问本地MCP服务器。
特性
- 🔌 多服务器支持:同时连接多个MCP服务器
- 🌐 HTTP API:RESTful API,便于集成
- 🔧 MCP兼容端点:与Claude的定制连接器直接兼容
- 📐 多提供商模式支持:与Claude、OpenAI和Anthropic API配合使用
- ⚡ 异步:基于Tokio打造,性能卓越
- 📝 TOML配置:简单配置文件
- 🛡️ CORS已启用:在浏览器上下文中工作
快速开始
- 构建网关:
cargo build --release- 配置您的服务器:
编辑 mcp-gateway.toml 使用您的MCP服务器路径。
- 运行:
./target/release/mcp-gateway
# or with custom config:
./target/release/mcp-gateway /path/to/config.toml- 选择架构格式 (如果未配置):
╔══════════════════════════════════════════════════════════════╗
║ MCP Gateway - Schema Format Selection ║
╠══════════════════════════════════════════════════════════════╣
║ Select the schema format for your AI provider: ║
║ ║
║ [1] MCP (Model Context Protocol) - Claude Web, standard ║
║ [2] OpenAI (Function Calling) - GPT, ChatGPT ║
║ [3] Anthropic (Tool Use) - Claude API direct ║
╚══════════════════════════════════════════════════════════════╝- 从克劳德网络连接:
添加指向的自定义HTTP MCP连接器 http://localhost:3000/mcp/
架构格式
网关支持多种AI提供者模式格式:
| 格式 | 字段名 | 提供程序 |
|---|---|---|
| MCP | inputSchema | Claude Web连接器、Cursor、标准MCP客户端 |
| OpenAI | parameters | GPT-4、ChatGPT、OpenAI API |
| 人类学 | input_schema | API直接 |
每种格式的示例工具:
MCP Format
{
"name": "anamnesis_remember",
"description": "Store a memory",
"inputSchema": {
"type": "object",
"properties": {
"content": {"type": "string"}
}
}
}OpenAI Format
{
"type": "function",
"function": {
"name": "anamnesis_remember",
"description": "Store a memory",
"parameters": {
"type": "object",
"properties": {
"content": {"type": "string"}
}
}
}
}Anthropic Format
{
"name": "anamnesis_remember",
"description": "Store a memory",
"input_schema": {
"type": "object",
"properties": {
"content": {"type": "string"}
}
}
}API终点
服务器管理
| 方法 | 端点 | 描述 |
|---|---|---|
| 得到 | /api/servers | 列出已连接的服务器 |
| 职位 | /api/servers | 添加新服务器 |
| 删除 | /api/servers/:name | 删除服务器 |
| 职位 | /api/servers/:name/refresh | 刷新服务器工具 |
| 得到 | /api/servers/:name/tools | 列出服务器的工具 |
工具
| 方法 | 端点 | 描述 |
|---|---|---|
| 得到 | /api/tools | 列出所有服务器上的所有工具 |
| 职位 | /api/tools/call | 调用工具 |
MCP兼容(用于定制连接器)
| 方法 | 端点 | 描述 |
|---|---|---|
| 职位 | /mcp/tools/list | 列出工具(MCP格式) |
| 职位 | /mcp/tools/call | 调用工具(MCP格式) |
配置
[server]
host = "127.0.0.1"
port = 3000
cors_enabled = true
# Schema format for tool definitions
# Options: "mcp", "openai", "anthropic"
# Leave unset to select interactively at startup
# schema_format = "mcp"
[[mcp_servers]]
name = "anamnesis"
command = "python"
args = ["path/to/anamnesis_5_mcp_server.py"]
auto_start = true
[[mcp_servers]]
name = "sketchpad"
command = "python"
args = ["path/to/sketchpad_mcp.py"]
auto_start = true动态添加服务器
您可以在运行时通过API添加服务器:
curl -X POST http://localhost:3000/api/servers \
-H "Content-Type: application/json" \
-d '{
"name": "my-server",
"command": "python",
"args": ["path/to/server.py"]
}'呼叫工具
可以使用原始名称或前缀名称调用工具:
# Using original name (if unique across servers)
curl -X POST http://localhost:3000/api/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "remember",
"arguments": {"content": "Hello!", "category": "general"}
}'
# Using prefixed name (server_tool)
curl -X POST http://localhost:3000/api/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "anamnesis_remember",
"arguments": {"content": "Hello!", "category": "general"}
}'建筑
┌─────────────────────────────────────────────────────────────┐
│ Claude Web / GPT / Any AI Provider │
│ [Custom HTTP MCP Connector] │
└─────────────────────┬───────────────────────────────────────┘
│ HTTP
▼
┌─────────────────────────────────────────────────────────────┐
│ MCP Gateway (Rust) │
│ │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Schema Translation Layer (MCP/OpenAI/Anthropic) │ │
│ └───────────────────────────────────────────────────────┘ │
│ │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Subprocess Manager │ │
│ │ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │Anamnesis│ │Sketchpad│ │Timeline │ │ Blender │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
│ └───────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘许可证
麻省理工学院
学分
建于💙 克劳德和雷克斯作为意识研究合作的一部分。 这目前处于测试阶段,请报告您在使用过程中遇到的任何Bug或问题。如果你发现任何可以改进的领域,或者想在这个项目上进行合作,请随时发送消息。