🧠 Model Context Protocol (MCP) Example – Python Implementation

SSE

by srivatssan

1 124 downloads Not rated yet MIT

About

This project is a simple vibe coded example of how an MCP Server could return a tool to the requesting client.

Details

Transport
SSE
License
MIT

Explore

- Minimal MCP server exposing tools via tools/list and tools/call
- Python client sending JSON-RPC requests to list and call tools
- Simulated real-time connection using /events SSE endpoint
- Modular structure ready to extend for resources/ and prompts/ support

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name 🧠 Model Context Protocol (MCP) Example – Python Implementation
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Install FastAPI and Uvicorn, then start the server with uvicorn main:app --reload inside the server/ directory. Install the requests package and run python main.py from the client/ directory to interact with the server. The server exposes endpoints POST /rpc for JSON-RPC tool listing/invocation and GET /events for simulated SSE heartbeat messages.

alerts_query

Returns all alerts

alerts_active

Returns all currently active alerts

alerts_active_count

Returns info on the number of active alerts

alerts_active_zone

Returns active alerts for the given NWS public zone or county

alerts_active_area

Returns active alerts for the given area (state or marine area)

alerts_active_region

Returns active alerts for the given marine region

alerts_types

Returns a list of alert types

alerts_single

Returns a specific alert

cwsu

Returns metadata about a Center Weather Service Unit

cwas

Returns a list of Center Weather Advisories from a CWSU

cwa

Returns a list of Center Weather Advisories from a CWSU

sigmetQuery

Returns a list of SIGMET/AIRMETs

sigmetsByATSU

Returns a list of SIGMET/AIRMETs for the specified ATSU

sigmetsByATSUByDate

Returns a list of SIGMET/AIRMETs for the specified ATSU for the specified date

sigmet

Returns a specific SIGMET/AIRMET

glossary

Returns glossary terms

gridpoint

Returns raw numerical forecast data for a 2.5km grid area

gridpoint_forecast

Returns a textual forecast for a 2.5km grid area

gridpoint_forecast_hourly

Returns a textual hourly forecast for a 2.5km grid area

gridpoint_stations

Returns a list of observation stations usable for a given 2.5km grid area

icons

Returns a forecast icon. Icon services in API are deprecated.

iconsDualCondition

Returns a forecast icon. Icon services in API are deprecated.

icons_summary

Returns a list of icon codes and textual descriptions. Icon services in API are deprecated.

satellite_thumbnails

Returns a thumbnail image for a satellite region. Image services in API are deprecated.

station_observation_list

Returns a list of observations for a given station

station_observation_latest

Returns the latest observation for a station

station_observation_time

Returns a single observation.

tafs

Returns Terminal Aerodrome Forecasts for the specified airport station.

taf

Returns a single Terminal Aerodrome Forecast.

obs_stations

Returns a list of observation stations.

obs_station

Returns metadata about a given observation station

office

Returns metadata about a NWS forecast office

office_headline

Returns a specific news headline for a given NWS office

office_headlines

Returns a list of news headlines for a given NWS office

point

Returns metadata about a given latitude/longitude point

point_stations

Returns a list of observation stations for a given point

radar_servers

Returns a list of radar servers

radar_server

Returns metadata about a given radar server

radar_stations

Returns a list of radar stations

radar_station

Returns metadata about a given radar station

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "\ud83e\udde0 model context protocol (mcp) example \u2013 python implementation": {
            "MCP-Demo": {
                "command": "python",
                "args": [
                    "main.py"
                ]
            }
        }
    }
}

McpServers

{
    "MCP-Demo": {
        "command": "python",
        "args": [
            "main.py"
        ]
    }
}

This repository provides a minimal yet functional example of the Model Context Protocol (MCP) using Python. It demonstrates how a Large Language Model (LLM) agent can communicate with enterprise systems through a standardized client-server interface using JSON-RPC over HTTP, including support for Server-Sent Events (SSE).

You can read my blog to understand the subject better: https://srivatssan.medium.com/model-context-protocol-exhaustively-explained-f5a30a87a3ff?sk=1b971265640303c66b04377371c82102

---

πŸ“¦ Repository Structure

mcp-protocol-example/
β”œβ”€β”€ client/
β”‚   └── main.py       # Python MCP client using JSON-RPC
β”œβ”€β”€ server/
β”‚   └── main.py       # FastAPI-based MCP server with /rpc and /events endpoints

---

πŸš€ How to Run This Example

1️⃣ Start the Server

Make sure you have FastAPI and Uvicorn installed:

pip install fastapi uvicorn

Then, start the MCP server:

cd server
uvicorn main:app --reload

This starts a FastAPI server with:
- POST /rpc: JSON-RPC handler for tool listing and invocation
- GET /events: Simulated SSE endpoint emitting heartbeat messages every 5 seconds

---

2️⃣ Run the Client

Install the required Python requests package:

pip install requests

Then run the client to interact with the server:

cd client
python main.py

Output:

Tools: [{'name': 'greet', 'description': 'Greets the user', ...}]
Response: {'message': 'Hello, Sri!'}

You can run http://localhost:8000/events
and you should see the heartbeat event being returned
like the one shown below.

_data: {'event': 'heartbeat'}

data: {'event': 'heartbeat'}
_
...

**
---

βš™οΈ What It Demonstrates

- A basic MCP server exposing tools via tools/list and tools/call
- A client sending JSON-RPC requests to list and call tools
- Simulated real-time connection using /events SSE endpoint
- Modular structure ready to extend for resources/ and prompts/ support

---

🧩 Next Steps

You can expand this prototype by:
- Adding more tools with different schemas
- Supporting resources/list and resources/read
- Managing prompt templates with prompts/get
- Implementing authentication and access control
- Handling streaming responses from server to client

---

πŸ“š References

- Model Context Protocol (official site)
- JSON-RPC 2.0 Specification
- FastAPI Documentation
- Server-Sent Events (MDN)

---

Created with ❀️ by Srivatssan Srinivasan

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.