Skip to content

[Feat]: passing call context to unauthenticated card modifier #657

Description

@cbugwadia32

Is your feature request related to a problem? Please describe.

We are wondering if support can be added for passing the call context to the regular agent card modifier, just as it is for the extended card modifier.

Describe the solution you'd like

Agent card modifiers should be given a second parameter for the call context, matching the signature of extended agent card modifiers.

Describe alternatives you've considered

We can construct our own Application and Adapter classes to override the get agent card endpoint handling, but this is cumbersome and hard to maintain.

Additional context

I guess we're also wondering if this is intentional - i.e. if agent cards should not depend on anything from the call context. In our case, we want to use part of the request URL (which is dynamic) as part of the url field in the response. Also, if we work to add support for this (like in #647), do we have to make the change backwards compatible and support modifiers that don't take in the call context (i.e. only have one parameter for the agent card to be modified)? I think anything goes as long as we're on the 0.X.Y versions (i.e. anything below 1.0), but just want to make sure.

As with #647 I am more than willing to lead development on this.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. self-assigned this
    on Feb 2, 2026
  2. added
    component: core
    on Feb 2, 2026
  3. rohityan commented on Feb 3, 2026

    @rohityan

    Hi @cbugwadia32 , We'll review this internally and get back to you with an update on its implementation status.

  4. removed their assignment
    on Feb 3, 2026
  5. mtsmyassin commented on Apr 17, 2026

    @mtsmyassin

    Suggested API

    Looking at the current card_modifier signature, extending it to optionally accept a ServerCallContext is a backwards-compatible change if we use inspect to detect the arity, or just overload with two signatures. The cleaner approach:

    Option A: Second-arg context with a default

    # src/a2a/server/apps/jsonrpc/jsonrpc_app.py (sketch)
    
    CardModifier = (
        Callable[[AgentCard], AgentCard] |
        Callable[[AgentCard, ServerCallContext | None], AgentCard]
    )
    
    def _apply_card_modifier(
        card: AgentCard,
        modifier: CardModifier | None,
        context: ServerCallContext | None,
    ) -> AgentCard:
        if modifier is None:
            return card
        sig = inspect.signature(modifier)
        if len(sig.parameters) >= 2:
            return modifier(card, context)  # type: ignore[call-arg]
        return modifier(card)  # type: ignore[call-arg]

    This lets existing single-arg modifiers keep working while new two-arg ones receive the call context.

    Option B: Single new signature (breaking)

    If you're OK with a major-version breaking change, just change the signature:

    CardModifier = Callable[[AgentCard, ServerCallContext | None], AgentCard]

    Users who don't need the context just ignore the second arg. This is cleaner long-term but requires updating every existing modifier.

    Where to plumb context in

    The card modifier is called from the .well-known/agent-card handler. That route currently doesn't build a ServerCallContext at all — it's a pure GET that sidesteps the normal request-handler machinery. So the fix needs two parts:

    1. Have the card endpoint build a ServerCallContext from request headers (at minimum user if an auth middleware populated it, plus request_headers).
      1. Pass that context into the card modifier.

    Motivating use case

    Per-user feature flags, regional URLs, or auth-state-dependent skills — e.g. hide skills.premium.* for free-tier callers based on a JWT claim. All of these are impossible today without a fork.

    Related

    This ties into #445 (client auth handling) and #281/#168 (trace context propagation) — they're all symptoms of the same gap: the .well-known/agent-card endpoint is disconnected from the main request pipeline. Might be worth a single PR that introduces a CardRequestContext and uses it in all three places.

    I can prep a PR with Option A if that's the preferred direction.

  6. ishymko commented on May 27, 2026

    @ishymko
    Member

    Hey @cbugwadia32, I am afraid ServerCallContext does not fit that well into a well-known agent card endpoint (i.e. tenant and user).

    Could you please expand a bit more on your use-case with dynamic URLs? Also worth mentioning that with modular routing in 1.0 SDK you can have fully custom handler for a well-known path only which is quite trivial: agent_card_routes.py.

    Other examples from the "Motivating use case" section from the above comment by @mtsmyassin actually belong to extended agent card which takes user context into account by design (see 3.1.11. Get Extended Agent Card).

  7. added
    question
    and removed on May 27, 2026
  8. DanCardin commented on May 27, 2026

    @DanCardin

    I started following this PR because our agent is accessible from at least 2 urls (publicly and internally to avoid clients hitting the internet). As of today, I have a big hack of a workaround to get the request context injected into the handler so that I can use the x-forwarded headers to reconstruct the base url of the incoming request

  9. added and removed
    question
    on May 28, 2026
  10. cbugwadia32 commented on Jun 1, 2026

    @cbugwadia32
    ContributorAuthor

    @ishymko - our use case is that the URL of the agent (which is part of the agent card) depends on the path to the agent card itself, e.g. if the public agent card is accessed at /agent/id123456/.well-known/agent-card.json then I want the response to include /agent/id123456 in the URL. If the v1 offering lets us achieve this somehow then we're good with that.

  11. github-actions commented on Jun 16, 2026

    @github-actions

    Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

  12. github-actions commented on Jun 29, 2026

    @github-actions

    This issue was closed because it has been inactive for 27 days. Please post a new issue if you need further assistance. Thanks!

  13. self-assigned this
    on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

component: core

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions