mcpField
M
mcp-proxy

mcp-proxy

本地服务
github.com/stephenlacy开发工具3370 周前更新

关于 mcp-proxy

mcp-proxy 是一个用 Rust 编写的双向 MCP 代理,支持 SSE 与 Streamable HTTP 传输并带有 OAuth 认证。它可以将远程 MCP 服务接入本地 stdio 客户端,也可以将本地服务暴露为远程服务。

主要功能

  1. 01支持 SSE 与 Streamable HTTP 传输
  2. 02OAuth 认证与自动刷新令牌
  3. 03双向代理:远程转本地或本地转远程
  4. 04传输方式根据 URL 自动识别
  5. 05使用 RUST_LOG 控制日志级别

适用场景

  1. 01在 Claude 或 Cursor 中接入远程 MCP 服务
  2. 02将本地 stdio 类 MCP 服务通过网络暴露
  3. 03清除认证缓存以解决认证问题

MCP 相关

该项目是 MCP 代理,可让 stdio 客户端连接远程 MCP 服务,也可将本地 MCP 服务以 SSE 或 Streamable HTTP 端点对外提供。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

mcp-proxy

支持 SSE 和 Streamable HTTP 传输并提供 OAuth 的 Rust 双向 MCP 代理。

功能

  • 多种传输方式:SSE 和 Streamable HTTP
  • OAuth 身份验证:完整的 OAuth 流程,并自动刷新令牌
  • 双向代理:将远程服务连接到本地客户端,或将本地服务公开为远程服务
  • 快速轻量:使用 Rust 构建,性能出色

用法

安装
# from crates.io
cargo install rmcp-proxy
# from github
cargo install --git https://github.com/stephenlacy/mcp-proxy
构建
cargo build --release
运行

代理可以在两种模式下运行:

1. 远程客户端模式

连接到远程 MCP 服务,并将其公开为本地 stdio 服务。支持 SSE 和 Streamable HTTP 传输,并可自动检测。

传输检测:

  • URL 包含 /sse → 使用 SSE 传输
  • 其他所有 URL → 使用 Streamable HTTP 传输
  • 使用 --transport 标志覆盖
基本示例
# Streamable HTTP
mcp-proxy http://localhost:9090/mcp/instances_abc123

# SSE transport
mcp-proxy http://localhost:8080/sse
mcp-proxy --transport sse http://localhost:8080/events

# Specific
mcp-proxy --transport streamable-http http://localhost:9090/api
与 Claude 或 Cursor 搭配使用
{
  "mcpServers": {
    "my-remote-server": {
      "command": "mcp-proxy",
      "args": ["http://example.com/mcp/instances_abc123"]
    },
    "sse-server": {
      "command": "mcp-proxy", 
      "args": ["--transport", "sse", "http://example.com/sse"]
    }
  }
}
2. 本地服务模式

通过 stdio 连接到本地 MCP 服务,并将其公开为远程服务。支持 SSE 和 Streamable HTTP 端点。

# Expose as SSE server
mcp-proxy --port 8080 -- your-command --arg1 value1 --arg2 value2
mcp-proxy --port 8080 python mcp_server.py
mcp-proxy --port 8080 -- npx -y @modelcontextprotocol/server-everything

# Or http+streamable
mcp-proxy --port 9090 --transport streamable-http -- python mcp_server.py

mcp-proxy --port 8080 -e KEY VALUE -e ANOTHER_KEY ANOTHER_VALUE -- your-command
身份验证管理
清除身份验证缓存

如果遇到身份验证问题,请清除身份验证缓存:

# Clear all auth data
mcp-proxy reset

# Or manually delete the directory
rm -rf ~/.mcp-auth
命令行选项
# Transport selection
--transport <TRANSPORT>    # sse, streamable-http, or auto (default: auto)

# Server mode options
--port <PORT>             # Port for local server mode (default: random)
--host <HOST>             # Host to bind to (default: 127.0.0.1)

# Environment variables (server mode)
-e, --env <KEY> <VALUE>   # Set environment variable
--pass-environment        # Pass through all environment variables

# Headers (client mode) 
-H, --headers <KEY> <VALUE>  # Add custom headers

# Reset auth
mcp-proxy reset           # Clear all stored auth data
日志

遗憾的是,上游 rmcp crate 会输出大量嘈杂日志

使用 RUST_LOG 环境变量控制日志详细程度:

# Minimal logging
RUST_LOG=error mcp-proxy http://example.com/mcp
RUST_LOG=debug mcp-proxy http://example.com/mcp
RUST_LOG=info mcp-proxy http://example.com/mcp
库用法
use rmcp_proxy::{
    sse_client::run_sse_client,
    streamable_http_client::run_streamable_http_client,
    StreamableHttpClientConfig, SseClientConfig
};

// Streamable HTTP client
let config = StreamableHttpClientConfig {
    url: "http://example.com/mcp/instances_abc123".to_string(),
    headers: HashMap::new(),
};
run_streamable_http_client(config).await?;

// SSE client  
let config = SseClientConfig {
    url: "http://example.com/sse".to_string(),
    headers: HashMap::new(),
};
run_sse_client(config).await?;

许可证

MIT

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。