Patterns
OpenAPI Integration
Generate MCP servers from OpenAPI specs
New in version 2.0.0
FastMCP can automatically generate an MCP server from an OpenAPI specification. Users only need to provide an OpenAPI specification (3.0 or 3.1) and an API client.
Route Mapping
By default, OpenAPI routes are mapped to MCP components based on these rules:
OpenAPI Route | Example | MCP Component | Notes |
---|---|---|---|
GET without path params | GET /stats | Resource | Simple resources for fetching data |
GET with path params | GET /users/{id} | Resource Template | Path parameters become template parameters |
POST , PUT , PATCH , DELETE , etc. | POST /users | Tool | Operations that modify data |
Internally, FastMCP uses a priority-ordered set of RouteMap
objects to determine the component type. Route maps indicate that a specific HTTP method (or methods) and path pattern should be treated as a specific component type. This is the default set of route maps:
Custom Route Maps
Users can add custom route maps to override the default mapping behavior. User-supplied route maps are always applied first, before the default route maps.
How It Works
- FastMCP parses your OpenAPI spec to extract routes and schemas
- It applies mapping rules to categorize each route
- When an MCP client calls a tool or accesses a resource:
- FastMCP constructs an HTTP request based on the OpenAPI definition
- It sends the request through the provided httpx client
- It translates the HTTP response to the appropriate MCP format