mcp-sse
by: sidharthrajaram
A working pattern for SSE-based MCP clients and servers
📌Overview
Purpose: To demonstrate a scalable, decoupled architecture for building SSE-based MCP servers and clients that can operate independently.
Overview: This project provides a server and client implementation utilizing Server-Sent Events (SSE) within the Model Context Protocol (MCP). Designed to work seamlessly in cloud-native environments, it allows for dynamic interaction between clients and a server, enabling flexible querying capabilities for various tools, such as weather forecasts.
Key Features:
-
Decoupled Processes: The MCP server and clients can operate independently, allowing for connections and disconnections at will, enhancing flexibility and cloud-native compatibility.
-
SSE Client and Server: Offers a simple implementation for both server (
weather.py
) and client (client.py
) using the National Weather Service APIs for the client to retrieve weather data based on user queries.
SSE-based Server and Client for MCP
This demonstrates a working pattern for SSE-based MCP servers and standalone MCP clients that use tools from them. Based on an original discussion here.
Usage
Note: Make sure to supply ANTHROPIC_API_KEY
in .env
or as an environment variable.
uv run weather.py
uv run client.py http://0.0.0.0:8080/sse
Example client interaction:
Initialized SSE client...
Listing tools...
Connected to server with tools: ['get_alerts', 'get_forecast']
MCP Client Started!
Type your queries or 'quit' to exit.
Query: whats the weather like in Spokane?
I can help you check the weather forecast for Spokane, Washington. I'll use the get_forecast function, but I'll need to use Spokane's latitude and longitude coordinates.
Spokane, WA is located at approximately 47.6587° N, 117.4260° W.
[Calling tool get_forecast with args {'latitude': 47.6587, 'longitude': -117.426}]
Based on the current forecast for Spokane:
Right now it's sunny and cold with a temperature of 37°F and ...
Why use SSE-based MCP servers and clients?
The MCP server can run as a separate process that agents (clients) connect to, use, and disconnect from whenever and wherever they want. SSE-based servers and clients can be decoupled processes, potentially running on separate nodes. This approach better fits "cloud-native" use-cases compared to the STDIO-based pattern where the client spawns the server as a subprocess.
Installing via Smithery
To install the SSE-based Server and Client for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @sidharthrajaram/mcp-sse --client claude
Server
weather.py
is an SSE-based MCP server presenting tools based on the National Weather Service APIs. Adapted from the MCP docs' example STDIO server implementation.
By default, the server runs on 0.0.0.0:8080
, but it is configurable with command line arguments:
uv run weather.py --host <your host> --port <your port>
Client
client.py
is an MCP client that connects to and uses tools from the SSE-based MCP server. Adapted from the MCP docs' example STDIO client implementation.
By default, the client connects to an SSE endpoint provided as a command line argument:
uv run client.py http://0.0.0.0:8080/sse