Skip to content

Defer native MCP servers behind tool_search by default - #408

Merged
ilovepixelart merged 1 commit into
mainfrom
feat/406-deferred-mcp-exposure
Oct 22, 2026
Merged

ilovepixelart merged 1 commit into
mainfrom
feat/406-deferred-mcp-exposure

Conversation

@ilovepixelart

Copy link
Copy Markdown
Owner

Every server pi-code hands to pi's native MCP was registered with exposure: "direct", so all of its tool definitions went out with every request: two plugin servers with 46 tools added about 39k characters to each one. Claude Code defers MCP tools behind tool search by default ("Tool search is enabled by default: MCP tools are deferred and discovered on demand", code.claude.com/docs/en/mcp#configure-tool-search).

  • Deferred by default (extensions/mcp/native.ts): a server is registered as "deferred". pi activates tool_search for it and names it in the mcp_servers prompt section; its tools are declared once tool_search loads them.
  • Upfront where Claude loads upfront: alwaysLoad: true on the server, or ENABLE_TOOL_SEARCH=false, registers it as "direct". alwaysLoad is now part of the server config types (extensions/mcp/config.ts).
  • Threshold modes defer: ENABLE_TOOL_SEARCH set to true, auto or auto:N registers "deferred"; pi has no context-size threshold to load tools under.
  • Behavior change: servers without alwaysLoad no longer have their tools declared in the first request; the model reaches them through tool_search. alwaysLoad: true or ENABLE_TOOL_SEARCH=false restores upfront declaration.

A tool's own _meta["anthropic/alwaysLoad"] is not read, since pi-code does not connect the server in native mode; docs/mcp.md says so. Spec clause MCPN-012 added, MCPN-003 updated.

The e2e smoke run checks that the deferred server is listed for tool_search and mcp__smoke__echo is not declared, that an alwaysLoad server's mcp__loaded__echo is declared, and that an unapproved project's server is neither declared nor listed. On the previous "direct" registration the first two checks fail.

Closes #406

  • npm run check passes (Biome, strict tsc, Vitest)
  • Tests cover the change

Every server handed to pi was registered with exposure "direct", so all
of its tool definitions went out with every request. Claude Code defers
MCP tools behind tool search by default and declares them upfront only
for a server with alwaysLoad: true or when ENABLE_TOOL_SEARCH is false.

toNativeServer now registers a server as "deferred" unless it sets
alwaysLoad: true or ENABLE_TOOL_SEARCH is "false". true, auto and auto:N
defer, as pi has no context-size threshold. pi activates tool_search for
deferred servers and names them in its mcp_servers prompt section.

The smoke run now checks that the deferred server is listed for
tool_search and its tool is not declared, that an alwaysLoad server's
tool is declared, and that an unapproved project's server is neither
declared nor listed.

Closes #406
@sonarqubecloud

Copy link
Copy Markdown

@ilovepixelart
ilovepixelart merged commit b2de62a into main Oct 22, 2026
13 checks passed
@ilovepixelart
ilovepixelart deleted the feat/406-deferred-mcp-exposure branch November 4, 2026 15:04
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.

Native MCP: register servers with deferred exposure by default, as Claude Code's tool search does

1 participant