Introduction
FastAPI-MCP is a Python library that automatically converts your existing FastAPI endpoints into MCP-compatible tools. Instead of writing MCP server code from scratch, you add a single line to your existing FastAPI app and every endpoint becomes an AI-callable tool.
Key features:
- Zero Config —
FastApiMCP(app).mount()is all you need. Every route becomes an MCP tool automatically. - Authentication Built-in — Leverages your existing FastAPI security dependencies (OAuth2, API keys, etc.) for MCP tool access.
- Schema Preservation — Request/response models, validation rules, and documentation carry over to MCP tool definitions.
- Selective Exposure — Include or exclude specific endpoints with
include_operationsandexclude_operations. - ASGI Transport — Direct in-process communication eliminates HTTP overhead when the MCP client and FastAPI run together.
- Custom Tool Naming — Override auto-generated tool names for cleaner AI assistant integration.
Perfect for teams that already have FastAPI backends and want to make them AI-accessible without rewriting anything.
FAQ
Q: Does it work with existing authentication? A: Yes. FastAPI-MCP reuses your existing FastAPI Depends() security — OAuth2 bearer tokens, API keys, and custom auth all work transparently.
Q: Can I choose which endpoints to expose?
A: Yes. Use include_operations=["get_item", "list_items"] or exclude_operations=["delete_all"] to control access.
Q: How do I connect Claude to my FastAPI-MCP server? A: Add this to your MCP config:
{
"mcpServers": {
"my-api": {
"url": "http://localhost:8000/mcp"
}
}
}Q: Does it handle complex request bodies? A: Yes. Pydantic models, query parameters, path parameters, and JSON bodies are all converted to MCP tool input schemas automatically.
Works With
- FastAPI 0.100+
- Python 3.10+
- Claude Code / Claude Desktop / Any MCP client
- Any existing FastAPI authentication setup