Skip to content

Hand MCP servers to pi's native MCP on pi 0.99 - #304

Merged
ilovepixelart merged 5 commits into
mainfrom
mcp-native
Sep 30, 2026
Merged

ilovepixelart merged 5 commits into
mainfrom
mcp-native

Conversation

@ilovepixelart

Copy link
Copy Markdown
Owner

pi 0.99 ships its own MCP support and drops it when an extension registers /mcp, printing Extension package "builtin:mcp": ... registers command /mcp, so built-in extension mcp was not loaded on every start. pi-code registered /mcp, so every pi 0.99 user saw that warning.

When pi.registerMcpServer exists and no MCP policy is set, pi-code keeps reading Claude's MCP configuration and applying approval, scopes and the disabled lists, and hands each server to pi instead of connecting it. Spec: docs/specs/mcp-native.md (MCPN-001 to MCPN-011).

  • extensions/mcp/native.ts: translates a server config to pi's McpServerConfig with exposure: "direct". ${VAR}/${VAR:-default} are expanded by pi-code, and every env and header value is escaped ($ as $$, a leading ! as $!), so pi's resolver never runs or expands it. Claude's CLAUDECODE/CLAUDE_* stdio variables, bearer tokens and the oauth fields are carried over; the timeout is pi-code's idle budget in seconds. Plugin servers register as plugin_<plugin>_<server>, so tools are named mcp__plugin_<plugin>_<server>__<tool> as in Claude.
  • sse, ws and websocket servers, servers with a headersHelper, and names outside [A-Za-z0-9_-] stay on pi-code's client.
  • In native mode pi-code registers no /mcp and no resource tools, does not read ~/.pi/agent/mcp.json or .pi/mcp.json (pi reads them), republishes pi's mcp__ tools on the tool roster each turn for hooks and subagent patterns, and unregisters its servers at session shutdown.
  • managed-mcp.json, allowedMcpServers or deniedMcpServers keep pi-code's own client for every server, since pi would connect its own mcp.json servers outside those rules. When pi's /mcp is disabled (-builtin:mcp) or replaced, pi-code connects everything itself. pi before 0.99 is unchanged.
  • Servers pi connects lose /mcp__server__prompt commands, @server:uri mentions, mcp_tool hooks and pi-code's timeout and reconnect settings, and get the full parent environment as stdio servers (Claude's default). Documented in docs/mcp.md.
  • scripts/e2e-smoke.sh configures a stdio server and asserts mcp__smoke__echo is declared and no builtin:mcp warning is printed; both checks fail against main.

A property test resolves escaped values with pi's own resolveConfigValueOrThrow and gets the original text back for any mix of !, $, { and }.

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

Frames handing Claude-configured MCP servers to pi's own MCP support on pi 0.99 and later: acceptance clauses MCPN-001 to MCPN-011, micro-tasks, what native mode gives up, and the decisions taken.
pi 0.99 drops its built-in MCP support when an extension registers /mcp and warns about it on every start. When pi.registerMcpServer exists and no MCP policy is set, pi-code no longer registers /mcp or the resource tools, and hands each server it would connect to pi instead (MCPN-001 to MCPN-003).

- Values are expanded by pi-code with Claude's rules and escaped for pi, so a leading ! or a $ in an env or header value is never run or expanded by pi.
- sse, ws and websocket servers, servers with a headersHelper, and names pi rejects stay on pi-code's client (MCPN-005).
- pi's own mcp.json files are left to pi (MCPN-006); approval and the disabled lists still decide what is registered (MCPN-007).
- pi's mcp__ tools are published on the MCP tool roster each turn (MCPN-008).
- When pi's /mcp is not running, everything connects on pi-code's client as before (MCPN-009).
The smoke configures a stdio MCP server and asserts pi declares its tool as mcp__smoke__echo on a pi with native MCP (smoke_echo before it) and prints no builtin:mcp replacement warning. docs/mcp.md describes native mode and what does not apply there.
fc.assert with a synchronous property returns nothing; the repo's other property tests prefix it with void for the noFloatingPromises rule.
Addresses the new-code Sonar findings: a boolean parameter selecting which config files load becomes claudeUserConfigPaths and claudeProjectConfigPaths, the bearer token ternary becomes a function, and the turn_start handler is synchronous.
@sonarqubecloud

Copy link
Copy Markdown

@ilovepixelart
ilovepixelart merged commit 32d2f1c into main Sep 30, 2026
10 checks passed
@ilovepixelart ilovepixelart mentioned this pull request Sep 30, 2026
2 tasks done
@ilovepixelart
ilovepixelart deleted the mcp-native branch October 8, 2026 08:29
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