Token导航 LogoToken导航TokenDH.com
mcp2rest (Ulasbilgen) logo
运维云端未说明官方级别未说明来源级核验

mcp2rest (Ulasbilgen)

MCP Server

一个独立的Node.js守护进程,管理多个MCP服务器并通过REST API暴露其工具,使开发者能够使用任何编程语言调用MCP工具。

工具数

1

提示词数

0

GitHub Stars

0

资源数

0
API集成TypeScript多语言支持本地部署

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

ulasbilgen

提供方

ulasbilgen

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

mcp2rest

⚠️ 已存档:此存储库已被移动 此项目不再在此存储库中维护。它已被移至: https://github.com/ulasbilgen/mcp2skill-tools 请访问新存储库以获取最新更新、问题和文档。 API和CLI命令保持相同,从而实现无缝迁移。

______________________________________________________________________

一个独立的Node.js守护进程,用于管理多个MCP(模型上下文协议)服务器,并通过REST API公开其工具。mcp2rest提供了一个通用的HTTP接口,允许使用任何编程语言的开发人员在没有Node.js集成复杂性的情况下利用MCP工具。

特性

  • 通用HTTP接口:通过REST API从任何语言访问MCP工具
  • 多服务器管理:同时连接到多个MCP服务器
  • 动态服务器管理:添加/删除服务器而不重新启动
  • 后台守护程序:使用PM2作为系统服务运行
  • 自动重新连接:优雅地处理服务器断开连接
  • 命令行界面:易于使用的命令行界面

安装

通过npm全局安装:

npm install -g mcp2rest

快速开始

1.启动网关

在前台模式下启动网关:

mcp2rest start

或作为系统服务安装(推荐):

mcp2rest service install

2.添加MCP服务器

添加Chrome DevTools MCP服务器:

mcp2rest add chrome chrome-devtools-mcp@latest

3.调用工具

使用任何HTTP客户端调用工具:

curl -X POST http://localhost:28888/call \
  -H "Content-Type: application/json" \
  -d '{
    "server": "chrome",
    "tool": "navigate",
    "arguments": {
      "url": "https://example.com"
    }
  }'

API终点

执行工具

在特定的MCP服务器上执行工具。

端点: POST /call

请求正文:

{
  "server": "chrome",
  "tool": "navigate",
  "arguments": {
    "url": "https://example.com"
  }
}

答复:

{
  "success": true,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Navigated to https://example.com"
      }
    ]
  }
}

列出服务器

获取所有连接的服务器及其状态。

端点: GET /servers

答复:

{
  "servers": [
    {
      "name": "chrome",
      "package": "chrome-devtools-mcp@latest",
      "status": "connected",
      "toolCount": 5
    }
  ]
}

获取服务器工具

列出特定服务器的所有可用工具。

端点: GET /servers/:name/tools

答复:

{
  "server": "chrome",
  "tools": [
    {
      "name": "navigate",
      "description": "Navigate to a URL",
      "inputSchema": { ... }
    }
  ]
}

添加服务器

动态添加新的MCP服务器。

端点: POST /servers

请求正文:

{
  "name": "filesystem",
  "package": "@modelcontextprotocol/server-filesystem",
  "args": ["/home/user/workspace"]
}

删除服务器

卸下MCP服务器。

端点: DELETE /servers/:name

健康检查

检查网关运行状况。

端点: GET /health

答复:

{
  "status": "ok",
  "serverCount": 2,
  "connectedServers": 2
}

OpenAPI规范

获取OpenAPI/Swagger格式的完整API规范。

端点: GET /openapi.yaml

答复: 具有完整API规范的YAML文件

例子:

curl http://localhost:28888/openapi.yaml > mcp2rest-api.yaml

此规范可以与Swagger UI、Postman或其他OpenAPI工具一起使用,以探索和测试API。

CLI命令

网关管理

# Start gateway in foreground (default port 28888)
mcp2rest start

# Start with custom port and host
mcp2rest start --port 4000 --host 0.0.0.0

# Start with custom config file
mcp2rest start --config /path/to/config.yaml

# Stop gateway
mcp2rest stop

服务管理

# Install as system service
mcp2rest service install

# Uninstall service
mcp2rest service uninstall

# Check service status
mcp2rest service status

# View service logs
mcp2rest service logs

# Follow logs in real-time
mcp2rest service logs --follow

服务器管理

# Add a server
mcp2rest add  
 [--args  ]

# Examples:
mcp2rest add chrome chrome-devtools-mcp@latest
mcp2rest add fs @modelcontextprotocol/server-filesystem --args /home/user/workspace

配置

配置存储在 ~/.mcp2rest/config.yaml:

servers:
  chrome:
    package: chrome-devtools-mcp@latest
    args: []
  
  filesystem:
    package: "@modelcontextprotocol/server-filesystem"
    args: ["/home/user/workspace"]

gateway:
  port: 28888
  host: localhost
  timeout: 30000
  logLevel: info

端口和主机配置

mcp2rest支持多种配置端口和主机的方式,优先级顺序如下(从高到低):

  1. CLI标志 (最高优先级)
  2. 环境变量
  3. 配置文件
  4. 默认值 (端口:28888,主机:localhost)

使用CLI标志

# Start with custom port
mcp2rest start --port 4000

# Start with custom host
mcp2rest start --host 0.0.0.0

# Start with both
mcp2rest start --port 4000 --host 0.0.0.0

使用环境变量

# Set port via environment variable
MCP2REST_PORT=4000 mcp2rest start

# Set host via environment variable
MCP2REST_HOST=0.0.0.0 mcp2rest start

# Set both
MCP2REST_PORT=4000 MCP2REST_HOST=0.0.0.0 mcp2rest start

使用配置文件

编辑 ~/.mcp2rest/config.yaml:

gateway:
  port: 4000
  host: 0.0.0.0

更改服务端口

要更改已安装服务的端口,请执行以下操作:

# 1. Edit the configuration file
nano ~/.mcp2rest/config.yaml
# Change gateway.port to your desired port

# 2. Reinstall the service (updates PM2 config)
mcp2rest service install

# 3. Restart the service
mcp2rest service restart

service install命令会自动从配置文件中读取端口和主机,并相应地配置PM2服务。

示例:Python客户端

import requests

# Execute a tool
response = requests.post('http://localhost:28888/call', json={
    'server': 'chrome',
    'tool': 'navigate',
    'arguments': {
        'url': 'https://example.com'
    }
})

result = response.json()
print(result)

示例:Go客户端

package main

import (
    "bytes"
    "encoding/json"
    "net/http"
)

func main() {
    payload := map[string]interface{}{
        "server": "chrome",
        "tool": "navigate",
        "arguments": map[string]string{
            "url": "https://example.com",
        },
    }
    
    jsonData, _ := json.Marshal(payload)
    resp, _ := http.Post(
        "http://localhost:28888/call",
        "application/json",
        bytes.NewBuffer(jsonData),
    )
    defer resp.Body.Close()
}

错误处理

所有错误都遵循一致的格式:

{
  "error": {
    "code": "SERVER_NOT_FOUND",
    "message": "Server 'chrome' not found",
    "serverName": "chrome"
  }
}

常见错误代码:

  • SERVER_NOT_FOUND:指定的服务器不存在
  • SERVER_DISCONNECTED:服务器未连接
  • TOOL_NOT_FOUND:服务器上不存在工具
  • TOOL_EXECUTION_ERROR:工具执行失败
  • TOOL_TIMEOUT:工具执行时间超过30秒
  • INVALID_ARGUMENTS:请求参数无效

需求

  • Node.js>=18.0.0
  • npm或npx

最近完成✅

  • \[x\] 自定义端口和主机配置 (v0.2.8)

- CLI标志: --port--host 用于启动命令 - 环境变量: MCP2REST_PORTMCP2REST_HOST - 优先级顺序:CLI标志>环境变量>配置文件>默认值 - PM2服务集成:使用配置文件设置自动配置服务 - 动态端口检测 addremove CLI命令

  • \[x\] 自动重新连接:当MCP服务器断开连接时,通过指数回退自动重新连接

- 实施于 src/gateway/Gateway.ts - 最多10次指数回退的重新连接尝试 - 从服务器崩溃中自动恢复

  • \[x\] 删除端点: DELETE /servers/:name REST端点

- 实施于 src/api/APIServer.ts - 通过API动态删除服务器

TODO

中优先级

  • \[\]可选CLI便利命令(列表、工具、删除)

- 注意:REST API已经提供了此功能

未来的增强功能

- 基于HTTP的MCP服务器的HTTP标头 - 基于stdio的MCP服务器的环境变量 - 支持Context7、PostHog、Figma Cloud等服务。

  • 速率限制
  • WebSocket支持流媒体
  • 基于Web的仪表板
  • 工具结果缓存

许可证

麻省理工学院

贡献

欢迎投稿!请打开问题或提交拉取请求。

文档

目录标签

目录标签

API集成TypeScript多语言支持本地部署RESTAPIMCP服务器管理动态服务器管理

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP