π The fast, Pythonic way to build MCP servers and clients.
feat: Move the Starlette context middleware to the front (#1812)
akkumaned0931de8e9d
diff --git a/src/fastmcp/server/http.py b/src/fastmcp/server/http.pyindex 72d64a93e..a842f0248 100644--- a/src/fastmcp/server/http.py+++ b/src/fastmcp/server/http.py@@ -3,7 +3,7 @@ from __future__ import annotationsfrom collections.abc import AsyncGenerator, Callable, Generatorfrom contextlib import asynccontextmanager, contextmanagerfrom contextvars import ContextVar-from typing import TYPE_CHECKING+from typing import TYPE_CHECKING, Unionfrom mcp.server.auth.middleware.bearer_auth import RequireAuthMiddlewarefrom mcp.server.lowlevel.server import LifespanResultT@@ -113,7 +113,7 @@ def create_base_app(A Starlette application"""# Always add RequestContextMiddleware as the outermost middleware- middleware.append(Middleware(RequestContextMiddleware))+ middleware.insert(0, Middleware(RequestContextMiddleware))return StarletteWithLifespan(routes=routes,