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请求。记录从服务器收到的响应。
Related MCP server: Echo MCP Server
先决条件
您的系统上安装了Node.js (建议使用 v10 或更高版本)。
入门
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 MCP JSON-RPC 客户端和服务器示例:
npx -y @smithery/cli install @melvincarvalho/mcpjs --client claude手动安装
克隆存储库:
git clone https://github.com/sandy-mount/mcpjs.git cd mcp-jsonrpc-example运行服务器:
打开终端窗口并运行:
node server.js您应该会看到如下消息:
Server listening on port 4000运行客户端:
打开另一个终端窗口并运行:
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文件。
贡献
欢迎随时提出问题或提交改进或建议的请求。
编码愉快!
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseCqualityDmaintenanceA 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.12,9331ISC
- Flicense-qualityDmaintenanceA simple demonstration MCP server that provides an echo tool and resource for learning how to build MCP servers. Serves as a starting point and template for creating custom MCP server implementations.
- Flicense-qualityDmaintenanceA Model Context Protocol (MCP) server designed for learning and experimentation. It provides a foundational setup for developers to build, run, and debug MCP server implementations using Node.js.
- Flicense-qualityDmaintenanceAn educational MCP server that teaches implementing the Model Context Protocol from scratch, enabling AI models to discover and invoke tools via JSON-RPC over stdio.
Related MCP Connectors
MCP server for understanding Javascript internals from ECMAScript specification.
A basic MCP server to operate on the Postman API.
A very simple remote MCP server that greets you, with a custom icon.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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