Repository navigation
fix(mcp): prevent normalized tool collisions - #1259
Conversation
# Conflicts: # crates/jcode-harness-api-server/src/translate_tests.rs # crates/jcode-harness-api/src/lib.rs # sdk/typescript/src/protocol.ts
…ibutors-20260913 Welcome pull requests from all contributors
|
| let mut counts = std::collections::HashMap::<&str, usize>::new(); | ||
| for base in &bases { | ||
| *counts.entry(base).or_default() += 1; | ||
| } |
There was a problem hiding this comment.
Cached startup registration can assign an unsuffixed name when it sees only one member of a normalized collision. Live discovery then assigns suffixed names after it sees both members, but leaves the original cached key registered. The same MCP tool family is therefore exposed under three names, and the obsolete cached alias can continue advertising cached metadata instead of the refreshed definition. Remove obsolete MCP registry keys during refresh, or assign names from one stable set of server/tool identities.
Knowledge Base Used: Agent runtime and tool loop
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/mcp/tool.rs
Line: 125-128
Comment:
**Reconcile refresh aliases**
Cached startup registration can assign an unsuffixed name when it sees only one member of a normalized collision. Live discovery then assigns suffixed names after it sees both members, but leaves the original cached key registered. The same MCP tool family is therefore exposed under three names, and the obsolete cached alias can continue advertising cached metadata instead of the refreshed definition. Remove obsolete MCP registry keys during refresh, or assign names from one stable set of server/tool identities.
**Knowledge Base Used:** [Agent runtime and tool loop](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/agent-runtime-and-tool-loop.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let suffix = format!("__{:08x}", stable_dispatch_hash(server, &tool.name)); | ||
| let mut candidate = format!("{base}{suffix}"); | ||
| let mut counter = 2u32; | ||
| while !used.insert(candidate.clone()) { | ||
| candidate = format!("{base}{suffix}_{counter}"); | ||
| counter = counter.saturating_add(1); | ||
| } | ||
| names[index] = candidate; |
There was a problem hiding this comment.
For normalized MCP-name collisions, eager registration and execution use generated suffixed aliases, but session allow/deny entries continue to match the historical unsuffixed name. A deny entry for the configured MCP capability therefore does not match either eager collision alias, allowing that external capability to execute despite being disabled. Resolve policy entries and generated aliases through the same MCP identity.
How this was verified: A session deny for the unsuffixed name allowed a suffixed collision alias to invoke the test external capability.
Knowledge Base Used:
Artifacts
- The complete regression test creates the normalized collision, applies the historical deny entry, and invokes the generated alias.
- The output records exit code 0 and `test tool::tests::unsuffixed_mcp_deny_does_not_block_a_suffixed_collision_alias ... ok`, showing that the denied capability executed through the suffixed alias.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/mcp/tool.rs
Line: 148-155
Comment:
**Match policies to aliases**
For normalized MCP-name collisions, eager registration and execution use generated suffixed aliases, but session allow/deny entries continue to match the historical unsuffixed name. A deny entry for the configured MCP capability therefore does not match either eager collision alias, allowing that external capability to execute despite being disabled. Resolve policy entries and generated aliases through the same MCP identity.
**How this was verified:** A session deny for the unsuffixed name allowed a suffixed collision alias to invoke the test external capability.
**Knowledge Base Used:**
- [Agent runtime and tool loop](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/agent-runtime-and-tool-loop.md)
- [Agent execution and tooling](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/agent-execution-and-tooling.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.795fd91 to
beeb0e2
Compare
|
Merged into master with review follow-ups in bcb6686 and real stdio coverage in c01aab7. Beyond collision-resistant names, integration now reconciles aliases by original MCP identity, removes stale live entries while retaining failed-server cached proxies, keeps legacy/alias deny policy consistent across eager/deferred routes and membership changes, honors legacy allowlists, and disconnects exact servers. Manual connect/list output uses actual aliases. The combined candidate passed 58 base MCP and 27 app-core MCP tests plus actual subprocess stdio coverage for eager/cache/reversed/partial discovery, dispatch identity, and management lifecycle. Integrated with original PR ancestry and contributor attribution preserved, applying only the actual contribution rather than the divergent old upstream tree. Validation is local targeted testing and isolated public-interface acceptance, not a claim that hosted CI is green. |
Summary
Prevent normalized MCP tool names from colliding at provider boundaries while preserving the original server-qualified dispatch identity.
Changes
Validation
git diff --check upstream/master...HEADupstream/mastercompleted successfully.Refs #972