Skip to content

fix(adk): Propagate access token to subagents and mcp tools#1858

Merged
jmhbh merged 13 commits into
kagent-dev:mainfrom
jmhbh:fix/a2a-authz-header-propagation
May 13, 2026
Merged

fix(adk): Propagate access token to subagents and mcp tools#1858
jmhbh merged 13 commits into
kagent-dev:mainfrom
jmhbh:fix/a2a-authz-header-propagation

Conversation

@jmhbh
Copy link
Copy Markdown
Contributor

@jmhbh jmhbh commented May 12, 2026

Overview

  • Fixes an issue where setting the KAGENT_PROPAGATE_TOKEN env var for Agent CR's using the python runtime would only propagate the access token to mcp tools and not to sub agents.
  • Fixes an issue where the setting the KAGENT_PROPAGATE_TOKEN env var for the go run would not propagate the token to mcp or subagents as it was unimplented.

Testing

  • Manually tested by deploying a coordinator agent and a subagent that uses the kagent-tool-server and making an a2a request to the coordinator agent then inspecting the logs. I added logs here and here for the go runtime and here for the python runtime to validate the allowed header was being added by the interceptor

closes #1745

… mcp tools for both the go and python adk runtimes

Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
@github-actions github-actions Bot added the bug Something isn't working label May 12, 2026
Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
@jmhbh jmhbh marked this pull request as ready for review May 12, 2026 22:49
Copilot AI review requested due to automatic review settings May 12, 2026 22:49
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels May 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses end-to-end auth token propagation when KAGENT_PROPAGATE_TOKEN is set, ensuring the incoming Authorization header is forwarded both to (1) sub-agent A2A calls and (2) downstream MCP tool calls, for both the Python and Go runtimes.

Changes:

  • Python: add optional Authorization forwarding to sub-agent A2A calls via _SubagentInterceptor and propagate the token from session state into the outbound ClientCallContext.
  • Go: implement token propagation for both remote sub-agent A2A tools and MCP transports when KAGENT_PROPAGATE_TOKEN is set.
  • Add unit tests in both runtimes covering the new propagation behaviors.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
python/packages/kagent-adk/src/kagent/adk/_remote_a2a_tool.py Adds propagate-token support to sub-agent A2A calls by passing Authorization through call context + interceptor.
python/packages/kagent-adk/tests/unittests/test_remote_a2a_tool.py Adds unit tests validating Authorization forwarding behavior in _SubagentInterceptor.
go/adk/pkg/agent/agent.go Plumbs KAGENT_PROPAGATE_TOKEN into MCP toolset creation and remote A2A tool construction.
go/adk/pkg/tools/remote_a2a_tool.go Adds an interceptor to forward Authorization from inbound A2A context into outbound sub-agent A2A calls.
go/adk/pkg/mcp/registry.go Adds propagateToken behavior to MCP transport header injection (Authorization forwarded independent of AllowedHeaders).
go/adk/pkg/mcp/registry_test.go Adds tests for propagateToken behavior on the MCP transport.
go/adk/pkg/constants/const.go Introduces a shared constant for normalized Authorization header name.
Comments suppressed due to low confidence (1)

python/packages/kagent-adk/src/kagent/adk/_remote_a2a_tool.py:414

  • In _handle_resume, the authorization context key is set using a hard-coded string ("authorization") instead of _AUTHORIZATION_CONTEXT_KEY. For consistency with _handle_first_call and the interceptor, use the constant here as well.
        call_context_state: dict[str, Any] = {_USER_ID_CONTEXT_KEY: tool_context.session.user_id}
        if self._propagate_token:
            incoming = tool_context.session.state.get(_HEADERS_STATE_KEY) or {}
            if isinstance(incoming, dict):
                auth = incoming.get("authorization") or incoming.get("Authorization")
                if auth:
                    call_context_state["authorization"] = auth
        call_context = ClientCallContext(state=call_context_state)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread go/adk/pkg/tools/remote_a2a_tool.go
Comment thread go/adk/pkg/mcp/registry.go Outdated
Comment thread python/packages/kagent-adk/src/kagent/adk/_remote_a2a_tool.py Outdated
Comment thread python/packages/kagent-adk/src/kagent/adk/_remote_a2a_tool.py Outdated
Copy link
Copy Markdown
Contributor

@supreme-gg-gg supreme-gg-gg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm overall, I agree using KAGENT_PROPAGATE_TOKEN is a better and more consistent approach than the previous PR / #1757

Comment thread python/packages/kagent-adk/src/kagent/adk/_remote_a2a_tool.py Outdated
Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
Comment thread go/adk/pkg/mcp/registry.go
Comment thread python/packages/kagent-adk/src/kagent/adk/_remote_a2a_tool.py Outdated
iplay88keys
iplay88keys previously approved these changes May 13, 2026
Copy link
Copy Markdown
Contributor

@iplay88keys iplay88keys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Just a few small comments.

Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
Comment thread go/adk/pkg/agent/agent.go Outdated
Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
Copy link
Copy Markdown
Contributor

@EItanya EItanya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small comment

Comment thread go/adk/pkg/tools/remote_a2a_tool.go Outdated
jmhbh added 2 commits May 13, 2026 16:26
Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
@github-actions github-actions Bot removed the bug Something isn't working label May 13, 2026
@github-actions github-actions Bot added the bug Something isn't working label May 13, 2026
Comment thread python/packages/kagent-adk/src/kagent/adk/_remote_a2a_tool.py Outdated
jmhbh and others added 3 commits May 13, 2026 16:50
Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
iplay88keys
iplay88keys previously approved these changes May 13, 2026
@jmhbh jmhbh enabled auto-merge (squash) May 13, 2026 20:55
@jmhbh jmhbh disabled auto-merge May 13, 2026 20:58
@jmhbh jmhbh enabled auto-merge (squash) May 13, 2026 21:09
@jmhbh jmhbh disabled auto-merge May 13, 2026 21:11
… propagate_token bool

Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
@jmhbh jmhbh enabled auto-merge (squash) May 13, 2026 21:51
@jmhbh jmhbh merged commit ca90cdd into kagent-dev:main May 13, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] _SubagentInterceptor should forward Authorization header from parent session to sub-agent A2A calls

5 participants