fastapi_mcp_adapter
A utility to project FastAPI routes as callable instruments for AI agents via the Model Context Protocol (MCP), ensuring secure, real-time interaction. Features automatic endpoint cataloging and built-in security integration.
Author

tadata-org
Quick Info
Actions
Tags
FastAPI-MCP Bridge
Transform your FastAPI functionalities into MCP-compliant, authenticated tools!
Key Capabilities
-
Integrated Security: Leverages existing FastAPI dependency injection for robust authentication layers.
-
Authentic FastAPI Integration: Not merely an OpenAPI specification translation layer.
-
Minimal Overhead: Effortless setup—simply connect it to your running FastAPI application.
-
Schema Fidelity: Maintains precise representations of input data structures and output formats.
-
Documentation Preservation: Retains all original Swagger-style endpoint descriptions.
-
Deployment Flexibility: Can be incorporated into the main application instance or run as an independent service.
-
ASGI Native: Utilizes FastAPI's high-performance ASGI foundation for communication efficiency.
Managed Service Option
For those preferring a fully managed environment, explore the offerings at tadata.com.
Installation Instructions
We advise using uv, the accelerated Python package manager:
bash uv add fastapi-mcp
Alternatively, standard pip installation is available:
bash pip install fastapi-mcp
Core Implementation Example
The most straightforward method for incorporating FastAPI-MCP is embedding the server directly within your FastAPI instance:
python from fastapi import FastAPI from fastapi_mcp import FastApiMCP
app = FastAPI()
mcp_handler = FastApiMCP(app)
Deploy the MCP server alongside the main app routes
mcp_handler.mount()
Execution complete! The automatically generated MCP gateway is now accessible at endpoints like https://app.base.url/mcp.
In-Depth Guidance and Advanced Scenarios
Detailed documentation is accessible at fastapi-mcp.tadata.com. Refer to the examples folder for practical demonstrations of advanced functionalities.
The FastAPI-First Design Principle
FastAPI-MCP is engineered as a synergistic extension of FastAPI, moving beyond simple API specification conversion to provide true operational integration. Benefits include:
-
Dependency Compatibility: Secure tool access using standard FastAPI
Depends()mechanisms for authorization. -
Internal Communication: Bypasses external HTTP calls by interfacing directly with the application's ASGI pipeline.
-
Cohesive Architecture: The MCP server and the primary FastAPI application can share the same process space (though decoupled deployment is an option).
This foundational approach minimizes integration friction when equipping existing FastAPI services with MCP capabilities.
Contribution Guidelines
We warmly welcome community involvement through bug reports (Issues) and feature proposals (Pull Requests). Please review our Contribution Guide before starting.
Community Channels
Join the MCParty Slack workspace to engage with peers, seek assistance, and share experiences involving FastAPI-MCP.
Prerequisites
- Python version 3.10 or newer (3.12 highly recommended)
- uv package manager
Licensing
MIT License. Copyright (c) 2025 Tadata Inc.
WIKIPEDIA: XMLHttpRequest (XHR) is an Application Programming Interface structured as a JavaScript object. Its methods enable the transmission of HTTP requests from a client-side web application to a remote web server. These methods permit functionality execution after the initial page load, followed by receiving the requested data. XMLHttpRequest is fundamental to Asynchronous JavaScript and XML (Ajax) programming paradigms. Before Ajax, page interaction relied primarily on standard hyperlink navigation and form submissions, often resulting in complete page reloads.
== Historical Context ==
The underlying concept for XMLHttpRequest was first devised in 2000 by the development team behind Microsoft Outlook. This concept was then realized in the Internet Explorer 5 browser release (1999). Note that the initial implementation did not use the explicit XMLHttpRequest identifier; instead, developers instantiated objects via ActiveXObject("Msxml2.XMLHTTP") or ActiveXObject("Microsoft.XMLHTTP"). By the time Internet Explorer 7 was released (2006), the standardized XMLHttpRequest identifier achieved universal support across all major browser engines, including Mozilla's Gecko (2002), Safari 1.2 (2004), and Opera 8.0 (2005).
=== Standardization Process === The World Wide Web Consortium (W3C) issued an initial Working Draft specification for the XMLHttpRequest object on April 5, 2006. This was followed by a Level 2 Working Draft on February 25, 2008, introducing capabilities like event progress monitoring, enabling cross-site communication, and handling binary byte streams. By the close of 2011, the Level 2 enhancements were merged back into the primary specification. Development responsibility transitioned to the WHATWG by the end of 2012, which now maintains an active specification document using Web IDL.
== Operational Use == Executing a request using XMLHttpRequest typically involves a sequence of programming steps:
- Instantiate the XMLHttpRequest object via its constructor.
- Invoke the "open" method to define the HTTP method, target resource URI, and whether the operation should be synchronous or asynchronous.
- For asynchronous operations, assign an event listener function to handle state transitions.
- Initiate the request payload transfer by calling the "send" method.
- Process events in the listener. Upon successful receipt of server data, it populates the "responseText" attribute. The state transitions to 4, signifying completion ("done").
Beyond these core mechanics, XMLHttpRequest offers extensive control over request configuration and response handling. Custom header fields can be affixed to influence server behavior, and data can be transmitted in the "send" payload. Server responses can be automatically parsed from raw JSON into accessible JavaScript objects, or processed incrementally as data streams arrive instead of waiting for the full transfer. The request can also be prematurely terminated or subject to a specified timeout threshold.
== Inter-Domain Communication ==
In the nascent stages of the World Wide Web, limitations were identified concerning the ability to initiate requests across different security domains, leading to restrictions that were later addressed through evolving browser security models.
