FastAPI-MCP

FastAPI-MCP is an open-source MCP tool that automatically converts your existing FastAPI endpoints into MCP tools. Seamlessly integrate your Python APIs with AI models and agents using the Model Context Protocol with minimal configuration.

FastAPI-MCP
FastAPI-MCP Capabilities Showcase

FastAPI-MCP Solution Overview

FastAPI-MCP is an open-source tool specifically designed for developers utilizing the FastAPI framework. It streamlines the creation of Model Context Protocol (MCP) Servers by automatically exposing existing FastAPI endpoints as discoverable MCP Tools. This crucial capability allows AI models and agents, operating through standard MCP Clients such as Cursor or Cline, to seamlessly interact with your API's functionalities without necessitating a complex rewrite. By integrating with just a few lines of Python code into your existing FastAPI application, FastAPI-MCP automatically converts your endpoints and serves them via an MCP Server interface. Developers can further enhance this by adding custom MCP Tools alongside the auto-generated ones. The primary value is the rapid integration of established FastAPI services into the MCP ecosystem, significantly reducing development overhead and instantly making your APIs accessible to AI agents.

FastAPI-MCP Key Capabilities

Automatic FastAPI Endpoint Conversion

FastAPI-MCP provides a core capability to automatically discover and transform existing FastAPI application endpoints into fully functional MCP tools. This process requires minimal developer intervention, typically involving just a few lines of code to integrate the add_mcp_server function into the FastAPI application instance. The tool introspects the FastAPI application's routes, analyzing path parameters, query parameters, and request bodies to generate corresponding MCP tool definitions. This includes mapping HTTP methods (GET, POST, PUT, DELETE, etc.) and data structures to the MCP tool schema, defining necessary inputs and expected outputs. This significantly accelerates the process of making existing API functionalities accessible to AI models and agents operating within the MCP ecosystem, eliminating the need for manual translation or rewriting of API logic into MCP specifications. For example, an existing /users/{user_id} GET endpoint in a FastAPI app can be automatically exposed as an MCP tool named get_user_by_id that accepts user_id as input.

Seamless MCP Server Integration

FastAPI-MCP simplifies the creation and mounting of an MCP Server directly within an existing FastAPI application. By calling the add_mcp_server function, developers can specify a mount path (e.g., /mcp) where the MCP server endpoints (/mcp/tools, /mcp/resources, etc.) will be hosted. This function handles the necessary boilerplate setup for the MCP server, including routing and request handling according to the MCP specification. It effectively embeds an MCP-compliant interface alongside the standard RESTful API endpoints, allowing the same application instance to serve both traditional HTTP clients and MCP clients. This integration avoids the need to run a separate process or manage a distinct deployment for the MCP interface, streamlining development and operations. A developer can integrate it by adding add_mcp_server(app, mount_path="/mcp", name="MyAPI_MCP") to their main FastAPI application file (app), instantly making their API MCP-compatible at the specified path.

Extensible Tool Definition

While FastAPI-MCP excels at automatic conversion, it also offers the flexibility to define custom MCP tools alongside the auto-generated ones. This allows developers to expose functionalities that may not directly map to existing FastAPI endpoints or require more complex logic than a simple API call translation. Developers can manually create specific MCP tool definitions using the underlying MCP library structures and register them with the server instance managed by FastAPI-MCP. This hybrid approach enables leveraging the speed of auto-generation for standard endpoints while retaining fine-grained control for specialized tasks or integrating functionalities beyond the scope of the original FastAPI application. For instance, a developer could auto-generate tools from their CRUD endpoints but add a custom MCP tool that orchestrates multiple API calls or interacts with a different backend service, all exposed through the same integrated MCP server interface. This ensures comprehensive coverage of required functionalities for AI agents.