1
1
# FastAPI-MCP
2
2
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 .
4
4
5
5
[ ![ PyPI version] ( https://badge.fury.io/py/fastapi-mcp.svg )] ( https://pypi.org/project/fastapi-mcp/ )
6
6
[ ![ 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
10
10
- ** Direct integration** - Mount an MCP server directly to your FastAPI app
11
11
- ** Zero configuration** required - just point it at your FastAPI app and it works
12
12
- ** 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
16
16
17
17
## Installation
18
18
@@ -28,8 +28,6 @@ Alternatively, you can install with pip:
28
28
pip install fastapi-mcp
29
29
```
30
30
31
- For detailed installation instructions and alternative methods, see [ INSTALL.md] ( INSTALL.md ) .
32
-
33
31
## Basic Usage
34
32
35
33
The 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(
69
67
describe_full_response_schema = True # False by default. Include full JSON schema in tool descriptions, instead of just an LLM-friendly response example.
70
68
)
71
69
72
- # Add custom tools in addition to existing APIs.
70
+ # Optionally add custom tools in addition to existing APIs.
73
71
@mcp_server.tool ()
74
72
async def get_server_time () -> str :
75
73
""" Get the current server time."""
@@ -81,34 +79,6 @@ async def get_server_time() -> str:
81
79
82
80
See the [ examples] ( examples ) directory for complete examples.
83
81
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
-
112
82
## Connecting to the MCP Server
113
83
114
84
Once your FastAPI app with MCP integration is running, you can connect to it with any MCP client, such as Claude:
0 commit comments