Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(cli): harness mcp-servers is refused in a Harness pane too, and the doc says an entry runs at every launch with no prompt (#1881's P3s) (#1900)

daniel-autoacbffc65a1af
diff --git a/cli/src/agentClient/mcpServers.spec.ts b/cli/src/agentClient/mcpServers.spec.ts
index 9845a67da..34bd4cda7 100644
--- a/cli/src/agentClient/mcpServers.spec.ts
+++ b/cli/src/agentClient/mcpServers.spec.ts
@@ -30,6 +30,9 @@ describe('harness mcp-servers (#1872)', () => {
expect(tried.err).toMatch(/may not change this machine's MCP servers/)
expect(readMachineMcp(tried.dataDir).servers).toEqual({})
}
+ // An agent in a Harness pane whose engine sets none of those variables (#1881's P3).
+ const inPane = mcpServersCommand(['add', 'lamp', '--', 'lamp-mcp'], { dataDir: mkdtempSync(join(tmpdir(), 'mcp-servers-')), env: {}, inPane: true, out: () => {}, err: () => {} })
+ expect(inPane).toBe(5)
// Listing is fine for anyone on this machine.
expect(run(['list'], { CODEX_THREAD_ID: 't' }).code).toBe(0)
})
diff --git a/cli/src/agentClient/mcpServers.ts b/cli/src/agentClient/mcpServers.ts
index acc38f37c..f12e98c97 100644
--- a/cli/src/agentClient/mcpServers.ts
+++ b/cli/src/agentClient/mcpServers.ts
@@ -37,6 +37,10 @@ export interface McpServersDeps {
dataDir?: string
/** Who runs it, by what its shell says (model.ts `outsideCaller`): an agent may list, never change. */
env?: NodeJS.ProcessEnv
+ /** Whether it runs in a pane a Harness daemon made (cli.ts, as `harness mcp` asks `paneOwner`): an agent there whose
+ * engine sets none of `outsideCaller`'s variables (Hermes, OpenCode) is refused too. A person's own terminal pane in
+ * Harness can't be told apart from an agent's, so it is refused alike, and told to run it outside Harness. */
+ inPane?: boolean
out?: (line: string) => void
err?: (line: string) => void
}
@@ -63,9 +67,10 @@ export function mcpServersCommand(argv: readonly string[], deps: McpServersDeps
}
if (verb !== 'add' && verb !== 'remove') { err(MCP_SERVERS_USAGE); return 2 }
const agent = outsideCaller(deps.env ?? process.env, '')
- if (agent) {
- err(`${agent.name} may not change this machine's MCP servers: a server runs a command inside every later agent here. `
- + 'Tell the person the exact harness mcp-servers command to run themselves.')
+ if (agent || deps.inPane) {
+ err(`${agent ? agent.name : 'An agent in a Harness pane'} may not change this machine's MCP servers: a server runs a command `
+ + 'inside every later agent here. Tell the person the exact harness mcp-servers command to run themselves, in a terminal '
+ + 'outside Harness.')
return REFUSED
}
if (why) { err(`Fix or remove it first: ${why}`); return 1 }
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index e1a9a181b..840e8b623 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -2672,7 +2672,7 @@ async function logsExportCommand(json: boolean): Promise<void> {
}
import { orchestratorCommand } from './orchestrator/command.js'
-import { paneOwner, sendCommand } from './messages/command.js'
+import { paneOwner, sendCommand, sendPane } from './messages/command.js'
import { agentOrigin, closeCommand, psCommand, replyCommand, showCommand, tellCommand, waitCommand, watchCommand, whoamiCommand } from './agentClient/commands.js'
import { agentsHelp, helpFor } from './agentClient/help.js'
import { openUrlCommand } from './agentClient/openUrl.js'
@@ -2733,9 +2733,13 @@ switch (cmd) {
case 'settings':
settingsCommand(rest, { port: daemonPort() }).then(code => { process.exitCode = code }).catch(onError)
break
- case 'mcp-servers':
- process.exitCode = mcpServersCommand(rest)
+ case 'mcp-servers': {
+ // Refused in a pane a Harness daemon made, as `harness mcp` tells one (#1881's P3): an engine there may set none of
+ // the variables `outsideCaller` reads. A pty host pane (Windows) is always Harness's.
+ const pane = sendPane(process.env)
+ process.exitCode = mcpServersCommand(rest, { inPane: !!pane && (!pane.startsWith('%') || !!paneOwner(pane)) })
break
+ }
case 'mcp': {
const pane = process.env.TMUX_PANE
mcpCommand({ run: harnessRunner(SCRIPT_PATH), inPane: !!pane && !!paneOwner(pane) }).then(code => { process.exitCode = code }).catch(onError)
diff --git a/docs/design/2026-10-28-machine-mcp-servers.md b/docs/design/2026-10-28-machine-mcp-servers.md
index 13e6dd5fe..33b17c81e 100644
--- a/docs/design/2026-10-28-machine-mcp-servers.md
+++ b/docs/design/2026-10-28-machine-mcp-servers.md
@@ -59,7 +59,10 @@ harness mcp-servers remove lamp
## Who may change it
-Only the person. An agent (`model.ts` `outsideCaller`: Claude Code, Codex, `AI_AGENT`) is refused with exit 5, with no
+Only the person. An entry's command runs at every matching launch with no prompt (`--mcp-config` servers start without
+Claude Code's project-server question), so `mcp-servers.json` is as trusted as the person's shell startup files. An agent (`model.ts` `outsideCaller`: Claude Code, Codex, `AI_AGENT`), or anyone in a pane a Harness daemon made
+(`paneOwner(TMUX_PANE)`, as `harness mcp` asks; a person's own terminal pane there is refused alike and told to run it
+outside Harness), is refused with exit 5, with no
`--person-said-yes` way round, because an entry runs a command inside every later agent on the machine. Listing is open
to anyone on the machine. The lamp holds its own limits: a Harness-started agent gets exactly the grants the lamp's
owner gave that computer, a body lease the person always wins back, and the lamp's rates and quiet hours.