Pi agent for MCP
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Pi agent for MCP
Give ChatGPT your laptop's shell — but only while you say so.
You are discussing an idea in ChatGPT, and at some point you want it to look at the thing that is actually on your machine: the failing test, the config file, the draft in this repository. This project puts a pi coding agent behind an MCP endpoint, so the model can ask it, and the agent works in a directory you picked.
Run /connect in pi and ChatGPT gets tools. Run /disconnect and it has
nothing. Nothing ever listens on your machine.
you → ChatGPT: my test suite is failing in ~/work/api, can you look?
ChatGPT → pi_ask: "In ~/work/api, run the test suite, find the cause, fix it."
pi (your laptop):
├─ bash npm test ← shown in your terminal, you approve
├─ read src/auth.test.ts
├─ edit add the missing await
└─ bash npm test (passes)
→ "Missing await in auth.test.ts:42. Fixed; suite passes."
ChatGPT → It was a missing `await` at `src/auth.test.ts:42`. Fixed, tests green.How it works
your laptop VPS cloud
┌──────────────────────┐ ┌───────────────────────┐ ┌────────────┐
│ pi (a normal session)│ │ pi-bridge relay │ │ ChatGPT │
│ │ │ │ │ web │
│ /connect ────────────┼─────►│ /agent held GET │ │ │
│ │◄─────┤ queue + task table │◄─────┤ connector │
│ extension: poll loop │ out │ │ HTTPS│ │
│ tool calls ⬄ gate │ only │ /mcp OAuth 2.1 ─────┼─────►│ │
└──────────────────────┘ └───────────────────────┘ └────────────┘Two pieces, one repository:
server/— the relay. Runs on a small VPS with a public HTTPS name. It speaks MCP to the client and OAuth 2.1 (with Feishu as the identity provider) to protect it.extension/— the agent side. Loaded by pi, adds/connect,/disconnect, and the confirmation gate. Holds an outbound connection to the relay.
The connection is outbound-only, so the laptop stays invisible, closing the lid is a sufficient kill switch, and no port forwarding is involved.
Related MCP server: TaskQuay
Tools
pi_ask and pi_task are the intended path: they hand a whole task to the local
agent, which owns a shell, the files and its own toolchain, and can run several
commands, read what failed and adapt.
tool | purpose |
| preferred. Hand a task to the local agent; get a finished answer |
| collect a |
| pwd, model, context tokens used, busy state, session file |
| summarise the session's context — |
| list the current branch, or roll the session back to an entry |
| not recommended — one deterministic command, when you need exact output |
| not recommended — verbatim text with line numbers |
| not recommended — whole-file replace |
| not recommended — exact-snippet replace |
The ranking is deliberate and is written into the tool descriptions. A model that
reaches for pi_exec reflexively turns every task into shell-quoting practice and
loses the ability to recover from a mistake, while pi_ask can run the command,
read the error and try something else. The four escape hatches still exist
because a summary is sometimes not good enough: you cannot quote a line number
out of a summary, and re-asking for a whole task because one line was wrong is
wasteful.
pi_compact and pi_tree exist because a session driven remotely fills up and
goes wrong in ways the chat window cannot see. pi_status shows how full the
context is before it becomes a problem; pi_tree rolls back with
summarize: false by default, since the point of rolling back is a smaller
context.
One asymmetry is worth knowing: rolling back to a user message removes that message too, so it can be sent again differently, while rolling back to an assistant message keeps it. The reply says which happened and what the context now ends with.
Security
The real risk is not a leaked URL. It is ChatGPT reading a web page, being told to run something, and having a shell. Three layers:
Confirmation gate (default). Every remote-triggered
bash,writeoreditis shown in your terminal with its exact text and must be approved./connect --autoturns this off for a session you have decided to trust. Forpi_askthe gate is implemented on pi'stool_callevent, so it also covers the commands the local agent decides to run on its own — one hook, both paths.Directory fence.
--cwdsets the root. Paths are checked against the real path of the nearest existing ancestor, so a symlink cannot walk out.Two independent credentials. MCP clients authenticate through OAuth 2.1, locked to one identity. The agent presents a static bearer token, because a laptop reconnecting every few seconds must not involve a browser. That token only buys the ability to receive work, never to call a tool.
MCP_ALLOW_NO_AUTH=1 exists for local experiments. With it, anyone who learns
the URL can drive your machine whenever you are connected — there is no
credential between the MCP endpoint and your shell. Do not run it that way on the
public internet.
Quick start
You need a machine that is always on with a public HTTPS name (a €4 VPS is enough), and a laptop with pi installed.
1. Relay
sudo useradd --system --home /var/lib/pi-bridge --shell /usr/sbin/nologin pi-bridge
sudo mkdir -p /opt/pi-bridge /etc/pi-bridge
sudo git clone https://github.com/Maxmilite/pi-agent-for-mcp /opt/pi-bridge
cd /opt/pi-bridge && sudo npm install --omit=dev
sudo cp deploy/pi-bridge.env.example /etc/pi-bridge/pi-bridge.env
sudo chmod 600 /etc/pi-bridge/pi-bridge.env # fill in the values
sudo chown root:pi-bridge /etc/pi-bridge/pi-bridge.env
sudo cp deploy/pi-bridge.service /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now pi-bridge
curl https://pi.example.com/healthz # {"ok":true,"agents":0,…}deploy/nginx.conf is the vhost. The two settings that matter are
proxy_buffering off and a proxy_read_timeout comfortably above
POLL_HOLD_SEC; without them the held poll turns into a hang.
The identity provider is Feishu: create an app and add
https://pi.example.com/callback to its redirect URL whitelist. Swapping in
another provider means rewriting server/oauth.mjs, which is the only file that
knows who Feishu is.
2. Agent
Write ~/.pi/agent/pi-bridge.json (mode 600):
{ "url": "https://pi.example.com", "token": "<AGENT_TOKEN>", "agent": "laptop" }Then make pi load extension/index.ts: list it in ~/.pi/agent/settings.json
under "extensions", or copy it to ~/.pi/agent/extensions/.
/connect laptop # confirm every bash/write/edit
/connect laptop --auto # no prompts
/connect laptop --cwd ~/work # confine to a directory
/connect laptop --force # take over a name left behind by a crash
/disconnect3. ChatGPT
Settings → Connectors → Create. Server URL https://pi.example.com/mcp,
authentication OAuth, advanced OAuth settings empty (dynamic client registration
is automatic).
Ask it pi_status first: it should answer with the pwd and the context size of
the session you connected.
Configuration
Relay, in /etc/pi-bridge/pi-bridge.env:
variable | default | meaning |
| — | public origin; must be |
| — | identity provider credentials |
| empty | the only account allowed to authorize (set it) |
| — | what a pi session presents to connect |
|
| listen address; stays on loopback behind nginx |
|
| OAuth client and token store |
|
| how long a poll is held; |
|
| lease length; an agent silent this long is gone |
|
| how long a tool call blocks before returning a task id |
|
| how long finished tasks stay fetchable |
|
| restrict the surface to |
Agent, in ~/.pi/agent/pi-bridge.json: url, token, and an optional agent
name defaulting to the hostname. PI_BRIDGE_URL and PI_BRIDGE_TOKEN override it.
Design notes
Transport is a held GET, not a socket. The agent issues an ordinary
GET /agent/poll; the relay holds it until there is work or for 25 seconds.
An idle session costs 2.4 requests a minute and still receives work the instant it
exists. No WebSocket, no SSE, no reconnection state machine — a dropped
connection is just the next GET failing and retrying.
Calls are picked up, never pushed. A tool call is only sent to an agent that is currently asking for work, which removes the entire class of "message lost while the laptop slept". The lease falls out of the same mechanism: no polls, no agent, no stale cleanup to write.
With two agents connected, agent is required. Omitting it is an error that
lists the choices. A silent default would eventually send a write to the wrong
machine, and the error is self-correcting: the model reads the list and retries.
Status is answered inline while busy. A status call must not queue behind five minutes of work, so it bypasses the work queue the same way an abort does.
Limitations
Identity is Feishu only, in one file (
server/oauth.mjs).No streaming: a tool call returns when the work is done, and anything slower than its wait window becomes a task id to poll.
pi has to be running. Close it and the name frees itself within
AGENT_TTL_SEC.Tested against ChatGPT's connector; any MCP client with streamable HTTP and OAuth 2.1 should work, but the others are untested.
The agent sees your whole machine within
--cwd. That is the point, and it is also the reason the confirmation gate defaults to on.
Development
npm install
npm test # 11 teststest/e2e.test.mjs is the honest one: it starts a real relay process, loads the
real extension, and talks to it as an MCP client would. It asserts that a write
lands on disk, that an ambiguous edit writes nothing, that a path escaping the
root is refused, that a denied confirmation leaves the file untouched, that the
tool_call gate fires for the agent's own commands, that compaction reports
before/after, and that /disconnect really does make the tools fail.
Node 20+ runs the relay; the test suite needs Node 23+, because it imports the extension's TypeScript directly instead of keeping a second build artifact in sync with the first.
Layout:
server/ index.mjs HTTP, OAuth endpoints, MCP wiring
hub.mjs agents, leases, queues, tasks — no HTTP in sight
tools.mjs the nine tools and their descriptions
oauth.mjs OAuth 2.1 authorization server, Feishu as the IdP
extension/ index.ts /connect, /disconnect, the gate, the poll loop
deploy/ systemd unit, nginx vhost, example configLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Use your Mac, Windows or Linux computer from ChatGPT, Claude or Codex: files, commands, documents.
Use your own Windows, Mac or Linux computer from ChatGPT, Claude, Cursor or Gemini CLI: run commands, read, write and search files, run long processes. Your computer only makes an outgoing connection (no open ports or VPN). Read-only mode, allowed folders, blocked commands and an action log keep you in control. Free plan available.
Connect ChatGPT, Claude, Cursor or VS Code to your Windows PC: files, terminal, browser, apps.
Your own computer's files from ChatGPT or Claude: folder rules, confirmations and undo.
Related MCP Servers
- AlicenseBqualityCmaintenanceEnables ChatGPT to work directly on local projects by reading files, editing code, running tests and commands, inspecting Git state, and managing durable workflows, with optional delegation to local Codex agents for complex tasks.28MIT
- AlicenseNot gradedqualityCmaintenanceEnables ChatGPT conversations to directly inspect local workspaces and delegate coding tasks to a local Codex agent, with controlled concurrency, reusable sessions, and task/usage tracking.MIT
- FlicenseNot gradedqualityAmaintenanceEnables ChatGPT to inspect and edit local projects, run bounded commands, use Git, automate Chrome or Edge, and control connected Excel workbooks, while invoking the Codex model only when explicitly needed.-
- AlicenseNot gradedqualityAmaintenanceEnables ChatGPT to inspect and edit local projects, run bounded commands and Git operations, control Chrome or Edge, manage connected Excel workbooks, and explicitly call Codex when model work is actually needed.MIT