"""Helpers for accessing the request-scoped MCP user/token from inside tools."""

from __future__ import annotations

from fastmcp.server.context import Context

from .auth import STATE_KEY_CLAIMS, STATE_KEY_TOKEN, STATE_KEY_USER


async def get_mcp_user(ctx: Context | None):
    if ctx is None:
        return None
    return await ctx.get_state(STATE_KEY_USER)


async def get_mcp_token(ctx: Context | None):
    if ctx is None:
        return None
    return await ctx.get_state(STATE_KEY_TOKEN)


async def get_mcp_claims(ctx: Context | None) -> dict | None:
    """Return the JWT claims dict for this request, or None for opaque-token callers."""
    if ctx is None:
        return None
    return await ctx.get_state(STATE_KEY_CLAIMS)
