Transform any FastAPI server into an MCP server
Project description
gmcp - Transform FastAPI to MCP
gmcp automatically converts any FastAPI server into an MCP (Model Context Protocol) server, exposing all API endpoints as tools that Claude can use.
Features
- 🚀 Zero Configuration: Just provide a FastAPI server URL
- 🔄 Auto-Discovery: Automatically discovers all endpoints via OpenAPI schema
- 🛠️ Full Support: Handles GET, POST, PUT, PATCH, DELETE methods
- 📝 Schema Aware: Preserves parameter types, descriptions, and validation
- 🔐 Authentication: Supports Bearer tokens, API keys, Basic auth, and custom headers
- 🔒 Secure: Environment variable support for sensitive credentials
- ⚡ Fast: Efficient async HTTP client built on httpx
Installation
# Install in development mode
pip install -e .
Usage
Basic Usage
Testing (list available tools):
# Test that gmcp can discover tools
gmcp --list-tools http://localhost:5000
Running as MCP server:
gmcp automatically detects when it's run from an interactive terminal and will show helpful instructions instead of starting the server. To use it as an MCP server, configure it in Claude Code (see below).
If you need to force MCP server mode (e.g., for testing with another MCP client):
gmcp --force http://localhost:5000
Configure in Claude Code
Add to ~/.claude/mcp_settings.json:
Basic (no auth):
{
"mcpServers": {
"my-fastapi-server": {
"command": "gmcp",
"args": ["http://localhost:5000"]
}
}
}
With Authentication:
{
"mcpServers": {
"my-api": {
"command": "gmcp",
"args": [
"http://api.example.com",
"--auth-type", "bearer",
"--auth-token", "$API_TOKEN"
],
"env": {
"API_TOKEN": "your-token-here"
}
}
}
}
See AUTH.md for complete authentication documentation.
Example
If your FastAPI server has these endpoints:
@app.get("/users/{user_id}")
async def get_user(user_id: int):
return {"id": user_id, "name": "John"}
@app.post("/users")
async def create_user(name: str, email: str):
return {"id": 123, "name": name, "email": email}
gmcp will automatically create MCP tools:
get_users_user_id- Get a user by IDcreate_users- Create a new user
Claude can then call these tools directly!
How It Works
- Fetch Schema: gmcp fetches the OpenAPI schema from
/openapi.json - Parse Endpoints: Converts each endpoint into an MCP tool definition
- Proxy Requests: When tools are called, gmcp makes HTTP requests to FastAPI
- Return Results: Responses are formatted and returned to Claude
Requirements
- Python 3.10+
- A running FastAPI server with OpenAPI enabled (default)
Development
Project Structure
gmcp/
├── src/
│ └── gmcp/
│ ├── __init__.py
│ └── server.py # Main MCP server implementation
├── examples/
│ ├── sample_api.py # Example FastAPI server
│ └── test_gmcp.sh # Test script
├── pyproject.toml
└── README.md
Testing
See examples/ directory for a sample FastAPI server and test script.
Documentation
- QUICKSTART.md - Get started in 5 minutes
- AUTH.md - Authentication guide (Bearer, API keys, Basic auth)
- USAGE.md - Detailed usage guide and troubleshooting
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gmcp-0.2.0.tar.gz.
File metadata
- Download URL: gmcp-0.2.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
757d6af52ca125d1b80966fbbc1f6da86cf1cf970cfbccfaa4b1228e0976592c
|
|
| MD5 |
20cb9fd7c0a1995d9d6422a7dd6c1584
|
|
| BLAKE2b-256 |
8ea67231cc90c48b19b0ca886b69f6d51c6761e93c1a0cc80d2374022634d2b5
|
File details
Details for the file gmcp-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gmcp-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bc653d04ecd974deea469e3bb948e6ab0f50662df6c0608f1eb42236dda9d62
|
|
| MD5 |
3777e8400fdd9c41de5ba2e950bada88
|
|
| BLAKE2b-256 |
cf69f4be22de0fb4202d81d0ff2dff651dc3caf54bdd1d41df31151721d9976b
|