🌉 REST MCP代理
在几秒内将任何MCP服务器转换为REST API
 ](https://nodejs.org/) 
弥合强大的MCP(模型上下文协议)服务器和热爱REST的应用程序之间的差距。没有更复杂的协议实现,只有简单的HTTP调用。
✨ 是什么让这个特别?
🚀 零配置复杂性 -适用于您现有的MCP服务器配置\ 🔌 通用兼容性 -任何MCP服务器都会立即成为REST端点\ 🛡️ 企业就绪 -内置身份验证、错误处理和日志记录\ 📊 工具发现 -从MCP模式自动生成API文档\ ⚡ 高性能 -具有连接池的持久连接\ 🎯 开发者友好 -直观的REST端点,具有灵活的参数传递
🎯 非常适合
- 集成团队 构建基于REST的工作流
- DevOps工程师 将MCP工具连接到现有基础设施
- API开发人员 需要MCP功能而不需要协议复杂性的人
- 自动化脚本 与stdio协议相比,它更适合HTTP
- 遗留系统 不能直接实现MCP
🚀 快速开始
1.克隆和安装
git clone https://github.com/yourusername/rest-mcp-proxy.git
cd rest-mcp-proxy
npm install2.配置您的MCP服务器
cp mcp_settings.json.example mcp_settings.json
cp env.example .env编辑 mcp_settings.json 使用您的MCP服务器配置:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
},
"brave-search": {
"command": "npx",
"args": ["@modelcontextprotocol/server-brave-search"],
"env": {
"BRAVE_API_KEY": "your-api-key-here"
}
}
}
}3.设置API密钥
echo "API_KEY=your-secure-api-key-here" > .env4.发射
npm start就是这样!您的MCP服务器现在可以通过REST API访问,网址为 http://localhost:3000 🎉
📡 API使用
列出可用工具
curl -H "x-api-key: your-api-key" http://localhost:3000/tools执行工具(GET)
# Simple tool call
curl -H "x-api-key: your-api-key" \
"http://localhost:3000/tool?tool=read_file&path=/etc/hosts"
# Multiple parameters in tool query
curl -H "x-api-key: your-api-key" \
"http://localhost:3000/tool?tool=search query=nodejs limit=10"执行工具(POST)
curl -X POST \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"path": "/etc/hosts", "encoding": "utf8"}' \
"http://localhost:3000/tool?tool=read_file"外部系统的导出工具
以标准化格式获取所有工具以进行集成:
curl -H "x-api-key: your-api-key" http://localhost:3000/serialize-tools🔧 高级功能
灵活的参数传递
选择适合您工作流程的方法:
- URL参数 (非常适合简单的通话)
/tool?tool=search&query=nodejs&limit=10- 工具查询语法 (干净易读)
/tool?tool=search query=nodejs limit=10- JSON正文 (非常适合复杂数据)
POST /tool?tool=create_file
{
"path": "/tmp/example.txt",
"content": "Hello World!",
"permissions": 644
}多种身份验证方法
- 基于标头:
x-api-key: your-key - 查询参数:
?api_key=your-key
健康监测
curl http://localhost:3000/health返回服务器状态、已连接的MCP服务器和可用工具计数。
🏗️ 建筑
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ REST Client │ │ MCP Proxy │ │ MCP Server │
│ │───▶│ │───▶│ │
│ (Your App) │ │ (This Project) │ │ (File System) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ MCP Server │
│ │
│ (Web Search) │
└─────────────────┘代理保持与所有配置的MCP服务器的持久连接,将其工具聚合到统一的RESTneneneba API表面。
🔒 安全功能
- API密钥验证 -保护您的端点
- 请求验证 -使用MCP模式进行自动参数验证
- 错误清理 -没有内部详细信息的安全错误消息
- 连接安全性 -MCP服务器通信安全
🌟 用例
CI/CD集成
# GitHub Actions example
- name: Read deployment config
run: |
curl -H "x-api-key: ${{ secrets.MCP_API_KEY }}" \
"$MCP_PROXY_URL/tool?tool=read_file path=config/production.yml"Webhook 自动化
// Process webhook with MCP tool
app.post('/webhook', async (req, res) => {
const result = await fetch(`${MCP_PROXY_URL}/tool?tool=process_webhook`, {
method: 'POST',
headers: { 'x-api-key': process.env.MCP_API_KEY },
body: JSON.stringify(req.body)
});
res.json(await result.json());
});外部工具集成
将您的MCP工具导出到工作流自动化平台:
# Generate tool definitions for Zapier, Make.com, etc.
curl -H "x-api-key: your-key" \
http://localhost:3000/serialize-tools > mcp-tools.json🛠️ 配置参考
环境变量
PORT=3000 # Server port (default: 3000)
API_KEY=your-secure-key # API authentication keyMCP设置格式
使用与Claude Desktop应用程序相同的格式以实现最大兼容性:
{
"mcpServers": {
"server-name": {
"command": "executable",
"args": ["arg1", "arg2"],
"env": {
"ENV_VAR": "value"
}
}
}
}📈 监测和可观察性
代理提供详细的日志记录和状态信息:
- 启动日志 -每个MCP服务器的连接状态
- 工具发现 -可用工具的自动编目
- 请求日志记录 -跟踪API的使用情况和性能
- 健康终点 -以编程方式监视系统状态
🤝 贡献
我们热爱贡献!无论是:
- 🐛 Bug报告和修复
- ✨ 新功能和增强功能
- 📚 文档改进
- 🧪 测试和质量改进
查看我们的 贡献指南 开始吧。
📜 许可证
ISC许可证-请参阅 许可证 文件以获取详细信息。
🔗 相关项目
______________________________________________________________________
由以下材料制成❤️ 对于MCP社区
⭐ 标记此回购 如果它能帮助你构建惊人的集成!
