Skip to content

fix(agent-core): disambiguate MCP tools with colliding names across s…#665

Open
LifeJiggy wants to merge 6 commits into
MoonshotAI:mainfrom
LifeJiggy:fix/mcp-tool-name-collision
Open

fix(agent-core): disambiguate MCP tools with colliding names across s…#665
LifeJiggy wants to merge 6 commits into
MoonshotAI:mainfrom
LifeJiggy:fix/mcp-tool-name-collision

Conversation

@LifeJiggy

@LifeJiggy LifeJiggy commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Instead of dropping the second server's tool when two MCP servers expose tools with the same name, append a numeric suffix (__2, __3) so both tools remain accessible. This fixes #575.

Enhancements:

  • Track collision count across registrations for incrementing suffixes
  • Updated collision error message to mention disambiguation
  • Both original and disambiguated tools are callable independently

Tests:

  • Cross-server collision disambiguation with suffix assignment
  • Multiple collisions get incrementing suffixes
  • Both tools callable independently via loopTools
  • Collision results contain disambiguation details

Related Issue
Resolve #575

Problem
When multiple MCP servers expose tools with the same name (e.g., both have read_node), the second server's tool was silently dropped. Only one server's tool was accessible, making it impossible to use overlapping MCP servers simultaneously.

What changed
Instead of dropping colliding tools, the ToolManager now disambiguates them by appending a numeric suffix (__2, __3) to the qualified name. Both tools remain registered and callable.

  • registerMcpServer() now tracks collision counts across registrations and appends __N suffixes for cross-server collisions (same-server collisions still drop the duplicate)
  • Updated collision error message to mention disambiguation instead of "losing tools were dropped"
  • trimTrailingOpenToolExchange fix was moved to a separate branch/PR

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill.
  • Ran gen-docs skill, or this PR needs no doc update.

…ervers

Instead of dropping the second server's tool when two MCP servers expose
tools with the same name, append a numeric suffix (__2, __3) so both
tools remain accessible. This fixes MoonshotAI#575.

Enhancements:
- Track collision count across registrations for incrementing suffixes
- Updated collision error message to mention disambiguation
- Both original and disambiguated tools are callable independently

Tests:
- Cross-server collision disambiguation with suffix assignment
- Multiple collisions get incrementing suffixes
- Both tools callable independently via loopTools
- Collision results contain disambiguation details
@changeset-bot

changeset-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c159bf2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…angeset

- Use executeTool helper instead of direct resolveExecution().execute()
  to handle Promise<ToolExecution> return type
- Add changeset for agent-core and kimi-code patch bumps
…QUALIFIED_LENGTH

When a disambiguated name (base + __N suffix) would exceed the 64-char
limit enforced by LLM providers, truncate the base name to fit. This
prevents API errors from providers that reject tool names over 64 chars.

Also added test verifying the length constraint is respected.
@LifeJiggy LifeJiggy marked this pull request as ready for review June 11, 2026 18:45
@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@c159bf2
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c159bf2

commit: c159bf2

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e1c2379f5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/agent/tool/index.ts Outdated
…sambiguation

When truncating a disambiguated name to fit MAX_QUALIFIED_LENGTH, the
resulting name might already be registered by another tool. Now probes
by incrementing the suffix count until a unique name is found.

Fixes P2 from Codex review: two long colliding names could truncate to
the same prefix+suffix, causing the latter to silently overwrite the
former.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfc73e2a22

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/agent/tool/index.ts
When a server re-registers after a reconnect, reset the collision count
for its base tool names so the disambiguated suffix numbers stay stable.
This prevents saved approvals, pending tool references, and model context
from becoming stale after normal reconnect flows.

Also fixes typecheck error by rewriting the probing test to use only
public API (no direct access to protected mcpTools map).
@LifeJiggy

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71bbcbbf51

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/agent/tool/index.ts Outdated
…ambiguation

When a server has same-server tool name duplicates AND the base name
collides with another server, the duplicate check must use the base
name (before suffix), not the disambiguated name. Otherwise the second
same-server duplicate slips through with a different suffix instead of
being reported as a same-server collision.
@LifeJiggy

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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.

MCP tools with identical names across multiple servers silently overwrite each other — only the last-loaded server wins

1 participant