Pi MCP Extension
MCP (Model Context Protocol) client extension for the Pi coding agent β connect Pi to any MCP server
Ask AI about Pi MCP Extension
Powered by Claude Β· Grounded in docs
I know everything about Pi MCP Extension. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
pi-mcp-extension
Connect Pi to any MCP server. Supabase, DeepSource, Playwright, Context7, filesystem, databases β if it speaks MCP, Pi can use it.
pi-mcp-extension is a production-ready Model Context Protocol client extension for the Pi coding agent. It manages server connections, discovers tools, and bridges them into Pi so the LLM can call them directly.
Features
- Multi-transport β
stdiosubprocesses,streamable-http, and legacysseout of the box - Auto-discovery β Paginated
tools/listwith cursor following (MCP 2025-03-26 spec) - Live tool refresh β
notifications/tools/list_changedtriggers re-discovery without restart - Clean cancellation β
AbortSignalpropagation vianotifications/cancelled - Smart reconnection β Fixed delay retry schedule (1s β 3s β 5s β 10s β 30s), configurable max retries
- Health checks β Opt-in periodic pings to detect stale connections
- Safe process lifecycle β PID tracking with safety-net
SIGKILLfor orphaned subprocesses - Stable tool names β Sanitized, collision-avoiding names (max 64 chars) that stay constant across reconnects
- No tool churn β Activate/deactivate pattern ensures tools don't flicker during reconnection
- Global + project config β Layered config (project overrides global) with per-server tuning
- Tool annotations β
readOnlyHint,destructiveHint,idempotentHint,openWorldHintsurfaced in tool descriptions - Structured error handling β Distinct error codes for config, connection, protocol, and tool-level failures
Installation
pi install npm:pi-mcp-extension
Or try without installing:
pi -e npm:pi-mcp-extension
Quick Start
-
Install the extension:
pi install npm:pi-mcp-extension -
Create a config file at
~/.pi/agent/mcp.json(global) or.pi/mcp.json(project-level):{ "mcpServers": { "supabase": { "transport": "streamable-http", "url": "https://mcp.supabase.com/mcp", "lifecycle": "eager" } } } -
Start Pi β your MCP tools are ready. Use
/mcpto check server status.
Configuration
Config files are loaded from two locations. Project config overrides global config via shallow merge (server-level replacement).
| Location | Scope |
|---|---|
~/.pi/agent/mcp.json | Global β applies to all projects |
.pi/mcp.json | Project β overrides global per-server |
Full Example
{
"settings": {
"toolPrefix": "mcp", // Tools appear as mcp_<server>_<tool> (default: "mcp")
"requestTimeoutMs": 30000, // Per-request timeout in ms (default: 30000)
"maxRetries": 5 // Max reconnection attempts, 0-10 (default: 5)
},
"mcpServers": {
// ββ HTTP-based servers βββββββββββββββββββββββββββββββββββββββββββββββββββ
"supabase": {
"transport": "streamable-http",
"url": "https://mcp.supabase.com/mcp",
"lifecycle": "eager"
},
"deepsource": {
"transport": "streamable-http",
"url": "https://mcp.deepsource.io/mcp",
"lifecycle": "eager"
},
// ββ Legacy SSE servers βββββββββββββββββββββββββββββββββββββββββββββββββββ
"legacy-server": {
"transport": "sse",
"url": "https://example.com/sse",
"lifecycle": "lazy"
},
// ββ stdio subprocess servers βββββββββββββββββββββββββββββββββββββββββββββ
"pathfinder": {
"command": "/path/to/pathfinder-mcp",
"transport": "stdio",
"lifecycle": "eager"
},
"context7": {
"command": "npx",
"args": ["-y", "@context7/mcp"],
"transport": "stdio",
"lifecycle": "lazy"
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/workspace"],
"transport": "stdio",
"lifecycle": "lazy",
"env": {
"NODE_ENV": "production"
}
}
}
}
Global Settings
| Field | Type | Default | Description |
|---|---|---|---|
toolPrefix | string | "mcp" | Prefix for registered tools: <prefix>_<server>_<tool>. Must match ^[a-zA-Z][a-zA-Z0-9_]*$. |
requestTimeoutMs | number | 30000 | Default per-request timeout in milliseconds |
maxRetries | number | 5 | Max reconnection attempts (0β10) before giving up |
Per-Server Config
| Field | Type | Default | Description |
|---|---|---|---|
transport | "stdio" | "streamable-http" | "sse" | "stdio" | Transport protocol |
command | string | β | Executable to spawn (required for stdio) |
args | string[] | [] | Arguments for the command |
env | Record<string, string> | β | Extra environment variables for the child process |
url | string | β | Server URL (required for streamable-http/sse) |
lifecycle | "eager" | "lazy" | "lazy" | eager = auto-start on session start, lazy = manual via /mcp:start |
requestTimeoutMs | number | global setting | Per-server timeout override |
healthCheckIntervalMs | number | disabled | Opt-in ping interval for connection health monitoring |
Commands
| Command | Description |
|---|---|
/mcp | Show status summary of all configured servers |
/mcp <name> | Show detailed status and stderr log for a specific server |
/mcp:start <name> | Start a server (resets retry count) |
/mcp:stop <name> | Stop a running server and deactivate its tools |
How It Works
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Pi Agent β
β β
β ββββββββββββ ββββββββββββββββββ βββββββββββββββ β
β β index.ts βββββΆβ server-manager βββββΆβ tool-bridge β β
β β (entry) β β (lifecycle) β β (MCP β Pi) β β
β ββββββββββββ βββββββββ¬βββββββββ ββββββββ¬βββββββ β
β β β β β
β βΌ βΌ βΌ β
β ββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β config β β MCP SDK β β TypeBox β β
β β (Zod) β β (transport) β β (schema) β β
β ββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
βΌ βΌ
Global/Project ββββββββββββββββ
mcp.json files β MCP Servers β
β (stdio/http) β
ββββββββββββββββ
- Config is loaded from global and project files (project overrides global by server name)
- Eager servers connect at session start; lazy servers wait for
/mcp:start - Tools are discovered via paginated
tools/listcalls (cursor-based, up to 100 pages) - JSON Schema β TypeBox conversion registers tools with Pi-compatible parameter schemas
- Pi tools are registered as
<prefix>_<server>_<tool>(sanitized, max 64 chars with hash suffix) - Tools activate/deactivate automatically as servers connect/disconnect
- AbortSignal is wired through to
notifications/cancelledfor clean cancellation - Reconnection uses a fixed delay schedule with configurable max retries
list_changednotifications trigger re-discovery, deactivating stale tools automatically- Session shutdown cleanly stops all servers and deactivates all tools
MCP Spec Compliance
Implements the MCP 2025-03-26 specification for tool clients:
| Feature | Status |
|---|---|
Protocol version 2025-03-26 (+ 2024-11-05 fallback) | β |
stdio transport | β |
streamable-http transport | β |
sse transport (legacy backwards compat) | β |
Cursor-based tools/list pagination | β |
tools/call with parameters | β |
roots/list capability (workspace root) | β |
notifications/tools/list_changed (live refresh) | β |
notifications/cancelled (AbortSignal) | β |
notifications/message (structured logging) | β |
isError: true distinction (protocol vs tool errors) | β |
Tool annotations (readOnlyHint, destructiveHint, etc.) | β |
| Resources bridge | β³ v2 |
| Prompts bridge | β³ v2 |
| Sampling | β³ v2 |
Development
# Install dependencies
npm install
# Type check (strict mode)
npm run typecheck
# Run all tests (47 tests)
npm test
# Run integration tests only (real stdio server)
npm run test:integration
Testing
The test suite includes:
- Config validation β Zod schema, global/project merge, defaults, error cases
- Server lifecycle β Connect, retry, shutdown, health check, race conditions
- Tool bridge β JSON Schema β TypeBox conversion, name sanitization, activate/deactivate
- End-to-end integration β Real mock MCP server over stdio with tool discovery and execution
License
MIT
