docs/python-sdk/fastmcp-server-http.mdx
fastmcp.server.httpset_http_request <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L355" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>set_http_request(request: Request) -> Generator[Request, None, None]
create_base_app <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L388" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>create_base_app(routes: list[BaseRoute], middleware: list[Middleware], debug: bool = False, lifespan: Callable | None = None) -> StarletteWithLifespan
Create a base Starlette app with common middleware and routes.
Args:
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 appReturns:
create_sse_app <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L416" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>create_sse_app(server: FastMCP[LifespanResultT], message_path: str, sse_path: str, auth: AuthProvider | None = None, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None) -> StarletteWithLifespan
Return an instance of the SSE server app.
Args:
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 middlewareReturns: A Starlette application with RequestContextMiddleware
create_streamable_http_app <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L545" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>create_streamable_http_app(server: FastMCP[LifespanResultT], streamable_http_path: str, event_store: EventStore | None = None, retry_interval: int | None = None, auth: AuthProvider | None = None, json_response: bool = False, stateless_http: bool = False, debug: bool = False, routes: list[BaseRoute] | None = None, middleware: list[Middleware] | None = None, host_origin_protection: HostOriginProtection = False, allowed_hosts: Sequence[str] | None = None, allowed_origins: Sequence[str] | None = None, session_idle_timeout: float | None = None) -> StarletteWithLifespan
Return an instance of the StreamableHTTP server app.
Args:
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. When None, sessions never expire from inactivity. Not
supported in stateless mode.Returns:
FastMCPStreamableHTTPSessionManager <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L43" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>Session manager that scopes resumability storage per transport session.
Methods:
event_store <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L68" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>event_store(self) -> EventStore | None
event_store <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L76" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>event_store(self, event_store: EventStore | None) -> None
StreamableHTTPASGIApp <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L80" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>ASGI application wrapper for Streamable HTTP server transport.
HostOriginGuardMiddleware <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L227" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>Validate Host and Origin headers before requests reach MCP sessions.
StarletteWithLifespan <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L348" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>Methods:
lifespan <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L350" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>lifespan(self) -> Lifespan[Starlette]
RequestContextMiddleware <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/http.py#L363" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>Middleware that stores each request in a ContextVar and sets transport type.