fastapi_mcp
Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!
claude mcp add --transport stdio tadata-org-fastapi_mcp python -m fastapi_mcp \ --env UV_APP_CONFIG="path or URL to FastAPI app config (optional)" \ --env FASTAPI_MCP_AUTH="authentication dependency configured in your FastAPI app (optional)"
How to use
FastAPI-MCP exposes your FastAPI endpoints as MCP tools, allowing external agents to discover and invoke them through the MCP protocol while leveraging your app's authentication and authorization logic. The server is designed as a native extension to FastAPI, using the app's ASGI interface to communicate directly with your application, so there are no extra HTTP hops between MCP and your FastAPI app. You can mount the MCP server directly to your FastAPI application or run it as a separate service, depending on your deployment needs. To get started, install the package, integrate it with your FastAPI app, and mount the MCP server to expose your endpoints as MCP tools. The resulting MCP interface preserves your endpoint schemas and documentation, making it easy for clients to discover available tools and their input/output contracts.
How to install
Prerequisites:
- Python 3.10+ (recommended 3.12)
- pip (or a Python environment/manager of your choice)
- A FastAPI application you want to expose via MCP
Installation steps:
- Install the MCP package using pip (preferred for Python environments):
pip install fastapi-mcp
- (Optional) If you prefer using uv for environment management or a dedicated runtime, ensure uv is installed in your environment:
pip install uv
-
Verify installation by importing in Python or running a simple script that imports FastAPI-MCP and mounts it to an app (see example under Basic Usage in the project docs).
-
Run your FastAPI app with MCP integration enabled (see Basic Usage for code snippets).
Additional notes
Tips and notes:
- Authentication is integrated with your FastAPI dependencies; use Depends() for access control on MCP tools just as you do for normal endpoints.
- The MCP server leverages the FastAPI ASGI interface, so there is no need for extra HTTP calls from the MCP to your app.
- You can mount the MCP server to the same FastAPI app or run it as a separate service depending on your deployment strategy.
- If you plan to deploy separately, ensure proper network configuration and security between the MCP server and the FastAPI app.
- Check your environment for Python version compatibility and ensure required dependencies are installed.
- Refer to the project documentation for advanced usage, including authentication schemes, tool discovery, and example integrations.
Related MCP Servers
ollama
An MCP Server for Ollama
mcp-tasks
A comprehensive and efficient MCP server for task management with multi-format support (Markdown, JSON, YAML)
gtm
An MCP server for Google Tag Manager. Connect it to your LLM, authenticate once, and start managing GTM through natural language.
metabase-ai-assistant
🚀 The most powerful MCP Server for Metabase - 111+ tools for AI SQL generation, dashboard automation & enterprise BI. Works with Claude, Cursor, ChatGPT.
mcp -templates
A flexible platform that provides Docker & Kubernetes backends, a lightweight CLI (mcpt), and client utilities for seamless MCP integration. Spin up servers from templates, route requests through a single endpoint with load balancing, and support both deployed (HTTP) and local (stdio) transports — all with sensible defaults and YAML-based configs.
mcp-client-gen
Turn any MCP server into a type-safe TypeScript SDK in seconds - with OAuth 2.1 and multi-provider support