Integrations
Provides a Python implementation of both MCP client and server components, allowing Python applications to expose and access MCP capabilities.
Employs WebSocket connections for real-time bidirectional communication between MCP clients and servers, supporting the complete MCP handshake and capability negotiation process.
Model Context Protocol (MCP) Python Implementation
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.
What is MCP?
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:
- Tools: Executable functions that perform actions
- Resources: Data sources that provide information
- Prompts: Predefined templates or workflows
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.
Project Structure
server/
: MCP server implementationserver.py
: WebSocket server that handles MCP requests and provides sample tools/resources
client/
: MCP client implementationclient.py
: Demo client that connects to the server and exercises all MCP capabilities
Features Demonstrated
This implementation showcases the core MCP protocol flow:
- Capability Negotiation: Client-server handshake via
initialize
- Capability Discovery: Listing available tools and resources
- Tool Invocation: Calling the
add_numbers
tool with parameters - Resource Access: Reading text content from a resource
Setup
- Create a virtual environment:Copy
- Install dependencies:Copy
Usage
- Start the MCP server (in one terminal):Copy
- Run the MCP client (in another terminal):Copy
The client will connect to the server, perform the MCP handshake, discover capabilities, and demonstrate invoking tools and accessing resources with formatted output.
How It Works
MCP Server
The server:
- Accepts WebSocket connections
- Responds to JSON-RPC requests following the MCP specification
- Provides a sample tool (
add_numbers
) - Provides a sample resource (
example.txt
) - Supports the MCP handshake and capability discovery
MCP Client
The client:
- Connects to the server via WebSocket
- Performs the MCP handshake
- Discovers available tools and resources
- Demonstrates calling a tool and reading a resource
- Presents the results in a formatted display
Protocol Details
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 |
Extending the Project
You can extend this implementation by:
- Adding more tools with different capabilities
- Adding dynamic resources that change on each read
- Implementing prompt templates for guided interactions
- Creating more interactive client applications
References
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
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.
Related MCP Servers
- -securityAlicense-qualityA simple MCP server implementation that provides AI models with basic Solana RPC methods and helpful development prompts.Last updated -21TypeScriptMIT License
- -securityFlicense-qualityImplements the Model Context Protocol (MCP) to provide AI models with a standardized interface for connecting to external data sources and tools like file systems, databases, or APIs.Last updated -90Python
- -securityAlicense-qualityA streamlined foundation for building Model Context Protocol servers in Python, designed to make AI-assisted development of MCP tools easier and more efficient.Last updated -13PythonMIT License
- -securityFlicense-qualityA simple demonstration project for the Model Control Protocol (MCP) server that provides tools for AI assistants to fetch news articles, perform calculations, retrieve weather data, and generate personalized greetings.Last updated -Python