MCP代理
](https://badge.fury.io/js/mcp-agent-proxy)  
将任何MCP客户端连接到任何代理服务器,通过简单、可组合的原语创建“代理互联网”。
快速开始
将此添加到MCP客户端的配置中:
{
"mcpServers": {
"mcpAgentProxy": {
"command": "npx",
"args": ["mcp-agent-proxy@latest"]
}
}
}就是这样! 代理允许您的MCP客户端连接到不同的代理服务器,并将代理交互作为MCP工具公开。它会自动检测代理服务器类型并相应地进行调整。
https://github.com/user-attachments/assets/9eaf1d36-298f-430f-b9e8-37e921cce2d1
这有什么作用
我们提供 5个简单工具 让代理在无限的网络上发现、连接和编排:
| 工具 | 目的 |
|---|---|
listAgents | 发现所有服务器上的可用代理 |
describeAgent | 获取智能路由的详细代理功能 |
callAgent | 使用智能冲突解决执行任何代理 |
connectServer | 在运行时动态添加新的代理服务器 |
disconnectServer | 删除动态连接的服务器 |
支持的服务器类型
- 马斯特拉:支持本地和远程Mastra服务器
- LangGraph:支持本地和远程LangGraph实例
- 可扩展:插件架构使添加对其他代理框架的支持变得容易
网络效应
代理服务器本身可以是MCP客户端,创建递归代理网络:
Your MCP Client → MCP Proxy → Agent Server (Mastra/LangGraph) → Agents -> MCP Proxy -> Other Agent Servers → 🚀 Agents一条配置线解锁了整个AI功能生态系统。
MCP合规性和功能
✅ 完全符合MCP 2025-03-26标准
- 完成最新模型上下文协议规范的实现
🚀 多运输支持
- 标准运输:标准MCP客户端集成(
npx mcp-agent-proxy) - 流式HTTP:具有会话管理的现代基于HTTP的传输
- 传统SSE:与现有SSE实现向后兼容
- 自动检测:根据客户端功能在传输之间无缝切换
常见配置
多台服务器(混合类型)
{
"mcpServers": {
"mcpAgentProxy": {
"command": "npx",
"args": ["mcp-agent-proxy"],
"env": {
"AGENT_SERVERS": "http://localhost:4111 http://localhost:2024"
}
}
}
}云+本地(混合Mastra和LangGraph)
{
"mcpServers": {
"mcpAgentProxy": {
"command": "npx",
"args": ["mcp-agent-proxy"],
"env": {
"AGENT_SERVERS": "https://my-mastra.vercel.app http://localhost:2024"
}
}
}
}来源(发展)
{
"mcpServers": {
"mcpAgentProxy": {
"command": "node",
"args": ["/path/to/mcp-agent-proxy/dist/mcp-server.js"],
"env": {
"AGENT_SERVERS": "http://localhost:4111"
}
}
}
}使用示例
基本代理呼叫:
Can you call the weatherAgent to get the current weather in New York City?网络探索
Explore the agents you're connected to智能冲突解决:
I need to use the weatherAgent from server1 specifically, not the default one动态网络扩展:
Connect to the ML specialists at https://ml-specialists.vercel.app and then use their modelTrainer agent环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
AGENT_SERVERS | _(无)_ | 空格/逗号分隔的服务器URL(支持Mastra和LangGraph) |
MCP_SERVER_PORT | 3001 | 代理服务器端口 |
MCP_TRANSPORT | http | 传输方式(stdio/http) |
示例和高级用法
中的即用型配置 examples/ 目录:
mcp.json-零设置multi-server-config.json-多个本地服务器vercel-config.json-云部署
有关高级配置选项,请参阅 配置.md.
故障排除
NPX问题:
npx clear-npx-cache
npx mcp-agent-proxy@latest端口冲突:
"env": { "MCP_SERVER_PORT": "3002" }连接问题:
- 确保代理服务器正在运行且可访问
- 检查防火墙设置和服务器URL
- 对于LangGraph:默认端口通常为2024(
langgraph dev) - 对于Mastra:默认端口通常为4111
调试模式:
DEBUG=mastra:* npx mcp-agent-proxy开发与测试
验证工作流
我们实施了全面的验证工作流程,以确保代码质量和MCP协议合规性:
快速命令
# Quick validation (build + test + lint + format)
pnpm validate:quick
# Full validation (includes integration tests + health checks)
pnpm validate:full
# CI validation (includes coverage + dead code analysis)
pnpm validate:ci单个命令
# Build and test
pnpm build
pnpm test
pnpm test:integration
# Code quality
pnpm lint
pnpm format
pnpm format:checkMCP协议测试
# Test MCP protocol compliance
pnpm mcp:test
# Test security features
pnpm security:test
# Manual server testing
pnpm start # Start server
pnpm check # Check running server (requires jq)测试覆盖率
- 总共355次测试 覆盖所有组件
- 单元测试 适用于所有工具、插件和配置
- 集成测试 符合MCP协议
- 安全测试 用于源验证和会话管理
- 健康检查 用于服务器监控
可用脚本
使用 pnpm run 查看所有可用脚本,或使用以下常见脚本:
pnpm dev # Build and start development server
pnpm test # Run all tests
pnpm test:watch # Run tests in watch mode
pnpm build # Build for production
pnpm lint # Run ESLint
pnpm format # Format code with Prettier贡献
我们欢迎捐款!请查看我们的 贡献指南 了解详情。
许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
______________________________________________________________________
_构建代理互联网,一次一个连接。_
