Skip to content

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
mainfrom
fix/ato-1365-mcp-wire-name
Draft

sosidudku1 wants to merge 2 commits into
mainfrom
fix/ato-1365-mcp-wire-name

Conversation

@sosidudku1

@sosidudku1 sosidudku1 commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What

Tool names go to OpenAI-compatible providers with dots escaped as __. That mapping is not one-to-one: an MCP tool mcp.srv.foo__bar and its sibling mcp.srv.foo.bar both became mcp__srv__foo__bar. The reply was decoded back as mcp.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, _3 suffix). 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 toolWireNames on 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

  • A suffix can push a wire name past 64 characters (plain names were not truncated before either).

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: native tool_calls and 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.

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant