fastapi-mcp-server
by vkmech999
README.md
# fastapi-mcp-server ⚡
> Turn any FastAPI app into a Claude-compatible MCP server instantly by reading its OpenAPI spec
## What it does
Point this tool at any running FastAPI app and it will:
1. Fetch the OpenAPI spec automatically from `/openapi.json`
2. Parse every endpoint — paths, methods, parameters, request bodies
3. Dynamically register one MCP tool per endpoint
4. Claude can now call any endpoint using natural language
**Zero manual tool writing. Zero code changes to your existing FastAPI app.**
## Demo
```
User: "Create a task titled Push code to GitHub with high priority"
Claude: [calls post_tasks tool]
→ Task created successfully ✅
User: "Mark task 2 as completed"
Claude: [calls put_tasks_task_id tool]
→ Task updated ✅
User: "Show me all tasks"
Claude: [calls get_tasks tool]
→ Returns all tasks ✅
```
## Architecture
```
Your FastAPI App (running)
↓
fastapi-mcp-server fetches /openapi.json
↓
OpenAPIParser extracts all endpoints
↓
One MCP tool registered per endpoint
↓
Claude calls tools using natural language
↓
MCP server makes real HTTP requests to your API
↓
Results returned to Claude
```
## Tech Stack
- Python 3.12
- FastAPI + Pydantic
- MCP (Model Context Protocol)
- httpx
- OpenAPI 3.x
## Setup
### 1. Clone and install
```bash
git clone https://github.com/vkmech999/fastapi-mcp-server.git
cd fastapi-mcp-server
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
### 2. Configure environment
```bash
cp .env.example .env
# Set TARGET_API_URL to your FastAPI app
# Set AUTH_TYPE if your API requires authentication
```
### 3. Connect to Claude Desktop
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
```json
{
"mcpServers": {
"fastapi-mcp-server": {
"command": "/path/to/venv/bin/python3",
"args": ["-m", "mcp_server.server"],
"env": {
"TARGET_API_URL": "http://localhost:8000",
"AUTH_TYPE": "none",
"PYTHONPATH": "/path/to/fastapi-mcp-server"
}
}
}
}
```
### 4. Use it in Claude Desktop
```
"List all available endpoints"
"Get all tasks"
"Create a new user named John with email john@example.com"
"Delete task with ID 3"
```
## Authentication Support
| Auth Type | Use Case | Config |
|-----------|----------|--------|
| `none` | Public APIs | `AUTH_TYPE=none` |
| `bearer` | JWT / OAuth2 | `AUTH_TYPE=bearer` + `AUTH_TOKEN=eyJ...` |
| `api_key` | Third-party APIs | `AUTH_TYPE=api_key` + `AUTH_TOKEN=sk-...` + `AUTH_HEADER=X-API-Key` |
| `basic` | Legacy systems | `AUTH_TYPE=basic` + `AUTH_USERNAME` + `AUTH_PASSWORD` |
## MCP Tools
| Tool | Description |
|------|-------------|
| `list_api_endpoints` | Discover all registered endpoint tools |
| `get_*` | Auto-generated GET endpoint tools |
| `post_*` | Auto-generated POST endpoint tools |
| `put_*` | Auto-generated PUT endpoint tools |
| `delete_*` | Auto-generated DELETE endpoint tools |
## Running Tests
```bash
pytest tests/test_server.py -v
```
## Author
**Vivek Kumar** — Senior Python Full Stack Developer
[LinkedIn](https://linkedin.com/in/vivek-kumar-80943a104) · [GitHub](https://github.com/vkmech999)This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo issues