MP

mitsuhiko/pi-codemode-mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

40 stars 2 forks 质量 45 趋势 12

一种利用代码将MCP连接到Pi的实验方法

概览

Pi扩展,通过两个工具暴露MCP: - list_mcp_tools — 枚举所有MCP工具(前20个内联显示,溢出完整列表为临时文件)- call_mcp — 在沙箱中运行JavaScript,并允许脚本调用MCP服务器 它还增加了 /mcp 命令,用于状态、启用/禁用、重新连接和认证设置。 这是一个实验,旨在观察允许编码代理以一种允许组合的方式与MCP接口,是否会带来效率上的提升。请参见这篇博客文章。 实际发现是,以当前MCP的工作方式来看,这些效率提升并不实用。另一方面,一个内部使用代码的MCP服务器可以非常有帮助。例如,看看一个使用JavaScript环境调用Google服务的MCP服务器示例。那个服务器的表现实际上和类似技能相当。 按合并顺序加载(后续优先覆盖): 1. ~/.pi/agent/mcp.json 2.~/.pi/agent/.mcp.json 3./.pi/mcp.json 4./.mcp.json 你可以用 --mcp-config /path/to/file.json 来覆盖。

概述(AI 翻译)

Pi扩展,通过两个工具暴露MCP:

  • list_mcp_tools — 枚举所有MCP工具(显示前20个内联工具,溢出完整列表到临时文件)
  • call_mcp — 在沙箱中运行JavaScript,并允许脚本调用MCP服务器

它还增加了一个 /mcp 命令,用于状态、启用/禁用、重新连接和认证设置。

为什么?

这是一个实验,旨在观察允许编码代理与 以一种允许合成的方式进行MCP。参见这篇博客文章。

实际发现是,按照当前MCP的工作方式,这种效率提升并不实用。另一方面 提供一个内部代码的MCP服务器会非常有帮助。参见 示例MCP服务器 使用JavaScript环境来调用谷歌服务。那个功能实际上和类似的一样好 技巧才是关键。

配置文件

按合并顺序加载(后续优先覆盖):

  1. ~/.pi/agent/mcp.json
  2. ~/.pi/agent/.mcp.json
  3. /.pi/mcp.json
  4. /.mcp.json

你可以用--mcp-config /path/to/file.json来覆盖。

list_mcp_tools

参数:

  • query(可选):不区分大小写的文本匹配,或通过[[T10]的正则表达式]

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

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. /.pi/mcp.json
  4. /.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 — enable a specific MCP tool (or all tools for server)
  • /mcp disable — disable a specific MCP tool (or all tools for server)
  • /mcp reconnect [server] — reconnect one/all servers and refresh metadata
  • /mcp auth — 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 starts an OAuth browser login flow with localhost callback (for URL-based servers).
    • received tokens are stored in: ~/.pi/agent/mcp-oauth//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 lets you paste a token into that env var for the current pi process.
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →