FastAPI MCP

Stale
GitHub Python MIT

Description

Library to expose FastAPI endpoints as Model Context Protocol tools with authentication support, enabling AI agents to call existing APIs directly

Key Features

  • Native FastAPI extension — not just an OpenAPI-to-MCP converter
  • Authentication built in using existing FastAPI Depends() dependencies
  • Zero/minimal configuration — point at your FastAPI app and it works
  • Preserves request/response schemas and endpoint documentation from Swagger
  • ASGI transport for efficient direct communication without HTTP overhead
  • Flexible deployment — mount to same app or deploy as separate MCP server

Use Cases

💡 Exposing existing FastAPI microservices as MCP tools for AI agents
💡 Adding AI-callable interfaces to authenticated internal APIs
💡 Building MCP-compatible APIs without rewriting from scratch
💡 Enabling Claude or other AI assistants to invoke your REST endpoints
💡 Rapid prototyping of AI-connected backends with existing OpenAPI specs

Quick Start

uv add fastapi-mcp (or pip install fastapi-mcp). In your FastAPI app: from fastapi import FastAPI; from fastapi_mcp import FastApiMCP; app = FastAPI(); mcp = FastApiMCP(app); mcp.mount(). Your MCP server is available at /mcp

Related Projects