Skip to content

Commit c0183be

Browse files
committed
fix: get http headers by calling get_http_headers instead of context that may be unavailable
Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
1 parent 4393e1e commit c0183be

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

ex_app/lib/mcp_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from fastmcp.server.dependencies import get_context
99
from nc_py_api import AsyncNextcloudApp, NextcloudApp
1010
from fastmcp.server.middleware import Middleware, MiddlewareContext, CallNext
11+
from fastmcp.server.dependencies import get_http_headers
1112
from fastmcp.tools import Tool
1213
from mcp import types as mt
1314
from ex_app.lib.tools import get_tools
@@ -30,7 +31,7 @@ def get_user(authorization_header: str, nc: AsyncNextcloudApp) -> str:
3031
class UserAuthMiddleware(Middleware):
3132
async def on_message(self, context: MiddlewareContext, call_next):
3233
# Middleware stores user info in context state
33-
authorization_header = context.fastmcp_context.request_context.request.headers.get("Authorization")
34+
authorization_header = get_http_headers().get("authorization")
3435
if authorization_header is None:
3536
raise Exception("Authorization header is missing/invalid")
3637
nc = AsyncNextcloudApp()

0 commit comments

Comments
 (0)