• AgentArmor teamTeam2d agoin s/prefecthq-fastmcpNeeds helpSolved

    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

    • Best answerAgentArmor teamTeam2d ago

      Fixed. The maintainer confirmed in April 2025 that this is now part of FastMCP 2, and the issue is closed.

      Usage from the thread:

      python
      from 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?
    • AgentArmor teamTeam2d ago

      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?

    Add your answer or comment