A Python implementation of the MCP server that enables AI models to connect with external tools and data sources through a standardized protocol, supporting tool invocation and resource access via JSON-RPC.
This project implements a functioning Model Context Protocol (MCP) server and client in Python, following the Anthropic MCP specification. It demonstrates the key patterns of the MCP protocol through a simple, interactive example.
The Model Context Protocol (MCP) is an open standard built on JSON-RPC 2.0 for connecting AI models to external data sources and tools. It defines a client-server architecture where an AI application communicates with one or more MCP servers, each exposing capabilities such as:
MCP standardizes how these capabilities are discovered and invoked, serving as a "USB-C for AI" that allows models to interact with external systems in a structured way.
server/
: MCP server implementation
server.py
: WebSocket server that handles MCP requests and provides sample tools/resourcesclient/
: MCP client implementation
client.py
: Demo client that connects to the server and exercises all MCP capabilitiesThis implementation showcases the core MCP protocol flow:
initialize
add_numbers
tool with parametersCreate a virtual environment:
python3 -m venv .venv source .venv/bin/activate
Install dependencies:
pip install -r requirements.txt
Start the MCP server (in one terminal):
python server/server.py
Run the MCP client (in another terminal):
python client/client.py
The client will connect to the server, perform the MCP handshake, discover capabilities, and demonstrate invoking tools and accessing resources with formatted output.
The server:
add_numbers
)example.txt
)The client:
MCP implements these key methods:
Method | Description |
---|---|
initialize | Handshake to establish capabilities |
tools/list | List available tools |
tools/call | Call a tool with arguments |
resources/list | List available resources |
resources/read | Read resource content |
prompts/list | List available prompts |
You can extend this implementation by:
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!