fastapi-mcp-server
A Model Context Protocol (MCP) server functioning as a Full-Stack Context Bridge for FastAPI, APIRouters, live OpenAPI endpoints, and Pydantic models.
⚡ Why this exists: Two Different MCP Paradigms
It is important to distinguish between two completely different uses of MCP with FastAPI:
| Feature / Goal | fastapi-mcp (Execution Tool) |
fastapi-mcp-server (Co-Developer Bridge) |
|---|---|---|
| Primary Goal | Enables AI to call live endpoints as runtime tools. | Enables AI to write, inspect, and synchronize code. |
| Server Requirement | Requires a running, live uvicorn instance. |
Zero server needed: inspects local files on disk (or live URLs). |
| Pydantic Model Schemas | Only exposes parameters for executed calls. | Extracts full JSON schemas directly from Python BaseModel classes. |
| Frontend Code Gen | Not supported. | Directly outputs TypeScript interfaces & Zod validation schemas. |
| Project Auto-Discovery | Manual route registration. | AST scanner catalogs all apps, routers, and models automatically. |
| Ideal For | AI agents executing actions in production. | Developers & AI assistants writing frontend & backend code in IDEs. |
🌟 Key Capabilities
- Dual-Mode Introspection: Inspects local
.pyfiles directly from disk without running a server, or fetches live schemas from deployed staging/production URLs (https://api.example.com/openapi.jsonorhttp://localhost:8000/docs). - Instant TypeScript & Zod Generation: Converts Pydantic models and OpenAPI schemas into strict, copy-paste ready TypeScript
interfaces and Zod validation schemas with full typing, nullability, and JSDoc comments. - Standalone Router & Sub-Module Support: Introspects full applications (
main:app) as well as standaloneAPIRouterfiles (routers.users:router) and factory functions. - Project Auto-Discovery: Scans backend repositories using AST analysis to catalog every FastAPI app, router, and Pydantic model automatically.
- Cross-Repository Context: Frontend developers working in a separate repository (e.g. Next.js/React) can point their IDE's MCP client to the backend project directory to inspect backend types while writing frontend code.
📦 Installation & Quickstart
Using uvx (Recommended — no installation needed)
uvx fastapi-mcp-server
Using pip
pip install fastapi-mcp-server
Running from source
git clone https://github.com/username/fastapi-mcp-server.git
cd fastapi-mcp-server
uv sync
uv run fastapi-mcp-server
🛠️ Editor & Client Configuration
Zed IDE
Add to your Zed settings.json (Ctrl + , or Cmd + ,):
{
"context_servers": {
"fastapi-mcp-server": {
"command": {
"path": "uvx",
"args": ["fastapi-mcp-server"]
}
}
}
}
For local workspace development without publishing:
{
"context_servers": {
"fastapi-mcp-server": {
"command": {
"path": "uv",
"args": [
"run",
"--directory",
"/path/to/fastapi-mcp-server",
"fastapi-mcp-server"
]
}
}
}
}
Cursor
Go to Cursor Settings > Features > MCP Servers > + Add New MCP Server:
- Name:
fastapi-mcp-server - Type:
command - Command:
uvx fastapi-mcp-server
VS Code (with MCP / Copilot)
Add to your VS Code user or workspace settings (settings.json):
{
"mcp": {
"servers": {
"fastapi-mcp-server": {
"command": "uvx",
"args": ["fastapi-mcp-server"]
}
}
}
}
Claude Desktop
Add to your claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"fastapi-mcp-server": {
"command": "uvx",
"args": ["fastapi-mcp-server"]
}
}
}
🧰 Available MCP Tools
1. get_openapi_schema
Extracts the complete OpenAPI JSON schema from a local FastAPI app, standalone APIRouter, factory function, or live deployed HTTP URL.
app_path(str, required): Import target (e.g."main:app","routers.users:router","src/api.py:app") or live URL ("https://api.example.com/openapi.json","http://localhost:8000/docs").project_dir(str, optional): Path to the backend project root.
2. get_pydantic_schema
Extracts the JSON Schema from any Pydantic BaseModel class (supporting both Pydantic v2 and v1).
model_path(str, required): Import target (e.g."models.user:UserProfile","src/schemas.py:Item").project_dir(str, optional): Path to the backend project root.
3. list_registered_routes
Returns a structured catalog of registered routes, HTTP methods, operation IDs, summaries, and tags from an app, standalone router, or live URL.
app_path(str, required): Target app, router, or URL.project_dir(str, optional): Path to the backend project root.
4. get_typescript_definition
Directly generates strict TypeScript interfaces and types from a Pydantic model, local app, or remote OpenAPI URL.
target(str, required): Model target (e.g."models.user:UserProfile"), app target ("main:app"), or live URL.project_dir(str, optional): Path to the backend project root.
5. get_zod_schema
Generates client-side Zod validation schemas (z.object({...})) and inferred TypeScript types from a Pydantic model or OpenAPI target.
target(str, required): Model target, app target, or live URL.project_dir(str, optional): Path to the backend project root.
6. discover_fastapi_project
Scans a backend project directory using zero-execution AST parsing to catalog all FastAPI instances, APIRouters, and Pydantic models.
project_dir(str, optional): Path to the project directory to scan.
🛡️ Error Handling
All tools return clean structured JSON dictionaries rather than raising unhandled exceptions or crashing the MCP connection:
{
"error": "ModuleNotFoundError",
"detail": "Failed to import module 'src.main'. Searched in sys.path: [...]"
}
🤝 Contributing
We welcome contributions! Please check out CONTRIBUTING.md for details on setting up the dev environment, running tests, and submitting PRs.
📄 License
MIT License. See LICENSE for details.
Metadata
Release files for fastapi-mcp-server 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fastapi_mcp_server-0.1.0.tar.gz | 89.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_mcp_server-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 105.9 kB
Release files / fastapi_mcp_server-0.1.0.tar.gz
| Download URL | fastapi_mcp_server-0.1.0.tar.gz |
|---|---|
| Size | 89.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebc2b85ce4017c85620833e063d7f3a043e72de9a38d4593c3bee4ad8af096be
|
|
BLAKE2b-256 checksum How to use checksums |
eb2d81f7c2ad6f519aa117bc58794845f6629e3d9b1a1c865f62d190061cee69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / fastapi_mcp_server-0.1.0-py3-none-any.whl
| Download URL | fastapi_mcp_server-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5cbd90d2e42deae2cf325fe660878cba7d3c416e1d99aa4f9ca1ed436db85cdf
|
|
BLAKE2b-256 checksum How to use checksums |
7f9606053f54107cd785ef9153bf8ea3f20b02452e5a5383e7e848f02f0713c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for fastapi-mcp-server 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.