Pi MCP Adapter
Use MCP servers with Pi without burning your context window.
https://github.com/user-attachments/assets/4b7c66ff-e27e-4639-b195-22c3db406a5a
What's new in 7.0
https://github.com/user-attachments/assets/a3fc7834-2540-45b6-a80e-d9c17125a66c
On servers that support MCP Tasks, add "protocolVersion": "auto" and slow tools run in the background while the agent keeps working. Tool search can rank tools by meaning and send full schemas only for the ones that fit. And extract hands the agent just the values it asked for from a long result. Everything else is in the changelog.
Why This Exists
Mario wrote about why you might not need MCP. The problem: tool definitions are verbose. A single MCP server can burn 10k+ tokens, and you're paying that cost whether you use those tools or not. Connect a few servers and you've burned half your context window before the conversation starts.
His take: skip MCP entirely, write simple CLI tools instead.
But the MCP ecosystem has useful stuff - databases, browsers, APIs. This adapter gives you access without the bloat. One proxy tool (~200 tokens) instead of hundreds. The agent discovers what it needs on-demand. Servers only start when you actually use them.
pi-mcp-adapter vs Pi's built-in MCP
Since then, Pi 0.99 added MCP support of its own, which also keeps tool definitions out of context. Installing the adapter replaces it in Pi sessions. What you get by switching:
- Install many servers without paying for idle ones. The built-in starts every enabled server in every Pi session and keeps it running until the session ends. By default, the adapter starts a server when the model first calls it and stops it after 10 idle minutes.
- More servers work fully. Servers can ask you questions through forms, show interactive UIs, offer prompt templates as slash commands, and run long jobs in the background while the agent keeps working. The built-in doesn't handle these.
- Find tools by what you mean. The built-in's tool search only matches words. The adapter can also rank tools by meaning with a classifier model you can already use in Pi, such as Jev or Cloudflare's Clef: in a test of 12 everyday requests across 95 tools, Jev put the right tool first in 10 of 11, where word search did in 5.
- Sign-in tokens go in your OS keychain by default (an encrypted file is opt-in), not in a plain JSON file under
~/.pi/agent. - Adding servers is easier. Give the agent a server's URL and it installs it and checks its tools in the same session, opening sign-in first if the server needs it, with no shell command or
/reload. Servers already configured in Cursor, Claude Code, Codex, or VS Code can be imported with/mcp-adapter setup, which also adds presets such as Figma and GitHub.
The built-in turns codemode on by itself; with the adapter, add "+codemode" to defaultTools in Pi's settings. Pi's codemode works with both.
Over a session, measured on Pi 0.99.2 with 100 small local servers:
Stopping a server doesn't take its tools away: the model can still search them, and a stopped server starts again on its next call (0.1–0.3 s for a small local server). For a server that must keep state between calls, set "lifecycle": "lazy-keep-alive". The first session briefly starts new servers, 10 at a time, to read their tool lists. Measurements and details.
The full comparison has every row with sources, as of Pi 1.3.0.
When you install or update the adapter, it turns Pi's built-in MCP off in Pi's settings for you (the same switch as pi config → Built-in), so the two don't both run. If you remove the adapter, turn the built-in back on there (details).
Install
pi install npm:pi-mcp-adapter
Restart Pi after installation.
DeepSeek Harness (third-party bridge): Run the unmodified adapter in DSH via pi2dsh; see the verified dsh-TUI and Web MCP guide.
What happens on first run
The adapter reads standard MCP files automatically. No extra setup needed if you already have them.
If you prefer the terminal, you can also run pi-mcp-adapter init after install to scan for host-specific configs and add missing compatibility imports to the adapter config (~/.pi/agent/mcp-adapter.json by default, or $PI_CODING_AGENT_DIR/mcp-adapter.json when set).
Quick Start
Add a server to .mcp.json in your project:
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": ["-y", "[email protected]"]
}
}
}
Servers are lazy by default — they won't connect until you actually call one of their tools. The adapter caches tool metadata so search and describe work without live connections.
mcp({ search: "screenshot" })
chrome_devtools_take_screenshot
Take a screenshot of the page or element.
Parameters:
format (enum: "png", "jpeg", "webp") [default: "png"]
fullPage (boolean) - Full page instead of viewport
mcp({ tool: "chrome_devtools_take_screenshot", args: { format: "png" } })
Two calls instead of 26 tools cluttering the context.
Common tasks
Commands
If settings.autoAuth is true, mcp({ connect: ... }), mcp({ tool: ... }), and direct tool calls automatically run OAuth when needed and retry once.
In interactive sessions, you can also authenticate from /mcp-adapter with ctrl+a or Enter on a server that needs auth. /mcp-auth without a server only opens a picker in the interactive UI. For gateway authorization and manual callback completion, see Remote/headless authentication.
On Pi 0.99 and later, servers you already signed in to with Pi's built-in MCP can reuse that sign-in: the adapter asks once per server, and /mcp-adapter offers ctrl+p to import them. See Import a sign-in from Pi's built-in MCP.
How It Works
- One
mcptool in context (~200 tokens) instead of hundreds - Servers are lazy by default — they connect on first tool call, not at startup
- Tool metadata is cached to disk so search/list/describe work without live connections
- Idle servers disconnect after 10 minutes (configurable), reconnect automatically on next use
- npx-based servers resolve to direct binary paths, skipping the ~143 MB npm parent process
- MCP server validates arguments, not the adapter
- Remote keep-alive servers force-refresh their tool catalog during health checks, before user input, and before adapter-triggered turns, with bounded reconnect backoff
- Specific tools can be promoted from the proxy to first-class Pi tools via
directToolsconfig, so the LLM sees them directly instead of having to search
Limitations
- Each Pi session runs its own server processes; rmcp-mux can share one across sessions
- Compact MCP result rendering summarizes text, but inline images are still controlled by Pi's image display settings and may render below the compact text summary.
- Pi still owns one separator row before self-rendered tool output, so compact mode reduces adapter rendering height but cannot promise true zero-gap rows.
- MCP sampling support is text-only; context inclusion, tools, stop sequences, audio, and image content are rejected with explicit errors.
Documentation
The full reference lives in docs/: