A template for creating Model Context Protocol (MCP) servers using Python and FastMCP.
This template provides a foundation for building MCP servers with support for two transport protocols:
- STDIO (default) - Standard input/output communication
- SSE - Server-Sent Events over HTTP
- Easy configuration switching between STDIO and SSE protocols
- Automatic
mcp.json
configuration generation - Example tool implementation (
mcp_get_precise_time
) - Clean project structure with modular components
├── mcp_server.py # Main MCP server application
├── mcp_settings.py # Configuration settings
├── mcp_transport_configurator.py # Auto-configures mcp.json
├── mcp_util.py # Utility functions (add your tools here)
├── requirements.txt # Python dependencies
└── README.md # This file
-
Install dependencies:
pip install -r requirements.txt
-
Configure transport protocol: Edit
mcp_settings.py
to choose your transport protocol:SETTINGS = { PROTOCOL : STDIO, # or SSE PORT : "5500" # only used for SSE }
- Uses standard input/output for communication
- Suitable for direct integration with clients that support process spawning
- Configuration is automatically generated for VS Code MCP extension
- HTTP-based communication using Server-Sent Events
- Runs on configurable port (default: 5500)
- Suitable for web-based integrations or when firewall restrictions apply
python mcp_server.py
This will:
- Automatically configure the appropriate
mcp.json
file - Start the server with the selected transport protocol
To just update the mcp.json
configuration without starting the server:
python mcp_transport_configurator.py
The server automatically generates .vscode/mcp.json
based on your protocol choice:
{
"servers": {
"my-mcp-server": {
"command": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"args": ["mcp_server.py"],
"env": {
"PYTHONPATH": "${workspaceFolder}"
}
}
}
}
{
"servers": {
"my-sse-mcp-server": {
"type": "sse",
"url": "http://127.0.0.1:5500/sse"
}
}
}
- Implement your functions in
mcp_util.py
- Add MCP tool wrappers in
mcp_server.py
using the@app.tool()
decorator
Example:
# In mcp_util.py
def my_custom_function(param1, param2):
"""Your custom logic here"""
return f"Result: {param1} + {param2}"
# In mcp_server.py
@app.tool()
def my_custom_tool(param1: str, param2: str):
"""
Description of what this tool does
"""
return my_custom_function(param1, param2)
-
Port already in use (SSE mode):
- Change the port in
mcp_settings.py
- Check if another service is using the port
- Change the port in
-
Python path issues (STDIO mode):
- Ensure you're using a virtual environment
- Verify the Python path in the generated
mcp.json
-
Module import errors:
- Check that all dependencies are installed
- Verify PYTHONPATH is set correctly
- STDIO mode: Check VS Code MCP extension logs
- SSE mode: Server logs are printed to console
Tell me the precise time (using MCP Tools).
This template is provided as-is for educational and development purposes.
GUU8HC