Skip to content

Give Grok and the open agents Harness Relay's own tools below full access, over a loopback HTTP MCP endpoint #88

Closed

Description

@cyyeh

What problem would it solve? · 想解決什麼問題?

Harness Relay's own tools (browser, mail, calendar, through the gateway's relay MCP server, #84) reach Grok and the five open agents (OpenCode, Goose, Cline, OpenHands, Pi) in full access only (GATEWAY_FULL_ACCESS_ONLY, PR #87).

Each turn's program (gatewayShim.ts) and its one-turn token are written to data/tmp. Below full access that folder is a protected path: the commands an agent runs (a repository's script, something a page talked it into) must not read the token. Otherwise a command could drive the user's mail or browser without the agent's call ever showing in the chat; read-tier calls run without asking.

Claude Code, Codex and Copilot start their MCP servers outside the sandbox that holds their commands, so the program can read the token and the commands cannot. Grok's own sandbox, and Harness Relay's own sandbox around the open agents, hold the MCP servers they start together with their commands. Opening data/tmp to the program would open it to every command too, and the relay sandbox does not open the gateway's socket either.

Grok 與開源 agent 只有在完全存取時才拿得到 Harness Relay 自己的工具。原因是它們的沙箱把指令和 MCP server 裝在一起:讓工具程式讀得到每一回合的權杖,指令也就讀得到。

What would you like it to do? · 希望它怎麼做?

Give the gateway a second transport: a streamable-HTTP MCP endpoint on 127.0.0.1. The CLI gets the per-turn token only in memory, as a header of the MCP server it is given, never in a file or an environment variable that a command could read.

  • Grok: the connection would come from Grok's own process, not from inside its sandbox, so no sandbox opening is needed, if Grok advertises mcpCapabilities.http (its adapter already checks for it).
  • The open agents: the whole process runs in the relay sandbox, so that run would need an opening to the gateway's port alone (asked for by each adapter for its own CLI, as connectPorts is). The token must stay out of the config files an adapter writes:
    • OpenCode, Goose and OpenHands report mcpCapabilities.http in their recorded messages;
    • Cline reports none, and Pi does not use ACP, so each needs a way of its own or stays full-access only.
  • What stays the same:
    • the tiers: read runs; act is asked about below full access; send waits in the outbox;
    • the token per turn, revoked when the turn ends;
    • the connection limits;
    • loopback only;
    • the same checks as the socket.

Scope, in two steps · 範圍:分兩步

Not every CLI should move. The question for each one is where the token would live once it uses HTTP:

CLI How it is given its MCP servers now Where the token would live over HTTP Plan
Grok, OpenCode, Goose, OpenHands ACP session params Memory only Step 1 (this issue): today they get no tools below full access
Copilot, Cursor, Antigravity, Muse Code ACP session params Memory only Step 2, once step 1 is proven with the real CLIs
Codex app-server thread config (over stdin) Memory only Step 2
Claude Code --mcp-config file A file Stays on the stdio program
Cline, Pi No usable HTTP MCP (none recorded for Cline; Pi's would put the token in an environment variable) — Stays full-access only

Why step 2 is worth it

  • No Node.js needed: today every turn starts the program with Node.js. Without one (the desktop app, and on Windows Settings cannot install one), the tools are unavailable (no-node, no-node-path). A CLI that connects over HTTP needs no program and no Node.js.
  • Safer on Windows: Windows has no protected paths, so the token sits in a file until the program claims it, and a CLI that restarts its MCP server mid-turn loses the tools (claimOnce). A token held in memory has neither problem.
  • One process fewer per turn.

Why Claude Code stays

  • Its MCP config is a file, so the token would sit in that file.
  • On macOS and Linux the file could live in the protected data/tmp, which is as safe as today.
  • On Windows the file would be readable for the whole turn, which is worse than today's token that serves one connection and is deleted at once.

Alternatives you considered · 考慮過的其他做法

  • Opening data/tmp to those sandboxes: this lets every command an agent runs take the token and use the tools unseen. Rejected.
  • The token in the MCP server's environment: other processes of the same user can read it (/proc/<pid>/environ on Linux), and AGENTS.md rules it out.
  • Leaving it as it is: full access only, as now.

Checks needed

  • Each CLI must be tried for real (live tests): this cannot be checked with the e2e fakes alone.
  • Check that a command inside the sandbox cannot reach the token from the CLI's process.
  • The endpoint checks Host and Origin like the HTTP API (a web page in the user's own browser can reach 127.0.0.1), and Harness Relay's own browser tool refuses its port, as it refuses the server's.
  • Check Windows: the open agents run in full access only there, and Grok has no sandbox.

Area: Tools / skills / memory · 工具/skill/記憶; Agent CLIs.

Activity

  1. cyyeh commented on Nov 17, 2026

    @cyyeh
    ContributorAuthor

    Implemented in #87 (e9d21c8, b5a360e), for the CLIs that passed a check with the real CLI · 已在 #87 實作(e9d21c8、b5a360e),只給用真的 CLI 檢查通過的

    What is in · 做了什麼

    • The transport. The gateway also answers MCP's Streamable HTTP at http://127.0.0.1:<port>/mcp, with JSON (initialize, ping, tools/list, tools/call, batches).
      • The turn's token is in an Authorization: Bearer header of the MCP server the CLI is given over its stdin (ACP session params, Codex's thread config). No program, no file, no Node.js.
      • Refused unless it is a JSON POST of at most 4 MiB, with Host 127.0.0.1:<port> or localhost:<port>, no Origin, and a token granted for HTTP. A socket token is unknown on HTTP, and the reverse.
      • The same tiers and revocation as the socket. Harness Relay's own browser refuses the port.
      • Connections that have shown no token count apart (at most 256, the oldest giving way), and a request must come at once, so they cannot keep the CLIs out.
      • An act the user allows after the CLI stopped waiting (the request closed) is not done. Codex gets a turn's time for these calls (tool_timeout_sec), not its 5 minutes.
      • OpenCode names a call relay_<tool>; its own question about one is answered for the user, as the others' are. So no library server may be named relay or relay_….
      • A CLI that turns out to take no HTTP server gets the stdio program instead, made only then, and only where it could run.
    • A check for each CLI: npx tsx scripts/mcp-headers-check.ts <cli>.
      • It gives the real CLI, as it is signed in, a stand-in MCP server with a marker in its header: a new session, then a load (ACP), or a thread, a turn and a resume (Codex).
      • Then it lists every file the CLI wrote that holds the marker. A CLI joins GATEWAY_OVER_HTTP only once it passes.
    • The sandbox's side. scripts/sandbox-check.ts now checks that a command in Harness Relay's own sandbox cannot read its agent's memory. On Linux, /proc/<pid>/mem is refused in the sandbox, though the same read succeeds outside it (checked on a kernel without Yama; the check reports ptrace_scope; CI's Ubuntu job runs it). Not checked on macOS.

    Which CLIs · 哪些 CLI

    CLI Result of the check Now
    OpenCode 1.19.5 Every request had the header; no file held it after session/new and session/load Over HTTP, in every permission; below full access its sandbox opens it the gateway's port alone (connectPorts)
    Codex 0.169 Every request had the header; no file held it (rollout, SQLite state, logs) after a thread, a turn and a resume Over HTTP, no Node.js needed
    Copilot 1.0.112 session/new refused: "Authentication required" Not checked: keeps the stdio program
    Grok, Cursor, Antigravity, Muse Code Not installed here: their installers are their makers' scripts, and they need a sign-in Not checked: Grok in full access only; the others keep the stdio program
    Goose Not run here (its installer is a script). A loaded session starts again the MCP servers it was given (recorded), so it keeps their settings, headers included, in its session database, in a state folder its commands can read: inferred, not checked Full access only, until the check shows otherwise
    OpenHands Writes its MCP servers to mcp.json when it resumes Full access only
    Cline, Pi No HTTP MCP server that could be given so Full access only
    Claude Code Reads its MCP servers from a file Stdio program

    To move another CLI: run the check with it signed in. If it passes, add it to GATEWAY_OVER_HTTP in src/server/gateway.ts. For Grok, the fallback rule already keeps it from getting the stdio program below full access.

    Tests · 測試

    • Unit:
      • the HTTP endpoint and its refusals, the 413, connections without a token, an act whose caller left;
      • OpenCode's relay_<tool> and the reserved names;
      • the lazy stand-in;
      • HTTP without Node.js;
      • each CLI's grant options;
      • the ACP helpers' and Grok's handling of the stand-in;
      • OpenCode's connect-only ports.
    • End to end:
      • Codex below full access reaches the gateway over HTTP, its token in no argument;
      • OpenCode in full access now goes over HTTP;
      • OpenCode below full access in the sandbox, in read-only, its question answered with no card (macOS only, where OpenCode runs below full access).

    Still open · 仍待完成

    • The check for Grok, Copilot, Cursor, Antigravity and Muse Code, signed in.
    • A real CLI calling a gateway tool end to end (only the fakes do).
    • The memory check on macOS.

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions