Merge pull request #357 from jlowin/middleware

Always apply request context middleware
This commit is contained in:
Jeremiah Lowin 2025-05-07 10:06:19 -04:00 committed by GitHub
commit 17ec430095
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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