Skip to content

Guide · Open source

How to use fastapi_mcp: expose FastAPI endpoints as MCP tools

Updated · written with AI from the project's own documentation and checked against our catalogue data

fastapi_mcp is an open-source MIT-licensed Python library that adds a Model Context Protocol (MCP) server to an existing FastAPI application, so AI tools such as Claude or Cursor can call your API endpoints as tools. This guide is for Python developers who already have a FastAPI app. After reading it you will know how to install the library, mount an MCP server, and secure it with your existing FastAPI dependencies.

FastAPI-MCPtadata-org/fastapi_mcp · ★ 12k · MIT

Quick start

  1. 1Check your Python version. Confirm you have Python 3.10 or newer. The README recommends 3.12.
  2. 2Install the package. Run uv add fastapi-mcp, or pip install fastapi-mcp if you use pip.
  3. 3Create the MCP object. Import FastApiMCP and pass your existing FastAPI app to it.
  4. 4Mount the server. Call mcp.mount() to add the MCP server to your app.
  5. 5Find the MCP endpoint. The README says the server is available at /mcp on your app's base URL.
  6. 6Add authentication. Use your existing FastAPI Depends() dependencies to secure MCP access.

What fastapi_mcp does

fastapi_mcp exposes your FastAPI endpoints as Model Context Protocol (MCP) tools. It reuses your routes, request and response schemas, and endpoint documentation, so the tools match what your Swagger docs already show.

The project describes itself as a native extension of FastAPI rather than a generic converter from OpenAPI to MCP. It communicates with your app through FastAPI's ASGI interface, so it does not need to make separate HTTP calls to your API.

  • Authentication built in, using your existing FastAPI dependencies
  • Preserves schemas of request and response models
  • Preserves endpoint documentation as it appears in Swagger
  • Can be mounted on the same app or deployed separately

Install fastapi-mcp with uv or pip

The README recommends uv, a Python package installer. You can also use pip. The project requires Python 3.10 or newer, and the README recommends Python 3.12.

  • Requirements: Python 3.10+ (3.12 recommended) and uv or pip
uv add fastapi-mcp

Mount an MCP server on your FastAPI app

The simplest setup adds an MCP server directly to your existing FastAPI application. Create an FastApiMCP object from your app and call mount(). The README says the auto-generated MCP server is then available at https://app.base.url/mcp, where the base URL is your app's own address.

from fastapi import FastAPI from fastapi_mcp import FastApiMCP app = FastAPI() mcp = FastApiMCP(app) # Mount the MCP server directly to your FastAPI app mcp.mount()

Secure MCP access with FastAPI dependencies

fastapi_mcp can secure MCP endpoints using the FastAPI Depends() mechanism you already use for authentication and authorization. The README lists this as a core feature, so you do not need a separate auth system for MCP access. The project's full documentation at fastapi-mcp.tadata.com covers the details and advanced usage.

  • Use your existing Depends() authentication logic
  • Check the examples directory in the repository for code samples

Deploy the MCP server with your app or separately

By default the MCP server is mounted into the same app. The README also says the MCP server can be deployed separately from the original FastAPI app, and links to a deployment section in the documentation for that option.

  • Same app: mount the MCP server alongside your endpoints
  • Separate deployment: supported, per the project documentation

Where to get help and contribute

The README links to a Contribution Guide in the repository for people who want to post issues or submit pull requests. There is also a community Slack, MCParty, where users share experiences with the library.

What people use it for

  • Letting an AI assistant such as Claude or Cursor call your existing FastAPI endpoints as tools
  • Reusing your current FastAPI authentication for MCP endpoints instead of writing a second auth layer
  • Exposing an API without writing MCP tools by hand, using your existing routes and schemas

Frequently asked questions

Is fastapi_mcp free to use?

Yes, fastapi_mcp is released under the MIT License, a permissive open-source licence. The copyright notice in the README credits Tadata Inc. The README also mentions a separate hosted solution at tadata.com, which this guide does not evaluate.

What do I need to use fastapi_mcp?

You need an existing FastAPI application and Python 3.10 or newer, with Python 3.12 recommended. You also need uv or pip to install the package. The library extends FastAPI and is not a standalone tool.

How do I install fastapi-mcp?

Run uv add fastapi-mcp if you use uv, or pip install fastapi-mcp if you use pip. Both commands come from the project README.

Where is the MCP server URL after I mount it?

The README says the auto-generated MCP server is available at /mcp on your app's base URL, for example https://app.base.url/mcp. Replace the placeholder with your own app's address.

Can I secure MCP endpoints with my existing authentication?

Yes. The README says fastapi_mcp can secure MCP endpoints with the FastAPI Depends() mechanism you already use. Check the project documentation for implementation details.

Is fastapi_mcp an alternative to a generic OpenAPI to MCP converter?

The project positions itself as a FastAPI-native extension, not just an OpenAPI-to-MCP converter. It uses FastAPI's ASGI interface directly and preserves your schemas and docs. The source does not compare it with other tools, so check the project's documentation for further detail.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

fastapi_mcp suits Python developers who already run a FastAPI app and want AI assistants to call its endpoints with minimal setup and existing authentication. It is a poor fit for non-Python projects, for people who want a managed service without running code, or for anyone without a FastAPI app.

Install options & downloads