feat(tool): forward LLM tool-call id to MCP servers via _meta#158
Open
alenkacz wants to merge 1 commit into
Open
feat(tool): forward LLM tool-call id to MCP servers via _meta#158alenkacz wants to merge 1 commit into
alenkacz wants to merge 1 commit into
Conversation
The Registry now carries the originating LLM tool-call id (llm.ToolRequestPart.ID) on the execution context (tool.WithCallID / tool.CallIDFromContext), and the MCP client forwards it to the server in the tools/call request _meta under the domain-namespaced key "redpanda.com/llm-tool-call-id" (exported as mcp.MetaKeyLLMToolCallID). This lets a gateway or observability layer read the id off the wire and stamp gen_ai.tool.call.id on its tool-execution span, tying the tool call back to the specific model turn that requested it. _meta is the MCP protocol's sanctioned extensibility slot, so servers that don't understand the key simply ignore it and the tool's own arguments are untouched. No behavior change when the context carries no id: the _meta key is omitted. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Found 1 test failure on Blacksmith runners: Failure
|
weeco
approved these changes
Jun 22, 2026
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.
What
Threads the originating LLM tool-call id (
llm.ToolRequestPart.ID) from the agent loop down to the MCP server on everytools/call:tool.WithCallID/tool.CallIDFromContext— new context helpers (tool/callid.go).Registry.Executestashesreq.IDon the execution context immediately before invoking a tool (tool/registry.go). Harmless for tools that ignore it.tools/callrequest_metaunder the domain-namespaced keyredpanda.com/llm-tool-call-id, exported asmcp.MetaKeyLLMToolCallID(tool/mcp/tools.go).Why
Today, when an agent runs LLM and MCP calls through a gateway (e.g. Redpanda's
aigw), the gateway's MCP tool-execution span carries the tool name but not the which-tool-call id, so it can't be tied back to the specific model turn that requested it — only grouped by conversation. Forwarding the id lets the gateway stampgen_ai.tool.call.idon its span, enabling a precise tool-use ↔ invocation join (and lets the transcripts consumer dedup the gateway span against the in-agentexecute_toolspan byconversation + tool.call.id)._metais the MCP protocol's sanctioned extensibility slot: servers that don't understand the key ignore it, and the tool's ownargumentsare never touched. When the context carries no id (e.g. a directExecuteToolcall outside the registry), the_metakey is simply omitted — no behavior change.Tests
TestWithCallIDRoundTrip,TestRegistryExecuteExposesToolCallID— context plumbing.TestExecuteToolForwardsLLMToolCallID— asserts the id reaches the server in_metawhen present, and is absent when the context carries none.Consumer side (separate, in cloudv2)
The matching
aigwchange (readparams._meta→ stampgen_ai.tool.call.idon the MCP span) is a follow-up in the cloudv2 repo; this PR is the producer half and is a no-op until that lands.🤖 Generated with Claude Code