regdamon25/python-mcp-server-template
If you are the rightful owner of python-mcp-server-template and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This is a Model Context Protocol (MCP) server template designed to provide AI agents with access to API endpoints, built using Python and deployable via uv package manager or Docker.
get_users
Retrieve users from the API
create_user
Create a new user
get_user_by_id
Get user by ID
{{PROJECT_NAME}}
{{PROJECT_DESCRIPTION}}
This is an MCP (Model Context Protocol) server template that provides AI agents access to your API endpoints. It's built with Python and can be run using uv package manager or Docker.
Setup
Prerequisites
- Python 3.13 or higher (latest stable)
- uv package manager (or Docker)
Method 1: Local Development with uv
-
Install uv (if not already installed):
curl -LsSf https://astral.sh/uv/install.sh | sh
-
Install dependencies:
uv sync
-
Configure environment variables:
cp .env.example .env # Edit .env with your API configuration
-
Run the server:
uv run python -m src.server
Method 2: Docker
-
Configure environment variables:
cp .env.example .env # Edit .env with your API configuration
-
Build and run with Docker Compose:
docker-compose up --build
Or build and run manually:
docker build -t my-mcp-server . docker run --rm -it --env-file .env my-mcp-server
Available Tools
get_users
: Retrieve users from the APIcreate_user
: Create a new userget_user_by_id
: Get user by ID
Configuration
Set these environment variables in your .env
file:
API_BASE_URL
: Base URL of your existing API (default: http://localhost:8000)API_KEY
: API authentication key (optional)
Docker-specific Notes
- The default
API_BASE_URL
in Docker is set tohttp://host.docker.internal:8000
to access services on the host machine - Adjust the
docker-compose.yml
file if you need to expose ports or use different networking
Connecting to AI Clients
To connect this MCP server to an AI client like Claude Desktop, add this configuration:
Local Development
{
"mcpServers": {
"{{PROJECT_NAME}}": {
"command": "uv",
"args": ["run", "python", "-m", "src.server"],
"cwd": "/path/to/{{PROJECT_NAME}}"
}
}
}
Docker
{
"mcpServers": {
"{{PROJECT_NAME}}": {
"command": "docker",
"args": ["run", "--rm", "-i", "--env-file", "/path/to/{{PROJECT_NAME}}/.env", "{{PROJECT_NAME}}"],
"cwd": "/path/to/{{PROJECT_NAME}}"
}
}
}
Development
Testing
# Run tests with uv
uv run pytest
# Or create a simple test
uv run python test_server.py
Customization
To adapt this for your specific API:
-
Update
src/tools.py
:- Replace the example tools with your actual API endpoints
- Modify the
APIClient.make_request()
method if you need custom authentication - Update the
handle_tool_call()
function with your endpoint logic
-
Update
src/config.py
:- Add any additional configuration your API needs
- Modify authentication settings
-
Add more sophisticated error handling:
- Handle specific HTTP status codes
- Add retry logic for transient failures
- Implement proper logging
Project Structure
{{PROJECT_NAME}}/
āāā src/
ā āāā __init__.py
ā āāā server.py # Main MCP server implementation
ā āāā tools.py # Tool definitions and API client
ā āāā config.py # Configuration management
āāā pyproject.toml # Project configuration and dependencies
āāā docker-compose.yml # Docker Compose configuration
āāā Dockerfile # Docker image definition
āāā .env.example # Example environment variables
āāā .gitignore # Git ignore patterns
āāā .dockerignore # Docker ignore patterns
āāā README.md # This file