refactor(signing): thread signingContext via AsyncLocalStorage#615
Merged
Conversation
Flattens the signingContext parameter that #593 pushed through nine function signatures in the MCP and A2A transports. Top-level entries (callMCPTool, callMCPToolRaw, callMCPToolWithTasks, callA2ATool) push the context onto a new signingContextStorage ALS for the duration of the call; internal helpers read it from storage instead of receiving it as a parameter. Public entry-point signatures are unchanged, so external callers and integration tests continue to pass signingContext explicitly. The cache-key disambiguator still encodes the signing fingerprint so cached transports can't be reused across signing identities. Adds tests for interleaved concurrent callTool invocations with distinct signing identities and for the no-leak property of sequential signing/non-signing calls in the same async chain. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses reviewer feedback on #615: - Note that ProtocolClient.callTool's explicit signingContext arg is the seed for each transport's signingContextStorage.run, not incidental plumbing. - Document that task lifecycle methods (tasks/get, tasks/result, tasks/list, tasks/cancel) are MCP protocol methods, not AdCP ops, so extractAdcpOperation returns undefined and the signing fetch passes them through unsigned regardless of ALS state. - Note that callMCPToolWithOAuth consumes signingContext via the transport (connectMCP attaches the signing-fetch wrapper at creation time) rather than via ALS, because OAuth connections are not pooled. No behavior change — comments only. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #597.
Summary
signingContextStorage(AsyncLocalStorage<AgentSigningContext | undefined>) alongside the existing capability cache helpers insrc/lib/signing/agent-context.ts.callMCPTool,callMCPToolRaw,callMCPToolWithTasks,callA2ATool) now wrap their implementations insigningContextStorage.run(signingContext, ...)so the internal helpers can read the context from storage instead of receiving it as a parameter.signingContextparameter from the internal plumbing —withCachedConnection,getOrCreateConnection,connectMCPWithFallback,connectMCPWithFallbackImpl,callMCPToolImpl,callMCPToolRawImpl,getOrCreateA2AClient,createA2AClient,buildFetchImpl. Each now readssigningContextStorage.getStore()at the point it needs the context (cache-key build, fetch-wrapper build).ProtocolClient.callTool,callMCPToolWithOAuth,connectMCP, and the top-level MCP / A2A helpers still accept an explicitsigningContext, per the issue's non-goal.buildFetchImplcaptures the context at client-creation time; the A2A client cache is already keyed per signing-fingerprint, so different signing identities get different cached clients and build their own fetch wrappers in separate ALS scopes.ALS.run(context)— including withundefined— so non-signing calls cannot inherit a stale context from an enclosing scope.Test plan
test/request-signing-agent-integration.test.js(all 12 prior tests) — passes unmodified.ProtocolClient.callTools against the same seller URL with two distinct signing identities (Ed25519 + ES256) — each inbound request'sSignature-Inputcarries its ownkeyid, proving no cross-contamination.Signature-Input, proving the ALS scope is released when the first call resolves.main.🤖 Generated with Claude Code