pi-delegate-mcp 标志

pi-delegate-mcp

社区
howznguyen

MCP server that turns the pi coding agent into a steerable background worker: delegate a task, redirect it mid-run, and keep its context out of your own.

发布者howznguyen
代码仓库pi-delegate-mcp
语言TypeScript
复刻数
5
星标数
15
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    pi-delegate-mcp 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 15 个 Star 和 5 个 Fork。

██████╗ ██╗    ██████╗ ███████╗██╗     ███████╗ ██████╗  █████╗ ████████╗███████╗
██╔══██╗██║    ██╔══██╗██╔════╝██║     ██╔════╝██╔════╝ ██╔══██╗╚══██╔══╝██╔════╝
██████╔╝██║    ██║  ██║█████╗  ██║     █████╗  ██║  ███╗███████║   ██║   █████╗
██╔═══╝ ██║    ██║  ██║██╔══╝  ██║     ██╔══╝  ██║   ██║██╔══██║   ██║   ██╔══╝
██║     ██║    ██████╔╝███████╗███████╗███████╗╚██████╔╝██║  ██║   ██║   ███████╗
╚═╝     ╚═╝    ╚═════╝ ╚══════╝╚══════╝╚══════╝ ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝
                            ███╗   ███╗ ██████╗██████╗
                            ████╗ ████║██╔════╝██╔══██╗
                            ██╔████╔██║██║     ██████╔╝
                            ██║╚██╔╝██║██║     ██╔═══╝
                            ██║ ╚═╝ ██║╚██████╗██║
                            ╚═╝     ╚═╝ ╚═════╝╚═╝

npm node license

MCP server that exposes the pi coding agent as a delegable, steerable worker.

Point Claude Code (or any MCP host) at it and delegate work to any of pi's ~38 providers (DeepSeek, Grok, GLM, Kimi, Qwen, Codex, OpenRouter, local llama.cpp) with the sub-agent's context staying out of your main conversation.

What it's for

Your main harness runs on an expensive model, with a context window you care about. A lot of what it does doesn't need that model, and actively damages that context: grepping a repo for every call site, reading a 2000-line file to answer one question, auditing what a refactor left behind.

Hand that work to a delegate instead:

  • Cost. The grunt work runs on DeepSeek, GLM, Kimi, Qwen, or a local llama.cpp. You pay frontier prices only for the reasoning that actually needs them.
  • Context. The delegate reads the files on its own budget and returns a result. The 200 KB it read never enters your conversation.
  • Blast radius. Delegates are read-only by default (read, grep, find, ls), enforced at session construction. A cheap model doing exploratory work cannot touch your tree unless you opt it in.

The delegate is always the pi agent. Codex, Grok, DeepSeek and the rest supply the model behind it; this is not a wrapper around their CLIs.

Why pi, and not opencode or a CLI wrapper?

A delegate is only steerable if two channels stay open: you must be able to redirect it mid-task, and it must be able to ask you something and block until you answer. Most ways of driving a coding agent from another program close both.

pi -p / CLI wrappersopencode SDKthis server
Runs in-processno (subprocess)no (HTTP client to opencode serve)yes (createAgentSession)
Redirect a running turnnoabort onlysteer
Agent can ask you somethingno (ctx.hasUI false)not in the session APIstatus → answer *
Model per callnoyesmodel argument

pi -p and --mode json set ctx.hasUI = false. A delegate started that way is fire-and-forget by construction: it cannot raise a question, and you cannot redirect it.

opencode's SDK is a typed client for a separate server process: createOpencode() boots opencode serve and talks HTTP to it. Clean design, but it means a second process to supervise, and the session surface it exposes (prompt, abort, revert, messages) has no mid-turn steering and no path for the agent to ask the caller anything.

pi ships createAgentSession as an embeddable library. This server holds the session object in-process, so session.steer() can land a message after the current tool call and before the next model call, and a synthetic uiContext catches the agent's questions and parks them for answer. Nothing is shelled out; nothing has to be supervised.

* Questions come from pi extensions, so that channel is open only for delegates spawned with extensions: true. See Web search and other extension tools.

(The table compares the delegation channel, not sandboxing; opencode has its own permission config. See Read-only by default for what this server does and does not enforce.)

Tools

ToolPurpose
initCall first. Reports reachable models, permitted tools, and how to drive a delegate. Every other tool refuses until it has run once.
spawnDelegate in the background. Returns sessionId immediately. Use this by default.
spawn_batchFan out up to 10 delegates in one call. Validated as a batch, so nothing starts if one task is bad.
runDelegate and block until done. For quick questions only.
statusState, turns, tools used, latest text, and pending questions.
steerRedirect a running agent. Lands after its current tool call.
follow_upGive a finished delegate another turn. It keeps everything it read, so you do not re-explain the task.
answerAnswer a question surfaced by status. Only reachable with extensions: true, since only extensions can ask.
abortStop a session; partial output stays readable.
modelsList models this delegate may use.
sessionsList sessions, running and finished. Filter by state, expand with verbose.
forgetDrop a finished session from history, freeing its id.

Install

Requires Node.js 22.19+ and a working pi install that has been logged in once (pi, then /login).

Claude Code

bash
claude mcp add pi -e PI_DELEGATE_MODEL=openrouter/stealth/ox-alpha -- npx -y pi-delegate-mcp

Any MCP host, via .mcp.json

json
{
  "mcpServers": {
    "pi": {
      "command": "npx",
      "args": ["-y", "pi-delegate-mcp"],
      "env": { "PI_DELEGATE_MODEL": "openrouter/stealth/ox-alpha" },
      "timeout": 1800000
    }
  }
}

npx resolves the package on every launch. To pin it, install globally and call the binary directly:

bash
npm install -g pi-delegate-mcp
json
{ "mcpServers": { "pi": { "command": "pi-delegate-mcp", "timeout": 1800000 } } }

Keep the server key short, since it prefixes every tool name (mcp__pi__spawn).

From source

bash
git clone https://github.com/howznguyen/pi-delegate-mcp && cd pi-delegate-mcp
npm install && npm run build && npm link

First run

Ask your agent to delegate something. It calls init once to learn what this server can reach, then spawn:

json
{ "id": "audit-01", "label": "who still imports onnxruntime",
  "prompt": "Search this repo for anything still importing onnxruntime and list the files.",
  "cwd": "/path/to/repo" }
json
{ "sessionId": "audit-01", "state": "running", "model": "opencode-go/deepseek-v4-flash",
  "activeTools": ["read", "grep", "find", "ls"] }

spawn returns immediately. Poll with status for the ordered tool trace and the answer, or sessions when several are in flight. If init fails, it says exactly what is missing: pi not installed, no provider logged in, or a model scope that matches nothing.

Model names in the examples below are illustrative. Run models to see what your own pi install can actually reach.

Traceability

spawn and run both accept your own id and a free-text label:

json
{
  "id": "search-audit-01",
  "label": "what ONNX removal left behind",
  "prompt": "...",
  "model": "opencode-go/deepseek-v4-flash"
}

Ids are [A-Za-z0-9._:-], 1-64 chars, must start alphanumeric, and must be unique among live sessions. Omit for a UUID.

Finished sessions stay readable via status and sessions instead of vanishing, so you can go back and check what a delegate actually did. The newest PI_DELEGATE_HISTORY (default 50) are kept; forget drops one early.

status returns an ordered toolCalls trace: every tool the delegate ran, with arguments and timing. Add verbose: true for call ids and results:

json
{
  "seq": 1,
  "id": "call_467b4bb4…",
  "name": "bash",
  "state": "ok",
  "ms": 10,
  "args": "{\"command\":\"echo hello-trace\"}",
  "result": "hello-trace\n"
}

Arguments and results are clipped (PI_DELEGATE_TRACE_ARGS, PI_DELEGATE_TRACE_RESULT) with the dropped length recorded, so one read of a large file cannot flood your context.

Giving a delegate another turn

A finished delegate is not spent. pi keeps its session in memory, so follow_up re-prompts the same agent with everything it already read still in context:

json
{ "sessionId": "search-audit-01", "prompt": "Now check whether the build files reference it too" }
{ "sessionId": "search-audit-01", "state": "running", "turnsSoFar": 1 }

The delegate picks up where it left off. It still holds the files it read on the first turn, so the second question costs one model call rather than a fresh session re-reading the repository.

This is the cheap way to have a conversation with a delegate. Spawning a fresh one means re-explaining the task and paying for it to re-read the same files, and its answer arrives with none of the reasoning that led there.

follow_up refuses a delegate that is still working, because redirecting one mid-task is what steer is for. The two are not interchangeable: steer lands between tool calls on a running agent, follow_up starts a new turn on a finished one.

Fanning out

spawn_batch starts a whole batch in one call. Tasks inherit the batch-level model, cwd, tools and extensions, and override them individually where they need to:

json
{
  "idPrefix": "audit",
  "model": "opencode-go/deepseek-v4-flash",
  "cwd": "/repo",
  "tools": ["ls"],
  "tasks": [
    { "prompt": "What still imports onnxruntime?", "label": "imports" },
    { "prompt": "Which build files still reference ONNX?", "label": "build" },
    {
      "prompt": "Any ONNX model files left on disk?",
      "label": "artifacts",
      "model": "opencode-go/ox-alpha-free"
    }
  ]
}

That names them audit-01, audit-02, audit-03 and returns in a few milliseconds, since launching a delegate does not wait for it to think.

The batch is validated before anything starts: id format, ids duplicated inside the batch, ids already live, blocked tools, and every model name. One bad task fails the call and launches nothing. Half a fan-out is the worst outcome, because you pay for the delegates that did start and still have to work out which ones did not.

Poll the whole batch with one sessions call rather than one status per delegate. Drop to status only for the delegate you actually want to read. steer and abort stay per session.

Picking a model per call

model on any call overrides PI_DELEGATE_MODEL. An unresolvable name is a hard error, never a silent fallback to the default model, because a silent fallback is how you end up billing a model you never asked for.

Which names resolve is decided by pi's own enabledModels scope, which this server enforces rather than merely displays:

opencode-go/deepseek-v4-flash  -> ok      (listed in enabledModels)
opencode-go/glm-5.3            -> refused (out of scope)
knowns-hub/claude-opus         -> ok      (custom provider, see below)

Custom providers bypass the scope. Any model served by a provider declared in ~/.pi/agent/models.json is offered even when enabledModels does not name it, on the grounds that declaring a provider by hand is already an intent to use it. This is why the list can be much longer than enabledModels: three entries in the scope plus two custom providers can easily mean fifteen offered models. init says so explicitly in models.scopeNote when it applies.

Two switches change that:

Effect
PI_DELEGATE_STRICT_SCOPE=1Honour enabledModels exactly. The custom-provider bypass is dropped.
PI_DELEGATE_IGNORE_SCOPE=1Drop scoping altogether. Every authenticated model is usable.

Call models to see what is actually reachable under whichever setting is in force.

Status line

Claude Code allows exactly one statusLine command, so pi-delegate-statusline wraps whatever you already run and appends a segment showing this workspace's delegates:

json
{
  "statusLine": {
    "type": "command",
    "command": "PI_DELEGATE_STATUSLINE_WRAP=ccstatusline pi-delegate-statusline",
    "refreshInterval": 10
  }
}

Drop PI_DELEGATE_STATUSLINE_WRAP to print the pi segment alone.

π ▸ audit engine·t1·12s audit index·t2·8s   running, with turn counts and elapsed time
π ▸ migrate·t7·3m04s ?1 waiting             one delegate is blocked on a question
π ✓2                                        finished, nothing running

Which delegates belong to which session

Filtering by directory is not enough: two Claude Code sessions open on the same repository would show each other's delegates. Attribution uses process lineage instead.

The MCP host spawns one server per session, so the server records process.ppid, the host's pid. The status line, spawned by that same host, walks its own ancestry and keeps only the state files whose hostPid it finds there. Same repo, two sessions, no crosstalk. The directory filter remains as a fallback for state files written before this existed.

State lives in $XDG_STATE_HOME/pi-delegate-mcp/<pid>.json (PI_DELEGATE_STATE_DIR to relocate). Files are pruned when their process is gone, ESRCH only, since EPERM means the process is alive under another user. Servers also exit on their own when stdin closes or the host pid disappears, so a host that dies without closing the transport leaves nothing behind.

Read-only by default

Tools are locked to read, grep, find, ls at session construction. Anything else is refused before a session is even created.

To widen that, name the extra tools on the server:

json
"env": { "PI_DELEGATE_ALLOW_TOOLS": "bash" }

or PI_DELEGATE_ALLOW_WRITE=1 to permit everything.

bash is not a middle ground. pi ships no permission system, so a delegate holding bash can write files, delete them, and reach the network regardless of whether write and edit are on its list. Refusing those two while allowing bash records your intent; it does not enforce anything. Claude Code's permission prompts and hooks never see what pi does. If you need a real boundary, run this server inside a container.

Web search and other extension tools

pi's own tools are read, grep, find, ls, bash, powershell, write, edit. There is no search and no fetch among them. Those come from pi extensions, which register their own tools, and a delegate can use them.

Set extensions: true on the call and permit the tool names on the server:

json
"env": { "PI_DELEGATE_ALLOW_TOOLS": "web_search,fetch_content" }
json
{ "prompt": "Find the current Node LTS version and tell me just the number",
  "extensions": true, "tools": ["read", "grep", "find", "ls", "web_search"] }
json
{ "seq": 1, "name": "web_search", "state": "ok", "ms": 2568,
  "args": "{\"query\":\"latest stable Node.js LTS version\",\"numResults\":5}" }

This is how you give a delegate network reach without handing it bash. web_search can search and nothing else, and it passes through the same allowlist as every other tool, so the read-only default is unchanged for calls that do not ask for it.

Which tools exist depends on what the user running the server has installed. pi-web-access provides web_search, fetch_content, source_check and get_search_content. pi-mcp-adapter bridges the MCP servers in ~/.pi/agent/mcp.json and exposes them as mcp. pi has no MCP client of its own, so that extension is the only route to one.

extensions: true trusts every installed extension, not just the one you wanted. They load as a set, they run with the full privileges of this server's process, and some open sockets and timers that outlive the session. Turn it on per call, for the delegates that need it, rather than leaving it on by default. It also costs real startup time, which is why it is off unless asked for.

Configuration

Env varDefaultMeaning
PI_DELEGATE_MODELpi's own defaultModel used when a call omits model
PI_DELEGATE_ALLOW_TOOLSunsetComma list of extra tools to permit, e.g. bash
PI_DELEGATE_ALLOW_WRITEunset1 permits every tool
PI_DELEGATE_HISTORY50Finished sessions kept for review
PI_DELEGATE_TRACE_ARGS400Max chars of tool arguments kept in the trace
PI_DELEGATE_TRACE_RESULT600Max chars of tool results kept in the trace
PI_DELEGATE_BATCH_MAX10Ceiling on tasks per spawn_batch call
PI_DELEGATE_LIST_CAP60Above this, init summarises models by provider instead of listing them
PI_DELEGATE_STATE_DIRXDG state dirWhere status-line state is published
PI_DELEGATE_STATUSLINE_WRAPunsetStatus line command to wrap and append to
PI_DELEGATE_STATUSLINE_LOGunsetFile to append a timestamp to on every status line render, for debugging
PI_DELEGATE_PROGRESS_MS15000Progress notification interval during run
PI_DELEGATE_IGNORE_SCOPEunset1 ignores pi's enabledModels scope, allowing any configured model
PI_DELEGATE_STRICT_SCOPEunset1 honours enabledModels exactly, dropping the custom-provider bypass
PI_CODING_AGENT_DIR~/.pi/agentWhere pi's auth.json and config are read from

Long-running work

The MCP TypeScript SDK defaults to a 60 second request timeout, which a real task will blow through. Three defences, in order of preference:

  1. Use spawn + status. Nothing blocks, so no timeout applies.
  2. run emits periodic progress notifications, which reset the host's timeout.
  3. Raise the ceiling with "timeout" in .mcp.json or MCP_TOOL_TIMEOUT in the environment.

CLAUDE_AUTO_BACKGROUND_TASKS=1 makes Claude Code background long MCP calls after ~2 minutes. Note that progress notifications are discarded once a call is backgrounded, so pick (1) or (3), not both.

Auth

The server does not handle credentials. pi authenticates itself from ~/.pi/agent/auth.json, then environment variables. MCP hosts often launch servers with a stripped environment, so prefer auth.json (run pi once and /login) over exporting keys in a shell profile.

Development

bash
npm install
npm run build       # tsc, src/*.ts -> dist/
npm run typecheck   # tsc --noEmit, strict
npm run test:ci     # offline: boots the server over stdio and lists its tools
npm test            # full suite: needs a logged-in pi, makes real model calls

test:ci is what CI runs and what prepublishOnly gates on, because it needs no credentials and no network. npm test drives real delegates against real providers, so it costs money and only works where pi has been logged in.

PathWhat lives there
src/config.tsEvery environment variable, read in one place
src/permissions.tsThe tool allowlist and the gate that enforces it
src/registry.tsSession map, id claiming, history eviction
src/tools/One module per group of MCP tools
src/pi/Everything that touches the pi SDK
src/statusline/State file publishing and the status line binary

Releases are tag-driven. npm version patch && git push --follow-tags runs the build and tests, then publishes over OIDC trusted publishing, so no npm token is stored anywhere in the repository.

Issues and pull requests are welcome. If you are reporting a delegate that misbehaved, the toolCalls trace from status with verbose: true is the useful thing to attach.

Prior art

abatilo/pi-mcp-bridge takes the simpler route: spawn pi --mode json -p --session-id <uuid> and let pi persist sessions on disk, so the bridge holds no state at all. Elegant, and worth reading. It trades away steering, questions, and tool control to get there.

License

MIT

将 pi-delegate-mcp MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 pi-delegate-mcp 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 pi-delegate-mcp 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 pi-delegate-mcp MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "pi-delegate-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 pi-delegate-mcp MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 pi-delegate-mcp MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 pi-delegate-mcp 帮我完成这项任务吗?
pi-delegate-mcp
当然。我已阅读。
以下是我使用 pi-delegate-mcp 得到的结果。

常见问题

pi-delegate-mcp MCP 服务器有什么用途?

pi-delegate-mcp 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 pi-delegate-mcp MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 pi-delegate-mcp,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 pi-delegate-mcp MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 pi-delegate-mcp 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 pi-delegate-mcp MCP 连接到 TypingMind?

pi-delegate-mcp 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

pi-delegate-mcp MCP 在 TypingMind 中提供哪些工具?

pi-delegate-mcp 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 pi-delegate-mcp MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 pi-delegate-mcp 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇