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.
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.
Server (server.js
):
initialize
: Returns a basic capabilities object (advertising an "echo" tool).echo
: Echoes back the parameters provided by the client.Client (client.js
):
initialize
request followed by an echo
request.To install MCP JSON-RPC Client and Server Example for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @melvincarvalho/mcpjs --client claude
Clone the Repository:
git clone https://github.com/sandy-mount/mcpjs.git cd mcp-jsonrpc-example
Run the Server:
Open a terminal window and run:
node server.js
You should see a message like:
Server listening on port 4000
Run the Client:
Open another terminal window and run:
node client.js
The client will connect to the server, send the initialize and echo requests, and display the responses.
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:
initialize
method, it returns a JSON‑RPC response with basic capabilities and server info.echo
method, it returns the parameters that were sent in the request.The client connects to the server, sends a JSON‑RPC initialize
request, waits a short time, and then sends an echo
request. Responses from the server are printed to the console.
You can extend this example by:
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to open issues or submit pull requests with improvements or suggestions.
Happy coding!
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!