Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107---title: httpsidebarTitle: http---
# `fastmcp.server.http`
## Functions
### `set_http_request` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/http.py#L77" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonset_http_request(request: Request) -> Generator[Request, None, None]```
### `create_base_app` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/http.py#L110" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoncreate_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 app- `middleware`: List of middleware to include in the app- `debug`: Whether to enable debug mode- `lifespan`: Optional lifespan manager for the app
**Returns:**- A Starlette application
### `create_sse_app` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/http.py#L138" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoncreate_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 instance- `message_path`: Path for SSE messages- `sse_path`: Path for SSE connections- `auth`: Optional authentication provider (AuthProvider)- `debug`: Whether to enable debug mode- `routes`: Optional list of custom routes- `middleware`: Optional list of middleware
Returns: A Starlette application with RequestContextMiddleware
### `create_streamable_http_app` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/http.py#L265" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoncreate_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) -> StarletteWithLifespan```
Return an instance of the StreamableHTTP server app.
**Args:**- `server`: The FastMCP server instance- `streamable_http_path`: Path for StreamableHTTP connections- `event_store`: Optional event store for SSE polling/resumability- `retry_interval`: Optional retry interval in milliseconds for SSE polling.Controls how quickly clients should reconnect after server-initiateddisconnections. Requires event_store to be set. Defaults to SDK default.- `auth`: Optional authentication provider (AuthProvider)- `json_response`: Whether to use JSON response format- `stateless_http`: Whether to use stateless mode (new transport per request)- `debug`: Whether to enable debug mode- `routes`: Optional list of custom routes- `middleware`: Optional list of middleware
**Returns:**- A Starlette application with StreamableHTTP support
## Classes
### `StreamableHTTPASGIApp` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/http.py#L32" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
ASGI application wrapper for Streamable HTTP server transport.
### `StarletteWithLifespan` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/http.py#L70" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
**Methods:**
#### `lifespan` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/http.py#L72" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlifespan(self) -> Lifespan[Starlette]```
### `RequestContextMiddleware` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/http.py#L85" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Middleware that stores each request in a ContextVar and sets transport type.