FastAPI-MCP

v1.0.0Developer Toolsstable

Exposes FastAPI endpoints as Model Context Protocol (MCP) tools while preserving existing authentication, schemas, and documentation. It enables seamless integration of FastAPI services into MCP ecosystems using a native ASGI transport layer.

aiauthenticationauthorizationclaudecursor
Share:
11,873
Stars
0
Downloads
0
Weekly
0/5

What is FastAPI-MCP?

FastAPI-MCP is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to exposes fastapi endpoints as model context protocol (mcp) tools while preserving existing authentication, schemas, and documentation. it enables seamless integration of fastapi services into mcp ecosy...

Exposes FastAPI endpoints as Model Context Protocol (MCP) tools while preserving existing authentication, schemas, and documentation. It enables seamless integration of FastAPI services into MCP ecosystems using a native ASGI transport layer.

This server falls under the Developer Tools category on MCPgee, the world's largest MCP server directory with 33,000+ servers.

Features

  • Exposes FastAPI endpoints as Model Context Protocol (MCP) to

Use Cases

FastAPI endpoint exposure
Schema preservation
Authentication integration
tadata-org

Maintainer

LicenseMIT License
Languagepython
Versionv1.0.0
UpdatedMay 22, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx fastapi-mcp

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

How to Set Up and Use FastAPI-MCP

FastAPI-MCP is a Python library that automatically converts your existing FastAPI application's endpoints into MCP tools, preserving your authentication logic, Pydantic schemas, and OpenAPI documentation without any extra boilerplate. It uses a native ASGI transport layer for zero-overhead communication, meaning your FastAPI app becomes an MCP server the moment you add three lines of code. Python developers who already have FastAPI services and want to expose them to AI agents or Claude Desktop will find this the fastest path to MCP integration.

Prerequisites

  • Python 3.10 or later (3.12 recommended)
  • An existing FastAPI application
  • pip or uv package manager
  • An MCP-compatible client such as Claude Desktop or Cursor to test the integration
1

Install fastapi-mcp

Add fastapi-mcp to your project using uv (recommended) or pip. No additional dependencies beyond FastAPI are required for basic use.

uv add fastapi-mcp
# or:
pip install fastapi-mcp
2

Import and attach FastApiMCP to your app

Add three lines to your existing FastAPI application file. FastApiMCP wraps your app and mounts the MCP server at /mcp automatically.

from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()
mcp = FastApiMCP(app)
mcp.mount()
3

Run your FastAPI application

Start your application as usual. The MCP server is now available at the /mcp path alongside your existing API endpoints.

uvicorn main:app --reload
4

Verify the MCP endpoint is live

Confirm the MCP server is accessible by checking its URL. Replace localhost:8000 with your actual host and port.

curl http://localhost:8000/mcp
5

Configure your MCP client to connect

Point your MCP client at the running FastAPI-MCP server. For clients that support HTTP transport, use the /mcp URL directly.

{
  "mcpServers": {
    "fastapi-mcp": {
      "url": "http://localhost:8000/mcp"
    }
  }
}
6

Test endpoint exposure

Ask your AI client to list available tools. It should reflect all your FastAPI endpoints as callable MCP tools, with schemas derived from your Pydantic models.

FastAPI-MCP Examples

Client configuration

MCP client configuration pointing to a locally running FastAPI-MCP server.

{
  "mcpServers": {
    "fastapi-mcp": {
      "url": "http://localhost:8000/mcp"
    }
  }
}

Prompts to try

Example prompts once your FastAPI application is exposed via FastAPI-MCP.

- "List all available tools from my FastAPI application"
- "Call the /users endpoint and return the first 10 user records"
- "Create a new product using the POST /products endpoint with name 'Widget' and price 9.99"
- "What does the /orders/{order_id} endpoint accept and return?"
- "Run the /reports/sales endpoint with date_from=2026-01-01 and summarize the result"

Troubleshooting FastAPI-MCP

The /mcp endpoint returns 404 Not Found

Ensure you called `mcp.mount()` after creating the FastApiMCP instance. Also confirm your application has reloaded with `uvicorn main:app --reload`. The MCP endpoint only registers after mount() is invoked.

Authentication-protected endpoints return 401 when called from the MCP client

FastAPI-MCP preserves your FastAPI `Depends()` authentication. Your MCP client must pass the required credentials (Bearer token, API key, etc.) in the same way an HTTP client would. Check how your MCP client supports header injection or use FastAPI-MCP's built-in auth forwarding configuration.

Pydantic validation errors when the AI client calls an endpoint

The AI may be generating parameters that do not match your Pydantic model. Check the tool schema your MCP client receives (it should mirror your FastAPI OpenAPI docs) and refine your prompt to specify the correct field names and types.

Frequently Asked Questions about FastAPI-MCP

What is FastAPI-MCP?

FastAPI-MCP is a Model Context Protocol (MCP) server that exposes fastapi endpoints as model context protocol (mcp) tools while preserving existing authentication, schemas, and documentation. it enables seamless integration of fastapi services into mcp ecosystems using a native asgi transport layer. It connects AI assistants to external tools and data sources through a standardized interface.

How do I install FastAPI-MCP?

Follow the installation instructions on the FastAPI-MCP GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.

Which AI clients work with FastAPI-MCP?

FastAPI-MCP works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.

Is FastAPI-MCP free to use?

Yes, FastAPI-MCP is open source and available under the MIT License license. You can use it freely in both personal and commercial projects.

Browse More Developer Tools MCP Servers

Explore all developer tools servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.

Quick Config Preview

{ "mcpServers": { "fastapi-mcp": { "command": "npx", "args": ["-y", "fastapi-mcp"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

Ready to use FastAPI-MCP?

Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.

33,000+ ServersFree & Open SourceStep-by-Step Guides