Skip to content

fix(server): populate RequestMetadata.request_context on the A2A path (MCP parity) #1008

Closed

Description

@numarasSigmaSoftware

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.

# adcp/server/serve.py — MCP path populates it
2516:                request_context=request_context,

# adcp/server/a2a_server.py — A2A path omits it
381:        meta = RequestMetadata(
382:            tool_name=skill_name,
383:            transport="a2a",
384:            request_id=request.task_id,
385:        )
386:        ctx = self._context_factory(meta)

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.

Happy to open the PR for both.

Activity

  1. added
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Jul 31, 2026
  2. bokelley commented on Jul 31, 2026

    @bokelley
    Contributor

    Triage

    Thanks for filing!

    Classification: Bug (Item 1) + Docs (Item 2)
    Bucket(s): handlers, docs
    Status: ready-to-implement

    What the experts said:

    • 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
    • Checks: pytest tests/ -m 'not integration', mypy src/, ruff check .

    Triaged by Claude Code. Session: https://claude.ai/code/cse_012M54t669NicKWBAyiozFLZ


    Generated by Claude Code

  3. added
    bugSomething isn't working
    and removed
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions