@ineersa/my-pi-mcp-adapter

extensionmaintained

MCP (Model Context Protocol) adapter extension for Pi coding agent — bridges any MCP server into Pi as first-class tools

by · v0.1.13 · published 2mo ago

$ pi install npm:@ineersa/my-pi-mcp-adapter
downloads/mo
0
stars
6
last push
1mo ago
open issues
3

Signals

license: MITtestspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

No downloads in the last 12 weeks.

README

@ineersa/my-pi-mcp-adapter

MCP (Model Context Protocol) bridge for Pi coding agent. ToolSearch discovery · direct tools · lazy/eager/keep-alive lifecycle · TOON encoding · metadata cache.

npm license


⚠️ Requirement

This extension requires pi-mono from the refresh-tools-between-turns branch.

The setActiveTools API is not yet in pi-mono main. Without this branch, ToolSearch cannot activate discovered tools, and direct tool registration won't work correctly.


Why this fork?

This is a slimmed, enhanced fork of Nico Bailon's excellent pi-mcp-adapter. Here's what's different:

FeatureUpstream (Nico)This fork
Tool discoverySingle mcp mega-tool with JSON-in-JSON argsToolSearch — search by keyword, load exact tools. Each MCP tool has its own typed schema.
Token efficiency~200 tokens for proxy, but LLM must construct args-as-JSON~2000+ tokens saved per turn by only shipping active tool schemas
Direct toolsdirectTools in configSame, plus MCP_DIRECT_TOOLS env var for subagents
TOON encoding−27% token savings on JetBrains search results via TOON compression
/mcp panelInteractive TUI overlayText-based status (/mcp, /mcp tools, /mcp reconnect)
OAuth flowsFull OAuth with callback serverneeds-auth detection only — tool calls gracefully skipped
MCP UIBrowser/Glimpse integrationNot included
Tool activationProxy-based (all tools through one schema)Individual tool registration — each MCP tool is a first-class Pi tool with its own typed schema

The key architectural shift: Instead of a single mcp proxy tool with generic {tool?, args?, search?, connect?} schema, every MCP tool is registered individually with its full typed schema. ToolSearch gives the LLM keyword-based discovery, and only the tools it needs are active at any time. This saves thousands of tokens per turn while making tool calls type-safe.


Quick Start

Install

This package is part of the my-pi monorepo. Install via the one-command installer:

npx @ineersa/my-pi

Or install standalone:

pi install npm:@ineersa/my-pi-mcp-adapter

Configure a server

Create ~/.pi/agent/mcp.json:

{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["-y", "some-mcp-server"]
    }
  }
}

Reload & discover

/reload

Then ask your agent:

"Search for available MCP tools related to files"

The agent calls ToolSearch({ query: "files" }), discovers matching tools, and uses them with full typed schemas on the next turn.


Features at a glance

FeatureDescriptionMore
🔍 ToolSearchSearch & load MCP tools by keyword. ~2000+ tokens saved per turn.Examples →
Direct toolsFrequently-used tools active from turn 1. Config + env var.Examples →
😴 Lazy startupServers connect on first tool call. No startup delay.Examples →
🔄 Lifecycle modeslazy, eager, keep-alive per-server.Examples →
⏱️ Idle timeoutAuto-disconnect inactive servers. Configurable per-server.Examples →
📦 Metadata cacheTool schemas cached to disk. Register tools without live connections. 7-day TTL.Examples →
🚀 npx binary resolutionBypasses ~143MB npm parent process. Direct binary invocation.Examples →
🗜️ TOON encodingJSON→TOON compression. −27% tokens on JetBrains results.Examples →
📊 Call statisticsPer-server/per-tool counters. Find your most-used tools.Examples →
📥 Config importsImport MCP servers from Cursor, Claude, Codex, Windsurf, VS Code.Examples →
📁 Project-local config.pi/mcp.json overrides user-global ~/.pi/agent/mcp.json.Examples →
📖 Resource toolsMCP resources exposed as callable Pi tools.Examples →
Failure backoff60s cooldown after failed connections.Examples →
🔐 Bearer authEnv var or static token. OAuth servers gracefully skipped.Examples →
🛡️ Collision guardTools shadowing builtins silently skipped.Examples →
🔀 Cross-server dedupHandles name collisions in prefix: "none" / "short" modes.Examples →
📡 Status barConnected/total server count in Pi footer.Examples →

Configuration Reference

File locations

PriorityFileScope
1 (highest).pi/mcp.jsonProject-local overrides
2Imported configsFrom other tools
3 (base)~/.pi/agent/mcp.jsonUser global

Per-server fields

FieldTypeDefaultDescription
enabledbooleantrueDisable without removing from config
commandstringExecutable for stdio transport
argsstring[][]Command arguments
envobjectEnvironment variables (${VAR} supported)
cwdstringWorking directory
urlstringHTTP endpoint (StreamableHTTP/SSE)
headersobjectHTTP headers (${VAR} supported)
auth"bearer" or falseAuthentication type
bearerTokenstringStatic bearer token
bearerTokenEnvstringEnv var name for bearer token
lifecycle"lazy" / "eager" / "keep-alive""lazy"Connection lifecycle mode
idleTimeoutnumberglobal defaultMinutes before idle disconnect
startupTimeoutMsnumber30000Connection timeout at startup
exposeResourcesbooleantrueExpose MCP resources as callable tools
directToolsboolean or string[]falseMake specific tools always active
excludeToolsstring[]Hide specific tools from LLM
debugbooleanfalseShow server stderr

Global settings

FieldTypeDefaultDescription
toolPrefix"server" / "short" / "none""server"Tool name prefix style
idleTimeoutnumber10Global idle timeout in minutes
toonEncodeboolean or string[]Enable TOON encoding (true = all, array = specific servers)
captureStatsboolean or objectEnable call statistics

Commands

CommandDescription
/mcp or /mcp statusShow server connection status
/mcp toolsList all available tool names
/mcp reconnectReconnect all enabled servers
/mcp reconnect <server>Reconnect a specific server

Environment variables

VariableDescription
MCP_DIRECT_TOOLSComma-separated server/tool specifiers. * = all servers, server_name = all tools from that server, server/tool = specific tool, __none__ = no direct tools
MCP_UI_DEBUG=1Enable debug logging

Architecture

┌─────────────────────────────────────────────────────────┐
│                     Pi Agent                              │
│  ┌──────────┐  ┌──────────────┐  ┌──────────────────┐   │
│  │ Builtins │  │  ToolSearch  │  │  Direct MCP       │   │
│  │ (active) │  │  (active)    │  │  Tools (active)   │   │
│  └──────────┘  └──────┬───────┘  └──────────────────┘   │
│                       │                                  │
│                       │ discover ▼                       │
│               ┌───────▼────────┐                         │
│               │ Deferred MCP   │  Inactive until         │
│               │ Tools          │  discovered via         │
│               │                │  ToolSearch             │
│               └────────────────┘                         │
└──────────────────────┬──────────────────────────────────┘
                       │
          pi-mcp-adapter layer
                       │
   ┌───────────────────┼───────────────────┐
   │ lifecycle manager │ metadata cache    │
   │ health checks     │ ~/.pi/agent/      │
   │ idle timeout      │ mcp-cache.json    │
   └───────────────────┼───────────────────┘
                       │
             ┌─────────┼──────────┐
             │ stdio   │ HTTP      │ SSE
             ▼         ▼           ▼
          MCP Svr   MCP Svr     MCP Svr

Documentation

DocumentContent
examples.mdAll 17 examples with JSON configs and usage patterns
architecture.mdFull technical architecture — module map, lifecycle, data flow, transport layer
settings.mdDetailed settings reference
usage.mdUsage overview
maintenance.mdModule map, key events, tool registration flow
CHANGELOG.mdVersion history

License

MIT © 2026 Nico Bailon (original) · Ineersa (fork additions: ToolSearch, TOON encoding, direct tool activation)

This project is a fork of pi-mcp-adapter by Nico Bailon, modified and maintained as part of the my-pi monorepo. All original copyright and permission notices are preserved. See LICENSE for the full text.

The following components are new in this fork:

  • ToolSearch — keyword-based tool discovery replacing the mcp proxy mega-tool
  • TOON encoding — JSON→TOON compression for token-efficient MCP responses
  • Tool activation via pi.setActiveTools() (requires pi-mono refresh-tools-between-turns)
  • Slimmed scope: no OAuth flows, no MCP UI panel, text-based /mcp commands only