Spaces:
Running on CPU Upgrade

lighting-mvp / app /request_context.py
DanielKretschmer's picture
WonderAnaconda
Lighting MVP
427634d
Raw History Blame Contribute Delete
552 Bytes
"""Per-request context shared between the access-gate middleware and the
mounted MCP server.
The middleware authenticates every request (cookie or bearer token) and stows
the resolved user here; MCP tools — which run inside the mounted Streamable
HTTP sub-app and don't see FastAPI's ``request.state`` directly — read it back
to act as the authenticated operator.
"""
from __future__ import annotations
from contextvars import ContextVar
from typing import Any
current_user_ctx: ContextVar[Any | None] = ContextVar("current_user", default=None)