You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): populate RequestMetadata.request_context on the A2A path (MCP parity) #1008
RequestMetadata carries a request_context field documented as the way a context_factory reads request-scoped state set by middleware. The MCP path populates it; the A2A path does not, so a context_factory on A2A cannot see the incoming request at all.
Verified against 6.6.0 and v7.0.0-rc (the module is byte-identical between the two): a factory receiving meta sees request_context is None on every A2A request.
Impact. Any header-derived context is unreachable through the documented seam on A2A — deployment-specific auth headers, tenant hints, and test-mode headers alike. The available workaround is a ContextVar populated by an outer ASGI middleware and read inside the factory. That does work on A2A today (dispatch runs in the same asyncio task as the middleware, as auth.py:1449-1456 notes), but it is fragile by the SDK's own caveat there: it breaks if A2A ever grows a decoupled dispatch task. Adopters shouldn't have to depend on that coupling when the field already exists.
Proposed change. Thread the Starlette Request (or the ServerCallContext carrying it) into RequestMetadata at a2a_server.py:381-385, matching the MCP path.
Unrelated docs nit, same area: the docstring at a2a_server.py:1022-1028 states that PushNotificationConfigStore "does not pass a ServerCallContext" to set_info/get_info/delete_info and recommends a ContextVar workaround. Against the installed a2a-sdk==1.0.1 all three methods do take context: ServerCallContext, so the workaround is unnecessary and the advice misleads adopters into weaker scoping than the ABC supports.
code-reviewer: Both items confirmed. ServerCallContext does not carry a Starlette Request, so Item 1 requires a new ContextVar set in the A2A ASGI middleware (same populate-and-reset-in-finally pattern as current_principal at auth.py:1457-1464). Item 2 is independently confirmed by the live SDK and by examples/a2a_db_tasks.py, which already declares the correct context: ServerCallContext signatures — the docstring is wrong, not the reference impl.
dx-expert: Item 1 is high urgency — the silent-failure mode (factory guards with if request_context is not None:, falls through to ContextVars, no exception raised) makes the bug nearly invisible; and the existing auth.py comment at line 1454-1456 explicitly anticipates this exact fix. Item 2 actively routes adopters into a ContextVar workaround that has a documented background-task notification-loss race, when context: ServerCallContext is already available.
My take: Both are confirmed, non-breaking, and should ship together since they overlap in file scope.
Implementation scope:
src/adcp/server/serve.py — add (or repurpose) a cross-transport ContextVar for the Starlette Request
src/adcp/server/auth.py — set it from the A2A ASGI middleware, matching the current_principal pattern
src/adcp/server/a2a_server.py:381-385 — read ContextVar and pass as request_context=; do not pass request.call_context directly (ServerCallContext has no Request field); also fix the wrong docstring at line 1022-1028
examples/a2a_db_tasks.py — remove the same wrong PushNotificationConfigStore claim from the class docstring
Add a test verifying meta.request_context is not None when a context_factory is invoked via A2A
Activity
bokelley commentedon Jul 31, 2026
Triage
Thanks for filing!
Classification: Bug (Item 1) + Docs (Item 2)
Bucket(s): handlers, docs
Status: ready-to-implement
What the experts said:
ServerCallContextdoes not carry a StarletteRequest, so Item 1 requires a new ContextVar set in the A2A ASGI middleware (same populate-and-reset-in-finally pattern ascurrent_principalatauth.py:1457-1464). Item 2 is independently confirmed by the live SDK and byexamples/a2a_db_tasks.py, which already declares the correctcontext: ServerCallContextsignatures — the docstring is wrong, not the reference impl.if request_context is not None:, falls through to ContextVars, no exception raised) makes the bug nearly invisible; and the existing auth.py comment at line 1454-1456 explicitly anticipates this exact fix. Item 2 actively routes adopters into a ContextVar workaround that has a documented background-task notification-loss race, whencontext: ServerCallContextis already available.My take: Both are confirmed, non-breaking, and should ship together since they overlap in file scope.
Implementation scope:
src/adcp/server/serve.py— add (or repurpose) a cross-transport ContextVar for the StarletteRequestsrc/adcp/server/auth.py— set it from the A2A ASGI middleware, matching thecurrent_principalpatternsrc/adcp/server/a2a_server.py:381-385— read ContextVar and pass asrequest_context=; do not passrequest.call_contextdirectly (ServerCallContexthas noRequestfield); also fix the wrong docstring at line 1022-1028examples/a2a_db_tasks.py— remove the same wrongPushNotificationConfigStoreclaim from the class docstringmeta.request_context is not Nonewhen acontext_factoryis invoked via A2Apytest tests/ -m 'not integration',mypy src/,ruff check .Triaged by Claude Code. Session: https://claude.ai/code/cse_012M54t669NicKWBAyiozFLZ
Generated by Claude Code