MCP通过插座
一个网桥,允许您通过SOCKS5代理连接到SSE/流式HTTP MCP(模型上下文协议)服务器。此工具在本地充当stdio MCP服务器,使Cursor和其他MCP客户端能够访问只能通过SOCKS代理访问的远程MCP服务器。
使用 官方MCP Go SDK ().
特性
- SOCKS5代理支持:通过SOCKS5代理连接到MCP服务器
- socks5:// -本地DNS解析(连接前解析主机名) - socks5h:// -远程DNS解析(让代理解析主机名)
- 苏格兰和南方能源公司运输:完全支持服务器发送事件MCP传输
- 可流式HTTP传输:支持流式HTTP MCP传输
- 自动检测:自动检测传输类型(SSE与流式HTTP)
- 单一二进制:运行时没有外部依赖关系
- 跨平台:适用于macOS、Linux和Windows
安装
来源
git clone https://github.com/iiharu/mcp-over-socks.git
cd mcp-over-socks
make build使用Go安装
go install github.com/iiharu/mcp-over-socks/cmd/mcp-over-socks@latest用法
基本用法
# Local DNS resolution (resolve hostname before connecting to proxy)
mcp-over-socks --proxy socks5://localhost:1080 --server http://mcp.example.com/sse
# Remote DNS resolution (let the proxy resolve the hostname)
mcp-over-socks --proxy socks5h://localhost:1080 --server http://internal-server.corp.local/sse使用 socks5h:// 当MCP服务器主机名仅在远程网络内可解析时(例如内部DNS名称)。
命令行选项
Usage: mcp-over-socks [options]
Required:
--proxy SOCKS5 proxy URL
- socks5://host:port (local DNS resolution)
- socks5h://host:port (remote DNS resolution)
--server Remote MCP server URL (e.g., http://remote:8080/sse)
Optional:
--timeout Request timeout (default: 30s)
--log Log level: debug, info, error (default: info)
--transport Transport type: auto, sse, streamable (default: auto)
--version Show version and exit
--help Show this help message光标配置
添加到您的 ~/.cursor/mcp.json:
{
"mcpServers": {
"remote-mcp": {
"command": "/path/to/mcp-over-socks",
"args": [
"--proxy", "socks5://localhost:1080",
"--server", "http://your-mcp-server.example.com/sse"
]
}
}
}使用SSH SOCKS代理
- 启动SSH SOCKS代理:
ssh -D 1080 -N user@jump-host- 配置Cursor以使用网桥:
{
"mcpServers": {
"internal-mcp": {
"command": "mcp-over-socks",
"args": [
"--proxy", "socks5h://127.0.0.1:1080",
"--server", "http://internal-server.corp.example.com/mcp/sse"
]
}
}
}备注:使用 socks5h:// 当内部服务器主机名只能从跳转主机解析时。建筑
Cursor (MCP Client)
↓ stdio (JSON-RPC)
mcp-over-socks (Bridge)
↓ SOCKS5 Proxy
↓ HTTP/SSE or Streamable HTTP
Remote MCP Server桥:
- 通过stdin从Cursor接收JSON-RPC请求
- 通过SOCKS5代理将它们转发到远程MCP服务器
- 通过stdout返回对Cursor的响应
- 将错误和状态记录到stderr
发展
建筑
make build # Build for current platform
make build-all # Build for all platforms
make test # Run tests
make lint # Run linter
make clean # Clean build artifacts运行测试
go test -v ./...项目结构
.
├── cmd/
│ └── mcp-over-socks/
│ └── main.go # Entry point
├── internal/
│ ├── bridge/
│ │ ├── bridge.go # Main bridge logic (uses official MCP SDK)
│ │ └── errors.go # Error types
│ ├── config/
│ │ └── config.go # Configuration
│ ├── logging/
│ │ └── logger.go # Logger
│ └── transport/
│ └── socks.go # SOCKS5 dialer
├── tests/
│ └── unit/
├── Makefile
└── README.md依赖项
- -官方MCP Go SDK
- golang.org/x/net/proxy -SOCKS5代理支持
故障排除
无法连接到SOCKS代理
- 验证SOCKS代理是否正在运行
- 检查代理地址格式:
socks5://host:port或socks5h://host:port - 确保没有防火墙阻止连接
无法解析内部主机名
如果您连接到的内部服务器的主机名只能在远程网络中解析:
- 使用
socks5h://而不是socks5://启用远程DNS解析 - 验证主机名是否正确,并且可以从代理服务器解析
无法连接到MCP服务器
- 验证MCP服务器是否正在运行并且可以通过代理访问
- 检查服务器URL格式
- 尝试连接
curl首先通过代理:
curl --proxy socks5://localhost:1080 http://mcp-server/sse调试记录
启用调试日志记录以查看详细信息:
mcp-over-socks --proxy socks5://localhost:1080 --server http://example.com/sse --log debug 2>debug.log已知限制
- 无自动重新连接:如果SOCKS代理连接丢失,网桥将退出。您需要重新启动网桥(或依靠Cursor重新启动它)。
- 认证:通过URL语法支持SOCKS5身份验证:
socks5://user:password@host:port.
许可证
MIT许可证-请参阅 许可证 了解详情。
