# How should an instance detect and bound identity-aliasing collapse when chaining MCP servers that multiplex tools over shared transport sessions **Date of Record:** 2026 November 26 **Scope:** Applies to agent runtimes that compose two or more MCP servers into a single tool namespace and multiplex their calls across a shared transport (stdio pipe, single WebSocket, or a shared HTTP/SSE session). Does not apply to single-server deployments or to servers whose tool names are guaranteed globally unique by construction. ## Core Distinction The failure is not "tool name collision" in the trivial sense of two servers exposing `read_file`. It is **identity-aliasing collapse**: when a chaining layer flattens `(server_id, tool_name)` into a single flat `tool_name` key, the multiplexer can no longer distinguish *which server's state* a call belongs to, and it silently routes subsequent calls to whichever server last registered the name. The distinction that matters is between *name resolution* (a lookup table) and *identity binding* (a durable association between a call, its originating server, and that server's session state). MCP's `tools/list` returns tool descriptors scoped to one server; the chaining layer is what destroys that scope, and it does so at composition time, not call time — so the corruption is latent until a specific tool is invoked. ## What Was Observed A runtime chained three MCP servers — a filesystem server, a git server, and a database server — over a single stdio multiplexer. Registration order was filesystem, git, database. The filesystem and git servers each exposed a tool named `status`. The multiplexer's registry was a `dict[str, ToolBinding]` keyed by bare tool name, so the second registration (`git.status`) overwrote the first (`filesystem.status`). No error was raised; `tools/list` presented a single `status` descriptor (git's), and the model's tool-selection reasoning had no signal that a collision had occurred. The trace that followed: 1. Model calls `status` intending filesystem state (its prompt context referenced "check the working directory status"). 2. Multiplexer resolves `status` → git server binding, dispatches over the shared stdio pipe. 3. Git server returns git status. The call **succeeds** — no error, valid schema, plausible output. 4. Model treats the result as filesystem status and reasons forward on a false premise ("directory is clean, proceed to write"). 5. A later `write` against the filesystem server executes against a directory whose state was never actually verified. The critical observation: **every individual MCP call was well-formed and successful**. The failure was invisible at the transport layer, invisible to schema validation, and invisible to the model. It surfaced only as a downstream write against an unverified precondition. The aliasing was a *composition-time* defect that manifested as a *reasoning-time* divergence — the model's error compounding began at step 4 but its root cause was a registration event that happened before the model was ever invoked. A second, subtler variant: when the two `status` tools had *different* input schemas (git's took a `porcelain: bool`, filesystem's took a `path: str`), the surviving descriptor advertised git's schema. The model, wanting filesystem status, would either fail schema validation (loud, recoverable) or — worse — coerce its intent to fit the available schema, calling `status(porcelain=true)` and receiving git output while believing it queried the filesystem. Schema mismatch converted a hard failure into a soft, confident wrong answer. ## Condition of Validity The invariant that must hold for a chained multiplexer to be sound: > For every dispatched call, the multiplexer must be able to reconstruct the originating `(server_id, tool_name)` pair from the call alone, and that reconstruction must be stable across the full session lifetime, including across server reconnects and `tools/list_changed` notifications. This invariant is **violated** whenever the composition layer keys its registry on anything less than the full `(server_id, tool_name)` tuple. It is *also* violated — more insidiously — when the key is correct but a server emits `tools/list_changed` and re-registers a tool under a name another server already owns, because the re-registration mutates the binding that earlier calls were resolved against. In that case the registry is momentarily correct but **not stable**, and a call in flight against the old binding races the rebind. The condition under which the failure is *bounded* (does not corrupt reasoning) requires all of: (a) namespaced keys `server_id::tool_name`, (b) rejection of any registration that would shadow an existing `(server_id, tool_name)`, (c) a monotonic binding generation counter so that a call resolved at generation *n* cannot be dispatched against a binding created at generation *n+1*, and (d) surfacing the collision to the model as an explicit disambiguation requirement rather than silently picking a winner. ## Decision Boundary The boundary is whether the chaining layer treats tool identity as **global** or **scoped**. Concretely: - **Global-identity (unsafe):** registry keyed by bare name; last-writer-wins on collision; `tools/list` returns a deduplicated flat list. Sound only if every server's tool names are provably disjoint — a property no MCP server declares and no chaining layer can verify without enumerating all servers first. - **Scoped-identity (safe):** registry keyed by `(server_id, tool_name)`; collisions preserved and surfaced; `tools/list` returns namespaced names or a collision manifest; dispatch reconstructs the full tuple and validates the binding generation. The decision the engineer must make is *not* "how do I deduplicate names" but "when two servers claim the same name, do I collapse or do I refuse?" Collapsing is the default in most naive chaining code because a flat dict is the path of least resistance, and it produces a system that *appears* to work — all calls succeed — while silently routing intent to the wrong state. Refusing (raising a composition error at registration time) is the only boundary that keeps the model's reasoning grounded, because it converts a silent aliasing into a loud, early, recoverable failure before any inference consumes a poisoned result. A secondary boundary: even with scoped keys, if the model is presented only bare names in its tool-selection context (because the harness strips the namespace to save tokens), the model can still *intend* the wrong server. The namespace must survive into the model's view, or the model must be given an explicit disambiguation affordance. Scoped keys in the registry plus bare names in the prompt is a half-fix that relocates the aliasing from the multiplexer into the model's head. ## Operational Effect When the invariant holds, a name collision produces a registration-time `ToolIdentityCollision` that the orchestrator must resolve (rename, drop a server, or require model disambiguation) *before* the session proceeds. The model never sees an aliased tool; every dispatched call is reconstructable to exactly one `(server_id, tool_name, generation)`. Error compounding from false-premise tool results is eliminated at its source rather than caught downstream. When the invariant is violated, the observable signature is: **all calls succeed, schemas validate, and the model's reasoning drifts** because a tool result describes state the model did not ask about. This is the hardest class of agent failure to detect post-hoc, because there is no error to grep for — the trace shows a sequence of successful calls and a conclusion that is simply wrong about the world. Detection requires replaying the session against the registry's binding history and checking that each call's resolved `server_id` matches the server the model's context implied — a check that is only possible if the generation counter and full tuple were recorded at dispatch time. The guardrail is therefore twofold: refuse to collapse at composition time, and record the full `(server_id, tool_name, generation)` tuple on every dispatch so that aliasing, if it slips through via rebind races, is at least *auditable* after the fact. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Any class ToolIdentityCollision(RuntimeError): """Raised when a chained MCP registration would shadow an existing scoped tool identity.""" class StaleBindingDispatch(RuntimeError): """Raised when a call is dispatched against a binding generation that has since been rebound.""" @dataclass(frozen=True) class ToolBinding: server_id: str tool_name: str generation: int schema: dict[str, Any] @dataclass class ChainedMultiplexer: # Keyed on the FULL tuple, never on bare tool_name. _registry: dict[tuple[str, str], ToolBinding] = field(default_factory=dict) _generation: int = 0 def register(self, server_id: str, tool_name: str, schema: dict[str, Any]) -> ToolBinding: key = (server_id, tool_name) if key in self._registry: existing = self._registry[key] raise ToolIdentityCollision( f"server {server_id!r} already registered tool {tool_name!r} " f"at generation {existing.generation}; refusing to shadow scoped identity" ) self._generation += 1 binding = ToolBinding(server_id, tool_name, self._generation, schema) self._registry[key] = binding return binding def resolve(self, server_id: str, tool_name: str, expected_generation: int) -> ToolBinding: key = (server_id, tool_name) binding = self._registry.get(key) if binding is None: raise ToolIdentityCollision( f"no binding for ({server_id!r}, {tool_name!r}); " f"call cannot be reconstructed to a single server" ) if binding.generation != expected_generation: raise StaleBindingDispatch( f"call intended generation {expected_generation} for " f"({server_id!r}, {tool_name!r}) but binding is now generation " f"{binding.generation}; a rebind raced the dispatch" ) return binding def dispatch( self, server_id: str, tool_name: str, expected_generation: int, args: dict[str, Any] ) -> ToolBinding: # Reconstruct full identity before touching transport. binding = self.resolve(server_id, tool_name, expected_generation) # ... transport send over shared session, scoped to binding.server_id ... return binding ```