Pi Codemode MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add pi-codemode -- npx -y pi-codemode-mcp
README.md

An MCP extension for coding agents to manage and compose MCP tools.

pi-codemode-mcp

Pi extension that exposes MCP through two tools:

  • list_mcp_tools — enumerates all MCP tools (shows first 20 inline, overflows full list to a temp file)
  • call_mcp — runs JavaScript in a sandbox and lets the script call MCP servers

It also adds a /mcp command for status, enable/disable, reconnect, and auth setup.

Why?

This was an experiment to see if there is an efficiency benefit of allowing a coding agent interface with MCP in a way that allows composition. See this blog post.

The actual findings are that with how MCP works today, such efficiency gains are not useful. On the other hand an MCP server that uses code internally can be very helpful. See for instance an example MCP server that uses a JavaScript environment to call Google services. That one actually performs as well as a similar skill does.

Configuration files

Loaded in merge order (later overrides earlier):

  1. ~/.pi/agent/mcp.json
  2. ~/.pi/agent/.mcp.json
  3. <cwd>/.pi/mcp.json
  4. <cwd>/.mcp.json

You can override with --mcp-config /path/to/file.json.

`list_mcp_tools`

Parameters:

  • query (optional): case-insensitive text match, or regex via /pattern/flags

The tool always shows the first 20 matches inline. If more matches exist, it writes the full list to a temp .tsv file so the agent can grep/rg it.

Each listed MCP tool includes a compact schema signature, with required fields marked by * and optional fields in brackets.

Only currently enabled MCP tools are listed.

`/mcp` command

Use /mcp to manage MCP from interactive mode:

  • /mcp — opens an interactive select menu (status, reconnect, auth, and per-server tool toggles)
  • /mcp status — show server connection/auth state + enabled/disabled counts
  • /mcp enable <server> <tool|all> — enable a specific MCP tool (or all tools for server)
  • /mcp disable <server> <tool|all> — disable a specific MCP tool (or all tools for server)
  • /mcp reconnect [server] — reconnect one/all servers and refresh metadata
  • /mcp auth <server> — trigger auth setup flow

Tool enable/disable policies are persisted in:

  • ~/.pi/agent/mcp-tool-policies.json

Auth behavior

  • OAuth flow (standard MCP auth)
    • /mcp auth <server> starts an OAuth browser login flow with localhost callback (for URL-based servers).
    • received tokens are stored in: ~/.pi/agent/mcp-oauth/<server>/tokens.json
    • then the server is reconnected.
    • if a server's auth metadata does not support dynamic client registration, /mcp auth falls back to bearer setup for the current session (for GitHub Copilot MCP, it will try gh auth token automatically).
  • Bearer servers (auth: "bearer" or bearer token config)
    • if bearerTokenEnv is configured, /mcp auth <server> lets you paste a token into that env var for the current pi process.
    • if no bearerTokenEnv, it stores token in memory for the current session.

For OAuth servers that require pre-registered clients, you can provide:

  • oauthClientId
  • oauthClientSecret (optional)
  • oauthClientMetadataUrl (optional)
  • oauthTokenEndpointAuthMethod (optional)

in the server config entry.

`call_mcp`

call_mcp takes JavaScript code only (plus optional timeout/state reset). Prefer batching: solve each user task in one script and use Promise.all for independent calls. Inside the script:

  • await call(server, tool, args)
  • await readResource(server, uri)
  • listTools(query?)
  • servers (array of configured server names)
  • tools (map of server -> tool names)
  • resources (map of server -> resources)
  • state (persistent mutable object across calls)

Only tools currently enabled in MCP policy are visible/callable from call_mcp.

call(server, tool, args) throws on MCP tool errors (instead of returning nested isError) and includes parameter hints from schema. It also attempts one snake_case → camelCase retry for validation errors.

Example:

const screenshots = await call("chrome-devtools", "take_screenshot", { format: "png" });
const repos = await call("github", "search_repositories", { query: "pi-mono" });

return {
  screenshot: screenshots,
  repos,
  knownServers: servers,
  firstChromeTools: tools["chrome-devtools"]?.slice(0, 10)
};

Tools (2)

list_mcp_toolsEnumerates all enabled MCP tools with schema signatures.
call_mcpExecutes JavaScript in a sandbox to call MCP tools, read resources, and manage state.

Environment Variables

bearerTokenEnvEnvironment variable name for storing bearer tokens for session-based auth.

Configuration

claude_desktop_config.json
{"mcpServers": {"pi-codemode": {"command": "npx", "args": ["-y", "pi-codemode-mcp"]}}}

Try it

List all currently enabled MCP tools to see what I have access to.
Use call_mcp to search for 'pi-mono' repositories on GitHub and return the results.
Take a screenshot using the chrome-devtools tool via call_mcp.
Check the status of my MCP server connections using the /mcp status command.

Frequently Asked Questions

What are the key features of Pi Codemode?

Sandboxed JavaScript execution for composing multiple MCP tool calls. Interactive /mcp command for managing server connections and auth. Tool-level enable/disable policies with persistent storage. Automatic OAuth flow handling for URL-based MCP servers. Support for batching multiple tool calls using Promise.all.

What can I use Pi Codemode for?

Automating complex workflows that require data from multiple different MCP servers. Managing authentication and tool access policies for multiple MCP servers in one place. Executing custom JavaScript logic to process and aggregate data from MCP resources. Debugging and inspecting available MCP tool schemas and connection states.

How do I install Pi Codemode?

Install Pi Codemode by running: npx -y pi-codemode-mcp

What MCP clients work with Pi Codemode?

Pi Codemode works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Pi Codemode docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare