Back to MCP directory
publicPublicdnsLocal runtime

Remote-MCP

Remote-MCP是一个类型安全、双向且简单的远程MCP通信解决方案,支持远程访问和集中管理模型上下文。

article

README

🚀 远程-MCP 项目文档

远程-MCP 是一个远程模型上下文协议的解决方案,可实现远程访问和集中管理模型上下文,为模型上下文协议提供了强大的扩展能力。

🚀 快速开始

客户端配置

  1. 安装客户端包
    npm install @remote-mcp/client
    
  2. 创建本地 MCP 服务
    import { MCPRouter, LogLevel } from "@remote-mcp/client";
    
    const mcpRouter = new MCPRouter({
      logLevel: LogLevel.DEBUG,
      name: "example-client",
      version: "1.0.0",
    });
    
    // 添加自定义工具或命令
    mcpRouter.addTool(
      "calculator",
      {
        description: "Perform basic calculations.",
        schema: z.object({
          operation: z.enum(["add", "subtract", "multiply", "divide"]),
          a: z.string(),
          b: z.string(),
        }),
      },
      async (args) => {
        // 处理计算逻辑
        return {
          content: [{ type: "text", text: `${result}` }],
        };
      }
    );
    
    // 启动服务
    mcpRouter.listen(9512);
    

服务端实现

  1. 安装服务器包
    npm install @remote-mcp/server
    
  2. 创建远程 MCP 服务
    import { MCPRouter, LogLevel } from "@remote-mcp/server";
    import { createHTTPServer } from '@trpc/server/adapters/standalone';
    
    const mcpRouter = new MCPRouter({
      logLevel: LogLevel.DEBUG,
      name: "example-server",
      version: "1.0.0",
      capabilities: {
        logging: {},
      },
    });
    
    // 添加示例工具
    mcpRouter.addTool(
      "calculator",
      {
        description:
          "Perform basic calculations. Add, subtract, multiply, divide.",
        schema: z.object({
          operation: z.enum(["add", "subtract", "multiply", "divide"]),
          a: z.string(),
          b: z.string(),
        }),
      },
      async (args) => {
        const a = Number(args.a);
        const b = Number(args.b);
    
        switch (args.operation) {
          case "add":
            return { content: [{ type: "text", text: `${a + b}` }] };
          case "subtract":
            return { content: [{ type: "text", text: `${a - b}` }] };
          // 其他操作...
        }
      }
    );
    
    // 启动 HTTP 服务
    createHTTPServer({
      router: mcpRouter,
    }).start({ port: 9512 });
    

✨ 主要特性

核心组件

  • @remote-mcp/client:客户端库,作为本地 MCP 服务运行,连接到远程实现。
  • @remote-mcp/server:服务器端库,用于创建可远程访问的 MCP 服务。

功能特点

  • 基本的类型安全客户端/服务器通信。
  • 支持基本的 MCP 命令、工具和提示功能。
  • 提供 HTTP 头部支持(包括自定义头部和身份验证中间件)。
  • 初步的错误处理改进和基础中间件支持。

示例架构

以下是远程-MCP 的示例架构图:

远程-MCP 架构示意图

📚 详细文档

为什么现在需要这个库?

当前的 MCP 实现仅限于本地使用,无法满足远程访问和集中管理的需求。远程-MCP 解决了这一痛点,为模型上下文协议提供了扩展能力,支持更多高级功能。

已有的包依赖

  • @remote-mcp/client:用于客户端通信。
  • @remote-mcp/server:用于服务器端实现。
  • trpc:支持基于 TRPC 的远程过程调用。

未来的发展路线图

计划功能

  1. 完善错误处理:改进错误处理机制,提升用户体验。
  2. 支持更多协议:扩展对更多通信协议的支持。
  3. 增强安全性:增加更多的安全特性,如 SSL 支持和令牌验证。

如何贡献?

欢迎社区成员参与项目!

免责声明

本项目仅为实验性质,不适用于生产环境。使用前请仔细阅读文档并确保充分测试。

参考资料

  1. MCP 协议文档链接
  2. TRPC 文档链接

📄 许可证

项目遵循 MIT 许可证,具体条款详见 LICENSE 文件

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