Repository navigation
fix(llm): run the tool the model named when two MCP tool names escape the same way - #1136
Draft
sosidudku1 wants to merge 2 commits into
Draft
sosidudku1 wants to merge 2 commits into
sosidudku1 wants to merge 2 commits into
Conversation
…p (ATO-1365) nameEscape is not injective: mcp.srv.foo__bar and mcp.srv.foo.bar both escape to mcp__srv__foo__bar, and nameUnescape read it back as the dotted sibling, so a call to the first tool ran the second. The OpenAI adapter now assigns each descriptor a distinct wire name (names that round-trip keep their plain escape; a colliding name gets a deterministic _2/_3 suffix) and exposes a wire-to-canonical map built in the same memoized pass. Step parsing feeds it into toolCallsToBatch and the content-array recovery paths; nameUnescape stays the fallback for names the request did not offer.
The native message history escaped past calls with plain nameEscape, so a past call to mcp.srv.foo__bar was written as mcp__srv__foo__bar, the wire name the same request offers for mcp.srv.foo.bar. A model copying it ran the sibling one turn later. The adapter now also reports the names it had to suffix. The step's stream params carry them as toolWireNames (only when non-empty), the link attempt forwards them, and the body builder names history tool_calls through them before falling back to the adapter escape. The post-repair parse also decoded against the full catalog instead of the descriptors the request was built from; it now uses stepDescriptors like the first parse, so the strict and wire-name maps match the wire.
This branch has not been deployed
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
Tool names go to OpenAI-compatible providers with dots escaped as
__. That mapping is not one-to-one: an MCP toolmcp.srv.foo__barand its siblingmcp.srv.foo.barboth becamemcp__srv__foo__bar. The reply was decoded back asmcp.srv.foo.bar, so a call to the first tool ran the second one. The second tool was also silently dropped from the request.Now each tool gets a distinct wire name for the request (names that round-trip keep their usual spelling; a colliding one gets a stable
_2,_3suffix). Replies are decoded through the request's own wire-to-tool map. The old text decoding stays as the fallback for names the request did not offer. The same map is used in the recovery paths that read tool calls from message content or reasoning text, and in the post-repair parse (which now uses the step's own descriptors, not the full catalog).Past tool calls in the message history are written with the same per-request wire names (carried as
toolWireNameson the request, never sent in the body), so a model copying an earlier call cannot pick the sibling either.Why
A model's call must run the tool it named, never a neighbour with a similar name.
Known gaps
Tests
openai-tool-call-adapter.test.ts: both tools offered; each wire name resolves to its own tool; order independence; fallback for unknown names; a suffix never steals a third tool's natural name; the strict wrapper passes the map through.step-parsing.test.ts: nativetool_callsand the content path.openai-build-body.test.ts: history names use the request's wire names; plain escape without a map.step-batch-lifecycle.test.ts: the repair parse decodes a suffixed name against the step descriptors.Fixes ATO-1365.
Not yet checked on the second Mac.