Implements a Python-based Model Context Protocol server providing WebSocket JSON-RPC access to tools, resources, and prompts for AI model integration, supporting capability negotiation, discovery, and invocation.
Unlock the full potential of Model Context Protocol MCP Server through LangDB's AI Gateway. Get enterprise-grade security, analytics, and seamless integration with zero configuration.
Free tier available • No credit card required
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!