Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

always apply request context middleware

Jeremiah Lowin13d33996df08
diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.py
index 2c09da879..29556f29a 100644
--- a/src/fastmcp/server/server.py
+++ b/src/fastmcp/server/server.py
@@ -728,7 +728,7 @@ class FastMCP(Generic[LifespanResultT]):
# timeout to make it possible to close immediately. see
# https://github.com/jlowin/fastmcp/issues/296
uvicorn_config.setdefault("timeout_graceful_shutdown", 0)
- app = RequestContextMiddleware(self.sse_app())
+ app = self.sse_app()
config = uvicorn.Config(
app,
@@ -837,6 +837,8 @@ class FastMCP(Generic[LifespanResultT]):
# mount these routes last, so they have the lowest route matching precedence
routes.extend(self._custom_starlette_routes)
+ middleware.append(Middleware(RequestContextMiddleware))
+
# Create Starlette app with routes and middleware
return Starlette(
debug=self.settings.debug, routes=routes, middleware=middleware