fastapi-mcp2
Exposes FastAPI application endpoints as MCP tools, automatically converting an app's OpenAPI schema into tools. Supports operation filtering (include/exclude by operation ID or tag), auth configuration, header forwarding, and mounting over streamable HTTP (at /mcp) or SSE (at /sse), with input validation and clean error reporting on tool calls.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@fastapi-mcp2call the /users endpoint and show me the response"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
fastapi-mcp2
A maintained, drop-in fork of fastapi-mcp that works with mcp 2.x.
Expose your FastAPI endpoints as Model Context Protocol (MCP) tools. The import name is unchanged (fastapi_mcp), so
switching is one line.
Why this fork exists
Upstream fastapi-mcp 0.4.0 (July 2025) has no release since, and pip install fastapi-mcp now pulls mcp 2.x, which
changed the low-level server API. A fresh install then dies on the first line that matters:
>>> FastApiMCP(app)
TypeError: Server.__init__() takes 2 positional arguments but 3 were givenThe fix pull requests on upstream were closed unmerged, and pinning mcp<2 collides with other packages that need
mcp>=2.3. This fork ports the code to the new API (and keeps mcp 1.x working), and adds the fixes that were waiting.
Related MCP server: FastAPI-MCP
Switch in 30 seconds
$ pip uninstall fastapi-mcp # both packages install the same module, so remove the old one first
$ pip install fastapi-mcp2No code change: from fastapi_mcp import FastApiMCP keeps working.
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI()
mcp = FastApiMCP(app)
mcp.mount_http() # streamable HTTP at /mcp (recommended); mcp.mount_sse() serves SSE at /ssePoint any MCP client at http://localhost:8000/mcp. All the upstream options (include_operations,
exclude_tags, auth_config, headers, http_client, ...) work as documented in the
upstream docs; the examples/ folder is carried over.
What changed compared with fastapi-mcp 0.4.0
Works with
mcp1.12+ and 2.x (tested on 1.30 and 2.3). One compat module,fastapi_mcp/_compat.py, hides the API difference.Input validation on mcp 2: the 2.x server stopped validating tool arguments against the input schema, so the fork does it (
Input validation error: ...as a tool error, like 1.x did).Unknown tools and API errors come back as MCP tool errors (
isError), not as protocol crashes.Server description is passed as the MCP server
instructions(upstream passed it into the version slot).No OAuth client-secret leak (behavior change): the fake dynamic registration endpoint is unauthenticated and used to hand your
client_secretto anyone. It no longer does, unless you setAuthConfig(expose_client_secret=True).Path parameters are URL-encoded (
name="a b?c"no longer breaks the request path).Recursive models (a tree node that contains nodes) no longer overflow the stack while schemas are resolved.
Optional/union parameters get a deterministic JSON type instead of a set-order dependent one.
Clean shutdown: the HTTP session manager's background task stops with the FastAPI app (your own
lifespanstill runs).SSE message endpoint checks that a session is used with the credential that opened it (mcp 2 rule).
Fewer dependencies:
typer,rich,requestsandtomliwere never imported by the library and are gone.
What is not changed: the public API, the module name, tool naming and the OpenAPI to tool conversion.
Install
$ pip install fastapi-mcp2Needs Python 3.10+ (the same as mcp).
Tests
$ pip install -e . pytest pytest-asyncio pytest-cov pyjwt cryptography
$ pytest99 tests (conversion, tool calls, SSE and streamable-HTTP transports against a real uvicorn server, auth config,
OAuth registration, header forwarding, lifespan). The suite passes on Python 3.10, 3.12 and 3.14 with mcp 2.3, and on 3.10 and 3.12 with mcp 1.12, 1.20 and 1.30.
Credits and license
Based on fastapi-mcp by Tadata Inc. (MIT). This fork is independent and
not affiliated with Tadata. MIT license; both copyright notices are kept in LICENSE.
Support
If this saves you time, you can donate via PayPal.
This server cannot be deployed
Maintenance
Related MCP Connectors
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
Host any HTTP API as MCP tools with a tamper-evident cross-agent settlement ledger.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Related MCP Servers
- FlicenseNot gradedqualityNot gradedmaintenanceAuto-converts FastAPI endpoints into MCP tools for semantic search, data ingestion (text, code, conversations), and knowledge graph operations. Provides dual access through MCP protocol and direct API calls with automatic tool generation from FastAPI routes.-
- AlicenseNot gradedqualityDmaintenanceExposes 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.MIT
- AlicenseNot gradedqualityDmaintenanceExposes your FastAPI endpoints as Model Context Protocol tools with authentication, preserving schemas and documentation.1MIT
- AlicenseNot gradedqualityDmaintenanceExposes OpenAPI endpoints as MCP tools, enabling LLMs to discover and interact with REST APIs through the MCP protocol.10 npmMIT