Back to MCP directory
publicPublicdnsLocal runtime

rgarcia_mcp-server-server

该项目是一个概念验证的MCP服务器,旨在通过WebSocket网络通信替代传统的stdio进程管理方式,简化MCP服务器的使用和配置流程。

article

README

🚀 mcp-server-server

本仓库是一个MCP服务器的概念验证项目,可用于启动其他MCP服务器,解决了传统MCP服务器使用不便的问题,提升了使用的便捷性与系统的可扩展性。

🚀 快速开始

✨ 主要特性

  • 消除进程管理:无需在客户端中 spawn多个进程来管理不同的MCP服务器。
  • 提升可扩展性:借助网络通信,能更高效地管理和路由多个用户及不同配置的请求。

📦 安装指南

将现有的stdio MCP服务器转换为WebSocket MCP服务器,可使用以下命令通过websocket暴露现有MCP服务器:

bun run mcp-server -p 3001 -- npx -y @modelcontextprotocol/server-puppeteer@latest

💻 使用示例

基础用法

无需管理进程即可程序化地与MCP服务器交互,示例代码如下:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";

const transport = new WebSocketClientTransport(new URL("ws://localhost:3001"));

const client = new Client(
  {
    name: "example-client",
    version: "1.0.0",
  },
  {
    capabilities: {},
  }
);
await client.connect(transport);
const tools = await client.listTools();
console.log(
  "工具:",
  tools.tools.map((t) => t.name)
);
await client.close();

运行示例

bun run mcp-server-wrapper-client
$ bun run src/mcp-server-wrapper/example-client/example-client.ts
工具: [ "puppeteer_navigate", "puppeteer_screenshot", "puppeteer_click", "puppeteer_fill",
  "puppeteer_evaluate"
]

🔧 技术细节

项目目标

此仓库旨在展示如何将传统的基于stdio的MCP服务器转换为通过WebSocket进行通信的网络服务器,从而简化客户端与其交互的方式。

实现步骤

  1. 将现有MCP服务器封装为WebSocket服务:使用提供的包装程序,可轻松将任何现有的MCP服务器(如Puppeteer)转换为基于WebSocket的服务。
  2. 使用SDK进行程序化交互:通过MCP SDK和WebSocket客户端传输模块,能方便地与新的WebSocket MCP服务器进行交互。
  3. 扩展至MCP服务器即服务:目前,作为MCP客户端开发人员,在第1步中仍需为特定的MCP服务器和用户配置 spawn一个程序,后续有待进一步解决。

未来方向

  1. 统一接口:开发一个通用的MCP服务器接口,让任何服务器都能轻松通过WebSocket或其他协议暴露。
  2. 自动化配置:实现自动化的用户配置管理,减少手动 spawn进程的需求。
  3. 多租户支持:构建支持多用户的架构,允许每个用户根据自身需求定制和启动不同的MCP服务器实例。

结论

将MCP服务器转换为网络服务是一项具有革命性的改进,能极大提升开发效率和系统扩展性。尽管目前仍存在一些问题需要解决,但该方向值得深入探索和实践。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client