@spences10/pi-mcp

Pi extension for connecting MCP servers and exposing their tools

Package details

extension

Install @spences10/pi-mcp from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@spences10/pi-mcp
Package
@spences10/pi-mcp
Version
0.0.17
Published
May 4, 2026
Downloads
2,054/mo · 1,996/wk
Author
spences10
License
MIT
Types
extension
Size
131.8 KB
Dependencies
5 dependencies · 0 peers
Pi manifest JSON
{
  "extensions": [
    "./dist/index.js"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

@spences10/pi-mcp

npm version built with Vite+ tested with Vitest

Pi extension for connecting MCP servers and exposing their tools inside Pi.

Maintained in the my-pi Vite+ workspace and tested with Vitest.

Installation

pi install npm:@spences10/pi-mcp

Local development from this monorepo:

pnpm --filter @spences10/pi-mcp run build
pi install ./packages/pi-mcp
# or for one run only
pi -e ./packages/pi-mcp

Configuration

The extension loads MCP server definitions from mcp.json files in global and project locations.

A typical project mcp.json looks like:

{
	"mcpServers": {
		"sqlite": {
			"command": "npx",
			"args": ["-y", "mcp-sqlite-tools", "./data.db"]
		}
	}
}

Global MCP config is loaded automatically. Project-local mcp.json is untrusted by default because stdio servers can spawn local commands. Interactive runs prompt before loading it; headless runs skip it unless MY_PI_MCP_PROJECT_CONFIG=allow is set. Allow-once mode loads project MCP tools but suppresses rich tool descriptions and schema prose so untrusted server metadata cannot act as prompt injection. Use MY_PI_MCP_PROJECT_CONFIG=trust to trust and remember the current repo until its mcp.json hash changes and expose full metadata, or MY_PI_MCP_PROJECT_CONFIG=skip to force-disable project MCP config.

Stdio MCP servers receive a restricted child-process environment by default: baseline shell variables plus explicit per-server env values. Use MY_PI_MCP_ENV_ALLOWLIST=NAME,OTHER_NAME or the shared MY_PI_CHILD_ENV_ALLOWLIST to pass selected ambient variables through.

Server tools are registered as Pi tools using this naming format:

mcp__<server>__<tool>

For example, a sqlite server tool named execute_read_query becomes:

mcp__sqlite__execute_read_query

Commands

/mcp                         # open the TUI server manager
/mcp manage                  # same as /mcp
/mcp list
/mcp enable <server>
/mcp disable <server>
/mcp backup                  # backup global + project MCP config
/mcp restore [backup-file]   # restore from picker or filename/path
/mcp profile list
/mcp profile save [name]
/mcp profile load [name] [global|project]
/mcp profiles                # saved profile list and actions

Use /mcp to open a modal home menu for server management, read-only summaries, backups, and profiles. Toggles update the current session and persist a disabled/enabled flag in the winning mcp.json entry. Backups are written under ~/.pi/agent/mcp-backups/ and restore global/project MCP config exactly as captured after modal confirmation. Profiles are saved under ~/.pi/agent/mcp-profiles/ as reusable merged server sets that can be saved with a modal input and loaded into global or project MCP config after modal confirmation.

What it does

  • reads MCP server config
  • connects to stdio or HTTP MCP servers
  • performs the MCP initialize handshake
  • discovers tools via tools/list
  • registers each discovered MCP tool with Pi
  • forwards model tool calls to the MCP server
  • truncates oversized MCP tool text output to the first 50 KiB or 2,000 lines
  • when @spences10/pi-context is enabled, stores oversized full output in the local SQLite context sidecar and returns a searchable source id
  • otherwise saves truncated full output to a local /tmp/my-pi-mcp-output-*.txt file so it can be inspected with read or rg
  • cleans up server processes on session shutdown

Using from a custom harness

import mcp from '@spences10/pi-mcp';

// pass `mcp` as an ExtensionFactory to your Pi runtime

my-pi imports this package directly and enables it as the built-in MCP extension.

Development

pnpm --filter @spences10/pi-mcp run check
pnpm --filter @spences10/pi-mcp run test
pnpm --filter @spences10/pi-mcp run build

License

MIT