Skip to main content
Glama

MCP JSON-RPC Server

MCP JSON-RPC 客户端和服务器示例

本仓库包含一个简单易用的 JavaScript 实现的 JSON-RPC 客户端和服务器示例,该示例受 MCP 启发,面向初学者。该项目演示了使用 Node.js 内置模块进行基本通信的流程,无需任何外部依赖。

概述

  • 服务器( server.js ):
    • 侦听 TCP 端口 4000。
    • 实现两种 JSON-RPC 方法:
      • initialize :返回一个基本功能对象(宣传“echo”工具)。
      • echo :回显客户端提供的参数。
  • 客户端( client.js ):
    • 连接到服务器的端口 4000。
    • 发送initialize请求,然后发送echo请求。
    • 记录从服务器收到的响应。

先决条件

  • 您的系统上安装了Node.js (建议使用 v10 或更高版本)。

入门

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 MCP JSON-RPC 客户端和服务器示例:

npx -y @smithery/cli install @melvincarvalho/mcpjs --client claude

手动安装

  1. 克隆存储库:
    git clone https://github.com/sandy-mount/mcpjs.git cd mcp-jsonrpc-example
  2. 运行服务器:打开终端窗口并运行:
    node server.js
    您应该会看到如下消息:
    Server listening on port 4000
  3. 运行客户端:打开另一个终端窗口并运行:
    node client.js
    客户端将连接到服务器,发送初始化和回显请求,并显示响应。

工作原理

  • 服务器在端口 4000 上监听传入的 TCP 连接。当它收到 JSON-RPC 消息(每个消息都以换行符结尾)时,它会处理该请求:
    • 对于initialize方法,它返回具有基本功能和服务器信息的 JSON-RPC 响应。
    • 对于echo方法,它返回请求中发送的参数。
    • 如果请求了未知方法,它会以 JSON-RPC 错误进行响应。
  • 客户端连接到服务器,发送 JSON-RPC initialize请求,等待一小段时间,然后发送echo请求。服务器的响应将打印到控制台。

文件

  • server.js — JSON-RPC 服务器实现。
  • client.js — JSON-RPC 客户端实现。

定制

您可以通过以下方式扩展此示例:

  • 向服务器添加更多 JSON-RPC 方法。
  • 实施额外的错误处理和日志记录。
  • 尝试不同的传输协议或添加 TLS 支持。

执照

本项目遵循 MIT 许可证。详情请参阅LICENSE文件。

贡献

欢迎随时提出问题或提交改进或建议的请求。


编码愉快!

-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

一个使用 Node.js 构建的适合初学者的 MCP 启发式 JSON-RPC 服务器,通过“初始化”功能握手和“回显”功能提供基本的客户端-服务器交互。

  1. 概述
    1. 先决条件
      1. 入门
        1. 通过 Smithery 安装
        2. 手动安装
      2. 工作原理
        1. 文件
          1. 定制
            1. 执照
              1. 贡献

                Related MCP Servers

                • A
                  security
                  A
                  license
                  A
                  quality
                  A Model Context Protocol (MCP) server that provides JSON-RPC functionality through OpenRPC.
                  Last updated -
                  2
                  7
                  33
                  JavaScript
                  Apache 2.0
                  • Apple
                • -
                  security
                  F
                  license
                  -
                  quality
                  A Node.js-based MCP server implementing JSON-RPC 2.0, allowing users to generate random US State and signature soup combinations through a fun and simple tool.
                  Last updated -
                  1
                  1
                  JavaScript
                  • Apple
                  • Linux
                • -
                  security
                  A
                  license
                  -
                  quality
                  An MCP server that enables fetching web content using the Node.js undici library, supporting various HTTP methods, content formats, and request configurations.
                  Last updated -
                  66
                  8
                  TypeScript
                  MIT License
                  • Apple
                  • Linux
                • -
                  security
                  A
                  license
                  -
                  quality
                  A Node.js package that provides Model Context Protocol server infrastructure for AWS Lambda functions with SSE support, enabling developers to implement MCP tools and prompts as serverless functions.
                  Last updated -
                  112
                  9
                  TypeScript
                  MIT License

                View all related MCP servers

                MCP directory API

                We provide all the information about MCP servers via our MCP API.

                curl -X GET 'https://glama.ai/api/mcp/v1/servers/melvincarvalho/mcpjs'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server