A Simple MCP Server and Client
LocalAbout A Simple MCP Server and Client
A small MCP server and client example for exploring city resources, weather forecasts, and travel advice. It demonstrates stdio communication and logs the underlying JSON-RPC messages for developers learning MCP.
Key features
- 01City information resources
- 02Weather forecast tool
- 03Weather-based travel prompt
- 04stdio client-server communication
- 05Human-readable JSON-RPC logs
Use cases
- 01Learn how MCP resources, tools, and prompts work
- 02Inspect JSON-RPC traffic while debugging
- 03Try a client that starts its server process
MCP support
The server exposes city resources, a weather tool, and a travel-advice prompt to MCP clients. The included client connects over stdio and demonstrates reading resources, calling the tool, and retrieving the prompt.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEA Simple MCP Server and Client
This is a simple Model Context Protocol (MCP) server and client implementation that demonstrates how to expose and access weather information.
Server
The server is implemented in server.js. It provides the following capabilities:
-
Resources:
city://NewYork: Basic information about New York Citycity://London: Basic information about Londoncity://Tokyo: Basic information about Tokyo
-
Tools:
get-weather: Get weather forecast for a city with parameters for city name and number of days
-
Prompts:
weather-advice: Get travel advice based on weather conditions
Client
The client is implemented in client.js. It demonstrates how to:
- Connect to the MCP server
- List available resources
- Read a specific city resource
- Call the weather forecast tool
- Get a weather advice prompt
JSON-RPC Communication
This implementation uses JSON-RPC 2.0 as the underlying communication protocol between client and server. Key JSON-RPC concepts used:
- Methods: Standard method names like
resources/list,resources/read,tools/call, andprompts/get - Parameters: Input data sent with method calls
- Request IDs: Unique identifiers to match requests with responses
- Results/Errors: Structured response data or error information
The MCP SDK abstracts much of this, but understanding the protocol is helpful for debugging and customization. You can see the raw JSON-RPC messages by examining the console output.
Running the Server and Client
-
Start the client:
node client.jsStarting the client will automatically start the server as a child process. The client will connect to the server and perform all the example operations.
-
To start the server independently:
node server.js
Transport Mechanism
This example uses stdio (standard input/output) as the transport mechanism between client and server. When the client is started, it spawns the server as a child process and communicates with it through stdin/stdout streams.
A custom logging transport is implemented to show the messages exchanged between the client and server. These messages are logged to the console in a human-readable format, which is helpful for understanding the protocol.
Troubleshooting
If you encounter issues with resource or prompt requests timing out, check the server implementation. The example includes direct message handling for certain request types to work around limitations in the current SDK version.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.