fastapi-mcp-server
Allows AI assistants to inspect FastAPI applications and routers, extracting OpenAPI schemas, registered routes, and backend metadata from local files or live deployments.
Provides tools to extract JSON schemas from Pydantic BaseModel classes and generate TypeScript interfaces and Zod schemas from them.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@fastapi-mcp-server Generate TypeScript interfaces from the Pydantic models in main:app"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
fastapi-mcp-server
A Model Context Protocol (MCP) server that connects AI coding assistants directly to your FastAPI applications, APIRouters, and Pydantic models.
Functions as a Full-Stack Context Bridge—allowing AI in your IDE to inspect local Python files or live backend deployments, generate 100% accurate TypeScript interfaces and Zod schemas, scaffold typed API clients, and discover backend routes without hallucinations or stale documentation.
Why this exists
When AI assistants write frontend hooks, API clients, or backend tests, they often guess request shapes, parameter names, and route paths based on incomplete file views or outdated training data.
fastapi-mcp-server solves this by giving AI assistants native inspection tools:
Dual-Mode Introspection: Inspects local
.pyfiles directly from disk (no runninguvicornrequired) 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.
Related MCP server: Swagger MCP Server
Installation & Quickstart
Using uvx (Recommended — no installation needed)
uvx fastapi-mcp-serverUsing pip
pip install fastapi-mcp-serverRunning from source
git clone https://github.com/username/fastapi-mcp-server.git
cd fastapi-mcp-server
uv sync
uv run fastapi-mcp-serverEditor & 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-serverType:
commandCommand:
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.jsonWindows:
%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: [...]"
}Development & Testing
# Clone the repository
git clone https://github.com/username/fastapi-mcp-server.git
cd fastapi-mcp-server
# Install dependencies
uv sync
# Run tests
uv run pytest
# Run type checker and linter
uv run basedpyright
uv run ruff check src testsLicense
MIT License. See LICENSE for details.
Available Tools
6 toolsdiscover_fastapi_projectA
Automatically scan a project directory to discover all FastAPI apps, APIRouters, and Pydantic models.
Args: project_dir: Optional path to the project root directory. Defaults to current working directory.
Returns: A structured catalog listing all discovered apps, routers, and models with import target strings.
Inputs: project_dir.
get_openapi_schemaA
Extract the complete OpenAPI schema from a local FastAPI app, APIRouter, factory function, or live HTTP URL.
Args: app_path: Import string pointing to the target (e.g. 'main:app', 'routers.users:router', 'https://api.example.com/openapi.json'). project_dir: Optional path to the project root directory. Defaults to current working directory.
Returns: The OpenAPI specification dictionary or an error dictionary.
Inputs: app_path (required), project_dir.
get_pydantic_schemaA
Extract the JSON Schema from a local Pydantic BaseModel class definition.
Args: model_path: Import string pointing to the Pydantic model (e.g. 'models.user:UserCreate', 'src/schemas.py:Item'). project_dir: Optional path to the project root directory. Defaults to current working directory.
Returns: The JSON schema dictionary for the Pydantic model or an error dictionary.
Inputs: model_path (required), project_dir.
get_typescript_definitionA
Generate strict TypeScript interfaces and types from a Pydantic model, FastAPI app, or live OpenAPI URL.
Args: target: Target identifier (e.g. 'models.user:UserProfile', 'main:app', 'https://api.example.com/openapi.json'). project_dir: Optional path to the project root directory.
Returns: TypeScript interface/type definitions code as a string, or an error dictionary.
Inputs: target (required), project_dir.
get_zod_schemaA
Generate Zod validation schemas with inferred TypeScript types from a Pydantic model, FastAPI app, or live OpenAPI URL.
Args: target: Target identifier (e.g. 'models.user:UserProfile', 'main:app', 'https://api.example.com/openapi.json'). project_dir: Optional path to the project root directory.
Returns: Zod schema definition code as a string, or an error dictionary.
Inputs: target (required), project_dir.
list_registered_routesA
List all registered HTTP routes, methods, operation IDs, summaries, and tags from a FastAPI app, APIRouter, or live URL.
Args: app_path: Import string pointing to the target (e.g. 'main:app', 'routers.items:router', 'http://localhost:8000/docs'). project_dir: Optional path to the project root directory. Defaults to current working directory.
Returns: A list of registered routes or an error dictionary.
Inputs: app_path (required), project_dir.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a distinct output type: OpenAPI schema, Pydantic JSON schema, route listing, TypeScript interfaces, Zod schemas, and project discovery. The two code generation tools accept similar targets, but their output formats are clearly described, so misselection is unlikely.
Most tools follow a get_<object> pattern such as get_openapi_schema, get_pydantic_schema, and get_zod_schema. list_registered_utes and discover_fastapi_project use different verbs but are still predictable and consistent in naming style.
Six tools is a well-scoped count for a FastAPI introspection and schema generation server. Each tool serves a clear purpose without unnecessary redundancy.
The tool set covers OpenAPI extraction, Pydantic schema extraction, route listing, project discovery, and both TypeScript interface and Zod schema generation. This provides comprehensive coverage for the server's stated purpose.
Maintenance
Related MCP Connectors
Publish your API docs so AI assistants can look up endpoints and call your API correctly.
Serves your design system and coding standards to coding agents, so they stop guessing.
Versioned documentation registry and semantic search for AI tools and coding assistants.
Coding agents in multi-service codebases routinely rebuild existing helpers, trust stale type definitions, and modify API contracts without knowing who consumes them. Carrick solves this by indexing your entire TypeScript ecosystem across service and repository boundaries. By integrating deeply with the TypeScript compiler, Carrick traces every route, type, and cross-service call while recording function behaviour so agents search by intent rather than name. Delivered via MCP for AI agents and LSP for IDEs, Carrick ensures models see existing endpoints and utilities before generating new code. The scanner is source-available and runs from your CLI or CI pipeline.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that provides tools for introspecting and analyzing FastAPI applications, including route discovery, model schema extraction, and source code viewing. It enables users to explore API structures, generate documentation, and debug dependency injection hierarchies through natural language.MIT
- FlicenseNot gradedqualityDmaintenanceBrings OpenAPI/Swagger documentation into AI assistants, enabling endpoint discovery, deep inspection, cURL generation, and TypeScript type generation.-
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to generate TypeScript types, Zod schemas, TypeBox, and JSON Schema from any API endpoint or JSON.2 npmMIT
- FlicenseAqualityCmaintenanceExposes FastAPI reference documentation as MCP tools, enabling LLMs to query FastAPI docs during development for accurate code generation.3-