使用说明
mcp遥控器
一个基于Go的npm替代品 mcp-remote 包裹。通过HTTP/SSE在stdio JSON-RPC和远程MCP服务器之间充当透明的双向代理,完全支持OAuth 2.1。
stdin (JSON-RPC) --> mcp-remote-go --> HTTP POST / SSE --> Remote MCP Server
stdout (JSON-RPC) <-- <-- HTTP Response <--
stderr (diagnostics)
为什么?
- 修复
expires_in对比expires_at令牌过期错误 - 令牌存储的原子文件写入(崩溃时不会损坏)
- 互斥保护令牌刷新(无重复刷新竞赛)
- 自动
invalid_grant/invalid_client重试恢复 - 约6 MB静态二进制文件与约61 MB Bun捆绑包
安装
来源
git clone https://github.com/anthropics/mcp-remote-go.git
cd mcp-remote-go
make build-arm64 # macOS Apple Silicon
make build-amd64 # macOS Intel
make build-linux # Linux amd64
二进制文件输出到 dist/mcp-remote-go-<platform>.
用法
mcp-remote-go <server-url> [options]
选项
| 标志 | 默认值 | 描述 |
|---|---|---|
--transport |
http-first |
运输策略: http-first, sse-first, http-only, sse-only |
--header |
自定义HTTP标头(Key: Value 格式,可重复) |
|
--host |
localhost |
OAuth重定向URI的回调主机名 |
--allow-http |
false |
允许非HTTPS服务器URL |
--debug |
false |
启用stderr的详细日志记录 |
例子
# Basic usage
mcp-remote-go https://mcp.example.com/v1/mcp
# With custom headers
mcp-remote-go https://mcp.example.com --header "X-Api-Key: sk-123"
# Force SSE transport
mcp-remote-go https://mcp.example.com --transport sse-only
# Local development
mcp-remote-go http://localhost:3000/mcp --allow-http --debug
MCP客户端配置
在克劳德桌面(claude_desktop_config.json):
{
"mcpServers": {
"my-server": {
"command": "/path/to/mcp-remote-go",
"args": [
"https://mcp.example.com/v1/mcp"
]
}
}
}
具有标头和传输选项:
{
"mcpServers": {
"my-server": {
"command": "/path/to/mcp-remote-go",
"args": [
"https://mcp.example.com/v1/mcp",
"--header", "X-Api-Key: sk-123",
"--transport", "http-first"
]
}
}
}
认证
OAuth 2.1在服务器返回时自动处理 401 Unauthorized:
- 通过RFC 9728(资源元数据)或RFC 8414(众所周知)发现授权服务器
- 动态注册客户端(RFC 7591)
- 打开浏览器,使用PKCE登录(S256)
- 捕获本地主机端口上的回调
- 将代码交换为令牌并缓存它们
代币存储在 ~/.mcp-auth/ (用覆盖 MCP_REMOTE_CONFIG_DIR).令牌刷新在到期前60秒主动发生。如果刷新失败 invalid_grant,令牌将被擦除,并重试完整的身份验证流(最多3次)。
运输谈判
默认 http-first 策略发送第一个真实消息(例如。, initialize)通过流式HTTP POST:
- 如果服务器成功响应(或出现非404/405错误),则继续使用流式HTTP
- 如果服务器返回404或405,则返回到传统SSE
未发送探测请求。这个决定是在第一个真正的信息上懒散地做出的。
其他策略: sse-first (尝试SSE,回退到HTTP), http-only, sse-only.
发展
# Run all tests with race detector
make test
# Run a single package's tests
go test -v -race ./internal/transport/...
# Run a single test
go test -v -race -run TestFallback_404FallsBackToSSE ./internal/transport/...
# Build for current platform
make build
许可证
无许可证 --公共领域。MCP工具应该是共享的基础设施,而不是任何人拥有的东西。
