模型上下文协议网关

一个高性能的模型上下文协议(MCP)网关,作为多路复用器,允许LLM客户端通过单一统一端点与多个上游MCP服务器通信。

  • by KilianIschtschuk
  • Rust
  • 本地部署
  • 更新于
在 GitHub 查看 KilianIschtschuk/apparatus-mcp-gateway

使用说明

设备MCP网关

高性能 模型上下文协议(MCP)网关 内置于Rust中。此网关充当多路复用器,允许LLM客户端通过单个统一端点与多个上游MCP服务器(本地Stdio进程和远程HTTP/SSE服务)通信。

特性

  • 多路复用: 将多个MCP服务器合并到一个工具列表中。
  • 命名空间 : 自动为工具添加前缀(例如。, time_service::get_time)以防止服务器之间的冲突。
  • 运输桥接: 将标准JSON-RPC HTTP请求连接到基于Stdio的子进程。
  • 声明性配置: 通过简单的 config.yaml 文件。
  • 与Axum和Tokio共同打造: 完全异步、安全、闪电般快速。

入门指南

先决条件

  • 锈 (最新稳定)
  • 紫外线 (可选,用于运行基于Python的MCP工具)

安装

  1. 克隆存储库:
git clone https://github.com/youruser/apparatus-mcp-gateway.git
cd apparatus-mcp-gateway

  1. 构建项目:
cargo build --release

配置

创建 config.yaml 在项目根目录中:

gateway_port: 3000

mcp_servers:
  # Local Python server using uvx
  time_service:
    type: stdio
    command: "uvx"
    args: ["mcp-server-time"]

  # Local Node.js server
  filesystem:
    type: stdio
    command: "node"
    args: ["/path/to/mcp-server-filesystem/index.js", "/allowed/path"]

📖 用法

  1. 运行网关:
cargo run

  1. 列出可用工具:
curl -X POST http://localhost:3000/message \
     -H "Content-Type: application/json" \
     -d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'

  1. 调用工具:
curl -X POST http://localhost:3000/message \
     -H "Content-Type: application/json" \
     -d '{
       "jsonrpc": "2.0",
       "id": "2",
       "method": "tools/call",
       "params": {
         "name": "time_service::get_current_time",
         "arguments": {"timezone": "UTC"}
       }
     }'

发展

格式代码:

cargo fmt

棉绒编码:

cargo clippy