This template provides a streamlined foundation for building Model Context Protocol (MCP) servers in Python. It's designed to make AI-assisted development of MCP tools easier and more efficient.
This project uses Cursor Rules for improved AI coding assistance, with patterns from Awesome Cursor Rules.
This template includes comprehensive MCP documentation directly in the project:
protocals/mcp.md
): The full Model Context Protocol specification that defines how AI models can interact with external tools and resources.protocals/sdk.md
): Detailed documentation for the MCP Python SDK.protocals/example_weather.py
): A practical weather service implementation demonstrating real-world MCP server patterns and best practices.mcp>=1.4.1
httpx>=0.28.1
starlette>=0.46.1
uvicorn>=0.34.0
shell
git clone https://github.com/yourusername/mcp-server-python-template.git
cd mcp-server-python-template
shell
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e .
The template includes a weather service example that demonstrates how to build MCP tools:
# Run with stdio transport (for CLI tools)
python server.py --transport stdio
# Run with SSE transport (for web applications)
python server.py --transport sse --host 0.0.0.0 --port 8080
To create your own MCP tools:
mcp
:python
from mcp.server.fastmcp import FastMCP
python
mcp = FastMCP("your-namespace")
Define your tools using the @mcp.tool()
decorator:
```python
@mcp.tool()
async def your_tool_function(param1: str, param2: int) -> str:
"""
Your tool description.
Args:
param1: Description of param1
param2: Description of param2
Returns:
The result of your tool
"""
# Your implementation here
return result
4. Run your server using the appropriate transport:
python
mcp.run(transport='stdio') # or set up SSE as shown in server.py
```
server.py
: Main MCP server implementation with example weather toolsmain.py
: Simple entry point for custom codeprotocals/
: Documentation and example protocolsmcp.md
: Complete MCP specification (~7000 lines)sdk.md
: MCP Python SDK documentationexample_weather.py
: Example weather service implementationpyproject.toml
: Project dependencies and metadataThe Model Context Protocol (MCP) is a standardized way for AI models to interact with external tools and resources. Key concepts include:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.