Build a simple Python MCP server with add and greet functions for easy testing and development
The MCP demo server is a simple and lightweight example project illustrating how to implement model context protocol (MCP) in a Python application. This server offers an intuitive and accessible gateway for developers who are exploring or implementing MVPs of more sophisticated MCP servers, allowing them to connect with AI applications through a standardized protocol. The simplicity and clarity with which it adheres to the MCP standards make it ideal for both educational purposes and experimental integrations.
This project introduces two foundational tools that adhere meticulously to the Model Context Protocol (MCP):
add(a: int, b: int) -> int
: A succinct addition function that takes two integers as input parameters and then returns their sum. This tool serves both educational and validation purposes by demonstrating the basic data handling capabilities expected from an MCP-compliant server.say_hello(name: str) -> str
: A greeting mechanism capable of generating personalized greetings based on a user-provided name. This illustrates how AI applications can dynamically create user-specific content or responses, reinforcing the practical utility and versatility provided by adhering to MCP.These tools not only form the backbone of the server but also set the stage for broader functionality integration into more complex AI workflows.
The design of this MCP demo server is rooted in simplicity. It leverages Python 3.x as its primary language and makes essential use of libraries such as uvicorn (or uv, abbreviated as uv
, hence the choice for concise command syntax) to handle the HTTP infrastructure required by the model context protocol.
The primary architecture involves setting up a virtual environment where dependencies like MCP can be installed. This setup ensures that all necessary tools are available without any versioning conflicts or external dependencies.
To embark on your journey with this MCP demo server, begin by cloning and navigating into the project directory:
git clone [repository-url]
cd mcp-demo
Next, establish a virtual environment and install the required packages:
python -m venv .venv
source .venv/bin/activate # On Windows use: .venv\Scripts\activate
pip install mcp[cli]
Upon completion of these setup steps, the groundwork for running your own MCP server is put in place.
The utility and applicability of this server extend beyond mere educational value. In real-world scenarios, it can serve as a robust foundation for:
Integration between this server and specific MCP clients is meticulously detailed. For instance:
{
"mcpServers": {
"[server-name]": {
"command": "uv",
"args": [
"run",
"--with",
"mcp[cli]",
"mcp",
"run",
"${workspaceFolder}/server.py"
]
}
}
}
This configuration snippet demonstrates the setup required for Claude Desktop to communicate with this server. The protocol's simplicity ensures seamless and efficient interaction between the client and the server.
{
"mcpServers": {
"[server-name]": {
"command": "uv",
"args": [
"run",
"--with",
"mcp[cli]",
"mcp",
"run",
"${workspaceFolder}/server.py"
]
}
}
}
Similarly, Continue can integrate with the server in a compatible manner. This integration not only showcases MCP’s wide applicability but also highlights its role as an adapter layer for diverse AI applications.
The compatibility matrix is crucial for understanding which clients and tools can seamlessly work with this MCP demo server:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ | Full Support |
Continue | ✅ | ✅ | ✅ | Full Support |
Cursor | ❌ | ✅ | ❌ | Tools Only |
Advanced configuration options and security measures are also discussed in depth:
Which AI applications are compatible with this MCP server?
How can I ensure secure communication between the client and server?
Can I use this server with other types of tools or libraries beyond these mentioned ones?
What steps are required for advanced configuration?
How does this server affect performance in terms of latency and throughput?
For developers interested in contributing or customizing the project:
The broader MCP ecosystem benefits greatly from projects like this as they provide practical examples and references. Additional resources such as the official MCP documentation, community forums, and repositories can be invaluable for further development or deeper understanding.
1. MCP Protocol Flow
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
2. Data Architecture
graph TD
A[MCP Client] --> B[Encrypted Request]
B --> C[MCP Server]
C --> D[Decryption & Authentication]
D --> E[Database Query]
E --> F[Data Processing]
F --> G[Response Packaging]
G --> H[Routable Data]
style A fill:#e1f5fe
style B fill:#d0ebff
style C fill:#f3e5f5
style D fill:#e8f5e8
style E fill:#fff2cc
style F fill:#fff9b3
style G fill:#fef1c6
Case 1: Data Acquisition for AI-Driven Market Analysis
add
and say_hello
functions, analysts can build complex queries that fetch relevant historical and current market data.Case 2: Interactive User Interface for AI-Driven Customer Service
say_hello
function dynamically personalizes greetings, while calls to add
could manage inventory levels or calculate discounts.This comprehensive MCP server serves as a foundational piece for developers aiming to integrate AI applications with data sources and tools. By following this documentation, one can build more complex and robust systems that leverage the power of Model Context Protocol.
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication
Python MCP client for testing servers avoid message limits and customize with API key
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Discover easy deployment and management of MCP servers with Glutamate platform for Windows Linux Mac
Explore community contributions to MCP including clients, servers, and projects for seamless integration
Learn how to use MCProto Ruby gem to create and chain MCP servers for custom solutions