fastmcp_slim/fastmcp/server/providers/openapi/README.md
This directory contains the next-generation FastMCP server implementation for OpenAPI integration, designed to replace the legacy implementation in /server/openapi.py.
The new implementation uses a stateless request building approach with openapi-core and RequestDirector, providing zero-latency startup and robust OpenAPI support optimized for serverless environments.
server.py - FastMCPOpenAPI main server class with RequestDirector integrationcomponents.py - Simplified component implementations using RequestDirectorrouting.py - Route mapping and component selection logicOpenAPIToolOpenAPIResource / OpenAPIResourceTemplateFastMCPOpenAPI ClassThe main server class orchestrates the stateless request building approach:
class FastMCPOpenAPI(FastMCP):
def __init__(self, openapi_spec: dict, client: httpx2.AsyncClient, **kwargs):
# 1. Parse OpenAPI spec to HTTP routes with pre-calculated schemas
self._routes = parse_openapi_to_http_routes(openapi_spec)
# 2. Initialize RequestDirector with openapi-core Spec
self._spec = Spec.from_dict(openapi_spec)
self._director = RequestDirector(self._spec)
# 3. Create components using RequestDirector
self._create_components()
def _create_tool(self, route: HTTPRoute) -> Tool:
# All tools use RequestDirector for consistent, high-performance request building
return OpenAPITool(
client=self._client,
route=route,
director=self._director,
name=tool_name,
description=description,
parameters=flat_param_schema
)
OpenAPI Spec → HTTPRoute with Pre-calculated Fields → RequestDirector → HTTP Request → Structured Response
HTTPRoute models with pre-calculated schemasid in path and body becomes id__path and idserver = FastMCPOpenAPI(
openapi_spec=spec, # Required: OpenAPI specification
client=httpx_client, # Required: HTTP client instance
name="API Server", # Optional: Server name
route_map=custom_routes, # Optional: Custom route mappings
enable_caching=True, # Optional: Enable response caching
)
from fastmcp.server.openapi_new.routing import RouteMap
custom_routes = RouteMap({
"GET:/users": "tool", # Force specific operations to be tools
"GET:/status": "resource", # Force specific operations to be resources
})
Tests are organized by functionality:
test_server.py - Server integration and RequestDirector behaviortest_parameter_collisions.py - Parameter collision handlingtest_deepobject_style.py - DeepObject parameter style supporttest_openapi_features.py - General OpenAPI feature complianceasync def test_stateless_request_building():
"""Test that server works with stateless RequestDirector approach."""
# Test server initialization is fast
start_time = time.time()
server = FastMCPOpenAPI(spec=valid_spec, client=client)
init_time = time.time() - start_time
assert init_time < 0.01 # Should be very fast
# Verify RequestDirector functionality
assert hasattr(server, '_director')
assert hasattr(server, '_spec')
# Enable debug logging to see implementation choices
import logging
logging.getLogger("fastmcp.server.openapi_new").setLevel(logging.DEBUG)
RequestDirector Initialization Fails
openapi-coreParameter Issues
Performance Issues
/utilities/openapi_new/README.md - Utility implementation details/server/openapi/README.md - Legacy implementation reference/tests/server/openapi_new/ - Comprehensive test suite