MCP JSON-RPC Client and Server Example
This repository contains a simple, beginner-friendly example of an MCP-inspired JSON‑RPC client and server implemented in JavaScript. The project demonstrates a basic communication flow using Node.js's built‑in modules without any external dependencies.
Overview
- Server (
server.js
):- Listens on TCP port 4000.
- Implements two JSON‑RPC methods:
initialize
: Returns a basic capabilities object (advertising an "echo" tool).echo
: Echoes back the parameters provided by the client.
- Client (
client.js
):- Connects to the server on port 4000.
- Sends an
initialize
request followed by anecho
request. - Logs the responses received from the server.
Prerequisites
- Node.js installed on your system (v10 or later is recommended).
Getting Started
Installing via Smithery
To install MCP JSON-RPC Client and Server Example for Claude Desktop automatically via Smithery:
Manual Installation
- Clone the Repository:Copy
- Run the Server:Open a terminal window and run:You should see a message like:CopyCopy
- Run the Client:Open another terminal window and run:The client will connect to the server, send the initialize and echo requests, and display the responses.Copy
How It Works
- The server listens for incoming TCP connections on port 4000. When it receives a JSON‑RPC message (each terminated by a newline), it processes the request:
- For the
initialize
method, it returns a JSON‑RPC response with basic capabilities and server info. - For the
echo
method, it returns the parameters that were sent in the request. - If an unknown method is requested, it responds with a JSON‑RPC error.
- For the
- The client connects to the server, sends a JSON‑RPC
initialize
request, waits a short time, and then sends anecho
request. Responses from the server are printed to the console.
Files
- server.js — The JSON‑RPC server implementation.
- client.js — The JSON‑RPC client implementation.
Customization
You can extend this example by:
- Adding more JSON‑RPC methods to the server.
- Implementing additional error handling and logging.
- Experimenting with different transport protocols or adding TLS support.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Feel free to open issues or submit pull requests with improvements or suggestions.
Happy coding!
This server cannot be installed
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.
A beginner-friendly MCP-inspired JSON-RPC server built with Node.js, offering basic client-server interaction through an 'initialize' capabilities handshake and an 'echo' function.
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol (MCP) server that provides JSON-RPC functionality through OpenRPC.Last updated -2733JavaScriptApache 2.0
- -securityFlicense-qualityA 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 -11JavaScript
- -securityAlicense-qualityAn MCP server that enables fetching web content using the Node.js undici library, supporting various HTTP methods, content formats, and request configurations.Last updated -668TypeScriptMIT License
- -securityAlicense-qualityA 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 -1129TypeScriptMIT License