Skip to content

fix(quickstart): resolve host-qualified tool names in callServerTool - #807

Open
annatchijova wants to merge 1 commit into
modelcontextprotocol:mainfrom
annatchijova:fix/quickstart-host-qualified-tool-names
Open

annatchijova wants to merge 1 commit into
modelcontextprotocol:mainfrom
annatchijova:fix/quickstart-host-qualified-tool-names

Conversation

@annatchijova

Copy link
Copy Markdown

What

examples/quickstart's callServerTool call hardcodes the literal tool name "get-time" instead of recovering it from getHostContext().toolInfo. That works when the client connects 1:1 to a single server, but breaks under any host that qualifies tool names to avoid collisions across aggregated servers (e.g. pdf-server-get-time) — the widget still renders (the entry call that invoked it went out qualified, correctly, by the host), but its own follow-up callServerTool calls go out under the bare name and fail to resolve.

Why this file

@jcollas's #753 already diagnosed the root cause and proposed the fix pattern (resolveToolName, recovering the host-applied prefix from getHostContext().toolInfo.tool.name), and listed 15 affected examples. This PR applies that pattern to quickstart specifically, since docs/quickstart.md embeds it verbatim and it's the example most third-party app authors fork first. The other 14 examples (basic-server-*, pdf-server, debug-server, wiki-explorer-server, lazy-auth-server, cohort-heatmap-server, customer-segmentation-server, system-monitor-server, integration-server) share the identical shape and are left for a follow-up rather than bundled here.

Changes

  • examples/quickstart/src/mcp-app.ts: add resolveToolName() and use it for the callServerTool call, falling back to the bare name on hosts that don't rewrite names.
  • docs/quickstart.md: regenerated via npm run sync:snippets — no hand edits, stays byte-identical to the source file.

Testing

  • tsc --noEmit in examples/quickstart — clean.
  • npm run build (the example's real build) — succeeds, output unchanged in size (211.83 kB / 54.23 kB gzip) from before the fix.
  • prettier --check on both changed files — passes.
  • No existing test asserts on the literal tool-name string (tests/e2e/servers.spec.ts checks the DOM result, not the call payload), so this is a behavior addition rather than a change to covered behavior; happy to add a regression test if there's a preferred place for one.

Closes part of #753

The quickstart example's callServerTool call hardcodes the literal
tool name "get-time" instead of recovering it from
getHostContext().toolInfo, so the widget's own follow-up tool calls
break under any host that qualifies tool names to avoid collisions
across multiple aggregated servers (e.g. "pdf-server-get-time").

Apply the resolveToolName pattern @jcollas proposed in modelcontextprotocol#753 to this
example specifically, since docs/quickstart.md embeds it verbatim and
it's the template most third-party app authors fork first. The other
14 affected examples listed in modelcontextprotocol#753 share the same root cause and fix
shape and are left for a follow-up.

docs/quickstart.md is regenerated from the source file via
`npm run sync:snippets`, not hand-edited.

Closes part of modelcontextprotocol#753

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