fastmcp.server.http
Functions
set_http_request
create_base_app
routes: List of routes to include in the appmiddleware: List of middleware to include in the appdebug: Whether to enable debug modelifespan: Optional lifespan manager for the app
- A Starlette application
create_sse_app
server: The FastMCP server instancemessage_path: Path for SSE messagessse_path: Path for SSE connectionsauth: Optional authentication provider (AuthProvider)debug: Whether to enable debug moderoutes: Optional list of custom routesmiddleware: Optional list of middlewarehost_origin_protection: Whether to validate Host and Origin headers before requests reach the SSE connection and message endpoints. Defaults to False for compatibility. “auto” protects localhost-bound servers and explicit host/origin allowlists.allowed_hosts: Additional hostnames that may appear in the Host header.allowed_origins: Additional browser origins trusted by the request guard. Configure CORS separately when browser JavaScript must read cross-origin responses.
create_streamable_http_app
server: The FastMCP server instancestreamable_http_path: Path for StreamableHTTP connectionsevent_store: Optional event store for SSE polling/resumabilityretry_interval: Optional retry interval in milliseconds for SSE polling. Controls how quickly clients should reconnect after server-initiated disconnections. Requires event_store to be set. Defaults to SDK default.auth: Optional authentication provider (AuthProvider)json_response: Whether to use JSON response formatstateless_http: Whether to use stateless mode (new transport per request)debug: Whether to enable debug moderoutes: Optional list of custom routesmiddleware: Optional list of middlewarehost_origin_protection: Whether to validate Host and Origin headers before requests reach the MCP endpoint. Defaults to False for compatibility. “auto” protects localhost-bound servers and explicit host/origin allowlists.allowed_hosts: Additional hostnames that may appear in the Host header.allowed_origins: Additional browser origins trusted by the request guard. Configure CORS separately when browser JavaScript must read cross-origin responses.session_idle_timeout: Maximum time in seconds a session may remain idle before it is terminated. The deadline is pushed forward on every request. Defaults to “auto”, which uses the MCP SDK’s default (1800 seconds as of SDK 2.2). When None, sessions never expire from inactivity. Only applies to stateful HTTP sessions.
- A Starlette application with StreamableHTTP support

