fix(invoke): add bearer-token support to the A2A invoke path for CUSTOM_JWT (#815)#1647
Draft
aidandaly24 wants to merge 3 commits into
Draft
fix(invoke): add bearer-token support to the A2A invoke path for CUSTOM_JWT (#815)#1647aidandaly24 wants to merge 3 commits into
aidandaly24 wants to merge 3 commits into
Conversation
…M_JWT runtimes A2A-protocol agents configured with CUSTOM_JWT authorization could not be invoked: the CLI auto-fetched a bearer token but invokeA2ARuntime always used the SigV4 client, dropping the token and triggering an "Authorization method mismatch" service error. Add bearerToken support to A2AInvokeOptions and, when set, send a raw HTTP POST of the JSON-RPC body with an Authorization: Bearer header via buildInvokeUrl / buildBearerInvokeHeaders, parsing the response through parseA2AResponse. Thread the token through all three call sites (invoke action, TUI invoke flow, dev web-UI invocations handler). Fixes aws#815
Contributor
Package TarballHow to installgh release download pr-1647-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.21.0.tgz |
Contributor
|
Claude Security Review: no high-confidence findings. (run) |
Contributor
|
Claude Security Review: no high-confidence findings. (run) |
agentcore-cli-automation
approved these changes
Jun 26, 2026
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Looks good to merge.
The fix mirrors the existing invokeWithBearerTokenStreaming pattern correctly:
buildInvokeUrl+buildBearerInvokeHeadersare reused — no logic duplication.- The bearer branch is gated on
options.bearerTokenand the SigV4 path is left untouched as a fallback. - All three call sites (
action.ts,invocations.ts,useInvokeFlow.ts) are updated, andresolveInvokeTargetalready auto-fetches the token upstream for the CLI/TUI paths, so existing CUSTOM_JWT users get the fix transparently.
Tests are appropriately scoped — mocking only at the true I/O boundaries (@aws-sdk/client-bedrock-agentcore and globalThis.fetch) and asserting both the bearer path and the SigV4 fallback. No excessive mocking.
No new telemetry is needed since InvokeAttrs already captures auth_type (src/cli/telemetry/schemas/command-run.ts:138).
Contributor
|
Claude Security Review: no high-confidence findings. (run) |
agentcore-cli-automation
approved these changes
Jun 26, 2026
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Looks good to merge.
The fix is correct and minimal:
- The bearer branch is properly gated on
options.bearerTokenininvokeA2ARuntime(agentcore.ts:960-977) and the SigV4 path is left intact as the fallback. The bearer code reusesbuildInvokeUrlandbuildBearerInvokeHeaders, mirroringinvokeWithBearerTokenStreamingandmcpRpcCallWithBearer— this also resolves the TODO at agentcore.ts:708. - All three A2A call sites are threaded:
action.ts:596,useInvokeFlow.ts:786, andinvocations.ts:463/559(via the newbearerTokenfield onDeployedInvokeParams).resolveInvokeTargetauto-fetches the token for CUSTOM_JWT agents upstream, so existing users get the fix transparently. - Response handling stays symmetric with the SigV4 path: a single
res.text()fed throughparseA2AResponseand wrapped insingleValueStream. The bearer path additionally surfaces the runtime session id from the response headers, which is a small bonus. - Tests mock only at true I/O boundaries (the
@aws-sdk/client-bedrock-agentcoreSDK client andglobalThis.fetch) and assert both the bearer path (Authorization header, JSON-RPC body shape, no SDK call) and the SigV4 fallback (no fetch call, SDK invoked). No excessive mocking, and the pattern matchesagentcore-mcp-bearer.test.ts. - No new telemetry is needed:
InvokeAttrs.auth_type(command-run.ts:138) is already derived fromoptions.bearerTokeninbuildInvokeAttrs(invoke/utils.ts:29), so the A2A+JWT path will be reported asbearer_tokenautomatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
#815 — A2A invoke does not support CUSTOM_JWT authentication
An A2A-protocol agent configured with CUSTOM_JWT authorization cannot be invoked. The CLI auto-fetches a bearer token but silently drops it on the A2A path, falling back to SigV4, so every invoke fails with a confusing "Authorization method mismatch" service error. There is no workaround other than a code change, and no add-time warning. Affects CLI invoke, the TUI, and the dev web-UI.
Fix
Add bearer-token support to the A2A invoke path, mirroring HTTP. (1) Add
bearerToken?: string;to A2AInvokeOptions (agentcore.ts:926-934). (2) In invokeA2ARuntime (agentcore.ts:942), when options.bearerToken is set, send a raw HTTP POST of the JSON-RPC body with Authorization: Bearer via buildInvokeUrl/buildBearerInvokeHeaders (agentcore.ts:201-233) instead of the SigV4 createAgentCoreClient + InvokeAgentRuntimeCommand, then parse the response through the existing parseA2AResponse. A2A uses the same InvokeAgentRuntime data plane and /runtimes/{arn}/invocations endpoint as HTTP, which already supports bearer auth, so this is sound. (3) Pass the token at the three call sites: bearerToken: options.bearerToken at action.ts:592-601, bearerToken: bearerToken || undefined at useInvokeFlow.ts:782-792, and thread bearerToken through DeployedInvokeParams to the A2A dispatch and handler at invocations.ts:456-463 / 552-560. Minimal-effort fallback only if the service truly rejects CUSTOM_JWT for A2A: add a fail-loud guard at the top of invokeA2ARuntime like AGUI's (agentcore.ts:1080-1082), or reject A2A+CUSTOM_JWT in validate.ts:319-335 — but the full fix is preferred.This fix was produced by an automated triage+fix run and validated locally (build + unit suite + symptom reproduction). It is being opened as a draft for CI and human review.
Related Issue
Closes #815
Documentation PR
N/A — bug fix; no devguide change required.
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typechecknpm run lintsrc/assets/, I rannpm run test:update-snapshotsand committed the updated snapshots — N/A, nosrc/assets/changesChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.