Get the FREE Ultimate OpenClaw Setup Guide →

fastapi_mcp

Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Install the MCP package using pip (preferred for Python environments):
pip install fastapi-mcp
  1. (Optional) If you prefer using uv for environment management or a dedicated runtime, ensure uv is installed in your environment:
pip install uv
  1. 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).

  2. 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

Sponsor this space

Reach thousands of developers