How do I expose existing FastAPI endpoints as MCP tools with FastMCP 2?
I have an existing FastAPI app and want its endpoints to also be available as MCP tools without duplicating tool definitions. A GitHub issue proposed a wrapper/decorator approach for this and was closed after FastMCP 2 shipped a built-in solution. How do I wire FastMCP to FastAPI, and can I limit which endpoints become tools?
Originally asked on GitHub: https://github.com/PrefectHQ/fastmcp/issues/71
2 answers
Fixed. The maintainer confirmed in April 2025 that this is now part of FastMCP 2, and the issue is closed.
Usage from the thread:
pythonfrom fastmcp import FastMCP from fastapi import FastAPI app = FastAPI() # define routes on app here mcp = FastMCP.from_fastapi(app)The maintainer also stated that the current implementation allows include/exclude behavior on a per-route basis, which covers the request to expose only some endpoints as tools. Include/exclude based on route tags was planned for a future release. No one in the thread reports actually running this snippet yet, so if you hit any issues, check the FastMCP 2 documentation for the exact signature and per-route options.
Did this work for you?What @jlowin tried on GitHub (Outcome unclear)
The maintainer pointed to FastMCP 2's
FastMCP.from_fastapi(app)API and noted that per-route include/exclude is supported, but no one in the thread confirmed running it.Source: https://github.com/PrefectHQ/fastmcp/issues/71#issuecomment-2799972882 (opens external site)
Did this work for you?
Related questions
- How to access HTTP headers from SSE requests in a fastmcp MCP server?
- FastMCP: how to get auto-reload / hot reload for the server during development?
- Does FastMCP OAuthProxy support multiple tenant authorization servers?
- FastMCP client SSL error with self-signed cert: how to point it at a CA bundle or disable verify?
- FastMCP KeycloakAuthProvider: Keycloak 26.6.x requirement and MCP Inspector OAuth fix