11# FastAPI-MCP
22
3- A zero-configuration tool for integrating Model Context Protocol (MCP) servers with FastAPI applications .
3+ A zero-configuration tool for automatically exposing FastAPI endpoints as Model Context Protocol (MCP) tools .
44
55[ ![ PyPI version] ( https://badge.fury.io/py/fastapi-mcp.svg )] ( https://pypi.org/project/fastapi-mcp/ )
66[ ![ Python Versions] ( https://img.shields.io/pypi/pyversions/fastapi-mcp.svg )] ( https://pypi.org/project/fastapi-mcp/ )
@@ -10,9 +10,9 @@ A zero-configuration tool for integrating Model Context Protocol (MCP) servers w
1010- ** Direct integration** - Mount an MCP server directly to your FastAPI app
1111- ** Zero configuration** required - just point it at your FastAPI app and it works
1212- ** Automatic discovery** of all FastAPI endpoints and conversion to MCP tools
13- - ** Type-safe conversion ** from FastAPI endpoints to MCP tools
14- - ** Documentation preservation ** from FastAPI to MCP
15- - ** Custom tools ** - Add custom MCP tools alongside your API endpoints
13+ - ** Preserving schemas ** of your request models and response models
14+ - ** Preserve documentation ** of all your endpoints, just as it is in Swagger
15+ - ** Extend ** - Add custom MCP tools alongside the auto-generated ones
1616
1717## Installation
1818
@@ -28,8 +28,6 @@ Alternatively, you can install with pip:
2828pip install fastapi-mcp
2929```
3030
31- For detailed installation instructions and alternative methods, see [ INSTALL.md] ( INSTALL.md ) .
32-
3331## Basic Usage
3432
3533The simplest way to use FastAPI-MCP is to add an MCP server directly to your FastAPI application:
@@ -69,7 +67,7 @@ mcp_server = add_mcp_server(
6967 describe_full_response_schema = True # False by default. Include full JSON schema in tool descriptions, instead of just an LLM-friendly response example.
7068)
7169
72- # Add custom tools in addition to existing APIs.
70+ # Optionally add custom tools in addition to existing APIs.
7371@mcp_server.tool ()
7472async def get_server_time () -> str :
7573 """ Get the current server time."""
@@ -81,34 +79,6 @@ async def get_server_time() -> str:
8179
8280See the [ examples] ( examples ) directory for complete examples.
8381
84- ### Simple integration example:
85-
86- ``` python
87- from fastapi import FastAPI
88- from fastapi_mcp import add_mcp_server
89-
90- app = FastAPI(title = " Simple API" )
91-
92- @app.get (" /hello/{name} " )
93- async def hello (name : str ):
94- """ Say hello to someone"""
95- return {" message" : f " Hello, { name} ! " }
96-
97- # Add MCP server
98- mcp_server = add_mcp_server(app, mount_path = " /mcp" )
99-
100- # Optionally add custom tools
101- @mcp_server.tool ()
102- async def get_current_time ():
103- """ Get the current server time"""
104- from datetime import datetime
105- return datetime.now().isoformat()
106-
107- if __name__ == " __main__" :
108- import uvicorn
109- uvicorn.run(app, host = " 127.0.0.1" , port = 8000 )
110- ```
111-
11282## Connecting to the MCP Server
11383
11484Once your FastAPI app with MCP integration is running, you can connect to it with any MCP client, such as Claude:
0 commit comments