Repository navigation
feat(harness): Reach cursor-agent's MCP through its own config file - #1024
Conversation
0d53176 to
0f3776d
Compare
omesser
left a comment
There was a problem hiding this comment.
Architect review — NOT CLEARED (NEEDS CHANGES)
Tip: 0f3776d6138d2ccd5a9681f15205e0ace4658dbb · CI green (ubuntu / macos / windows) · MERGEABLE/CLEAN
Scope: cursor-agent ignores session/new mcpServers (#1020). This PR adds a tokenless unix-socket MCP transport, writes <cwd>/.cursor/mcp.json, runs cursor-agent mcp enable ai-buddy, and hides the file via .git/info/exclude.
Effort is high. Approach is not crisp. Four mechanisms where one preferred path should decide.
Hard
-
Sock route is the wrong escalate. #1020’s own kill-table says an HTTP entry in
.cursor/mcp.jsonWorks. Rejection was token-at-rest + ephemeral-port approval-hash churn — both solvable without a unix socket (stable loopback URL; tokenless loopback analogous to 0600 sock; or Cursor-side${env:…}on HTTP headers). Sock adds a second transport, a hand-rolled HTTP/1.1 client (post_unix), unique path maintenance, and explicitly leaves Windows with no tools. If we are editing config anyway, keep MCP over HTTP so it works cross-system. Unique sock paths are not excusable here. -
Git exclude is out of scope and must be cut. Harness cwd is already well-defined (
AI_BUDDY_HARNESS_CWD/ Working directory →AttachCwd). If CLI-only isn’t enough, add/edit mcp config there. Git does not come into it.exclude_for(linked worktree /commondir),add_line/remove_line, and thegit status --porcelaintests are complexity for a cosmetic “don’t show in status.” No special git treatment. No test/verification config belonging in a user repo. -
Approach is not crisp. Actual stack: unix sock server + shim
--sock+ mcp.json merge/remove +mcp enableCLI + git exclude. Preferred order to re-decide, measured:- (a) CLI-only if a real Cursor CLI path can register+approve without file mutation;
- (b) else edit mcp config in harness-cwd only, prefer HTTP entry;
- (c) sock only if (b) is proven impossible — with that proof in the PR body, not implied.
Soft
-
File edit +
enablemay both be required — say so, don’t invent. Cursor docs:mcp enableadds to a local approved list; mcp.json has no documentedenabledboolean. So dual path can be justified as Cursor’s two stores (definition vs approval). The PR never states that crisply, and still owes a sentence on why writing the approval store directly (or--approve-mcps, already measured no-op underacp) isn’t enough. Justify or cut one. -
Windows gap as “said in docs” is not an answer if HTTP-in-config is on the table. Shipping a cursor-agent path that is unix-only while windows CI is green is a product hole, not a platform footnote.
-
Detach / merge hygiene is good (foreign servers preserved, unparsable left alone, remove only what install recorded). Keep that shape under whatever transport/config path survives.
Required rewrite shape
- Cut all
.git/info/excludemachinery and its tests. - Re-ground on harness-cwd mcp config; prefer
type: httpagainst the existing loopback endpoint (stabilize URL/approval hash without a sock). - Keep
enablebeforeacpspawn only with an explicit “two Cursor stores” rationale. - Sock +
--sockonly with a short measured proof that HTTP-in-config cannot meet no-secret-at-rest + stable approval id and Windows. - Re-ADR only after the transport choice is settled; don’t extend ADR-0026 to bless a path we are about to delete.
Verdict: NOT CLEARED. Rewrite before any approve.
— Cursor agent (Architect), on @omesser's behalf.
098eb7a to
f130894
Compare
omesser
left a comment
There was a problem hiding this comment.
Architect re-review — CLEARED
Tip: f13089425a8411504b50c906e3946a2c4133291f · CI green (ubuntu / macos / windows; deploy skipped) · MERGEABLE/CLEAN
Prior tip: 0f3776d6 was NOT CLEARED (sock + git exclude + dual-path fog).
Against the hard rewrite ask
| Ask | Tip f1308942 |
|---|---|
Cut unix sock / shim --sock |
Done. mcp_http.rs and crates/mcp-server are unchanged vs main (compare shows 0 hits on those paths). |
Cut .git/info/exclude |
Done. No exclude machinery in the six-file diff. |
| Prefer HTTP in harness-cwd mcp config | Done. Attach merges {"url", "headers": {"Authorization"}} into <cwd>/.cursor/mcp.json against the existing loopback endpoint. |
Justify file edit + mcp enable, or cut one |
Done, measured. PR body + cursor_mcp.rs module docs: CLI has no add; enable only approves a server already in mcp.json. Writing mcp-approvals.json directly was weighed and rejected (undocumented hash). |
| Windows not a footnote | Done. Same HTTP path on every platform; windows check green. |
| No repo/VCS entanglement | Done. Docs explicitly leave .cursor/ to the project. |
Approach is now the preferred (b) path from the last review: harness-cwd HTTP config + documented two-store enable. Sock is gone rather than blessed.
What held / what is soft
- Detach / merge hygiene stays good: foreign servers preserved, unparsable left alone,
Installedtracks created dir/file, remove only what install recorded, nomcp disable(would block next attach). - Token-at-rest is the real remaining cost, named honestly (0600 on unix, project ACL on Windows, per-run token, detach cleanup). Acceptable for CLEARED given the measured
${env:…}HTTP-header non-interpolation and the Windows sock gap that forced this trade. - Soft (non-blocking): module docs say
enableis "dropped when the entry has not changed";install_cursorstill always callsenableafter install. Within one app run that is ~380ms idempotent, not a skip — fix the sentence or the code later. - Soft (non-blocking): env-var table still says
AI_BUDDY_MCP_URL/TOKENare "Never written to a file"; the cursor-agent path writes the token value into mcp.json (ADR-0026 appendix covers the exception). Worth a one-line hedge in DEVELOPMENT.md when convenient. - Branch is 1 commit behind
main; mergeable_state is stillclean.
Verdict
CLEARED at tip f1308942. Architect does not merge — waiting on Oded’s explicit yes.
— Cursor agent (Architect), on @omesser's behalf.
omesser
left a comment
There was a problem hiding this comment.
Architect review — CLEARED
Tip: f13089425a8411504b50c906e3946a2c4133291f · CI green (ubuntu / macos / windows + build) · MERGEABLE/CLEAN
Refactors off the unix-sock design onto the same loopback HTTP + bearer every other HTTP harness gets, written into <cwd>/.cursor/mcp.json then approved with cursor-agent mcp enable ai-buddy. That matches the four hard gates:
- Dual path justified — Cursor has no
mcp add; define = mcp.json, approve =mcp enable. CLI-only cannot inject the endpoint. - HTTP entry —
{"url", "headers":{"Authorization":"Bearer …"}}; sock /serve_unix/--sock/Transportgone;mcp_http/mcp-serverbyte-identical to main. - No VCS meddling —
.git/info/excludedeleted; config is harness-cwd only. - Windows — install/enable are cross-platform; only
0o600is unix-gated. Not a tools gap.
Token-at-rest (0600 / per-run / detach cleanup / Windows ACL gap) is the deliberate ADR-0026 reversal already re-weighed — not a clearance blocker.
Soft nits only (non-blocking): module doc says enable is “dropped” when unchanged but harness always invokes it; env-table “Never written to a file” vs this path; unix-only enable fakes.
Do not merge without Oded’s explicit yes.
— Cursor agent (Architect), on @omesser's behalf.
omesser
left a comment
There was a problem hiding this comment.
Architect review — CLEARED
Tip: f13089425a8411504b50c906e3946a2c4133291f · CI green (ubuntu / macos / windows) · MERGEABLE/CLEAN
Scope: force-push rewrite of #1024. Prior tip 0f3776d6 was NOT CLEARED (sock + git exclude + uncrisp stack). This tip deletes both sock halves and all .git/info/exclude handling, and hands cursor-agent the same loopback HTTP URL + bearer as every other HTTP-capable Harness via <cwd>/.cursor/mcp.json + cursor-agent mcp enable ai-buddy.
Prior Hard — disposition
- Sock route — gone. Tip file list vs
main:README.md,docs/DEVELOPMENT.md, ADR-0026,src-tauri/src/cursor_mcp.rs(new),harness.rs,main.rs. Nomcp_http/mcp-serverdelta. Entry shape is{"url", "headers":{"Authorization"}}. Windows gets tools. - Git exclude — gone. No exclude code, fixtures, or tests. Docs: “ai-buddy does nothing about the user's VCS.”
- Approach crispness — landed on (b). Measured: no
mcp add→ CLI-only (a) cannot define a server. HTTP-in-harness-cwd mcp.json +enableis the path. Sock (c) deleted with the Windows/maintainability trade stated in the PR body and ADR appendix.
Oded’s four-point critique
- Prefer CLI-only — dual path is justified as Cursor’s split (define in mcp.json / approve via
mcp enable; noadd). Stated in module docs, PR body, DEVELOPMENT, ADR. Not inventing two stores. - Prefer MCP-over-HTTP — yes. Same ADR-0023 loopback + bearer; no unique sock routes.
- Harness-cwd, no special git, no repo mcp config — yes.
install_cursorusesself.cwd(AttachCwd←AI_BUDDY_HARNESS_CWD/ Working directory) beforeacpspawn. No committed test/verification mcp.json. No git treatment. - Merge — Architect does not approve or merge. Still needs Oded’s explicit yes.
Soft (do not block CLEARED; fix when convenient)
- Module-doc lie on enable-skip.
cursor_mcp.rsclaims ``enableis … dropped when the entry has not changed, so a second attach in one app run is free.'' Wiring does not:install` skips rewrite when JSON-equal, but `Session::install_cursor` always calls `enable` after a successful install (~380ms spawn every respawn). PR body is honest (“adds no second approval”). Fix the module doc, or return a `changed` flag from `install` and skip `enable` when false. - Token-at-rest in project cwd — accepted and documented (0600 unix; dies with app run; detach removes). Crash/kill without
shutdownleaves the entry until a later attach/detach. Stated risk, not a rewrite trigger. - Ephemeral URL/token → approvals churn — ~31 bytes/id/app-run in
mcp-approvals.json, no prune;disablecorrectly avoided. Honest cost of sharing the per-run HTTP endpoint. - Windows ACL gap —
restrictis a no-op off-unix; file keeps project ACL. Named in DEVELOPMENT. Acceptable now that Windows actually gets tools. - Branch / history naming — title is correct; branch still
feat/1020-cursor-agent-mcp-socket; sock-era commits remain in PR history though tip tree is clean. Cosmetic.
Hard
none
Verdict
CLEARED at f13089425a8411504b50c906e3946a2c4133291f. Prior Hard blockers are satisfied. Soft items above are docs/hygiene, not blockers.
Do not merge without Oded’s explicit yes. Architect clearance is not merge authority.
— Cursor agent (Architect), on @omesser's behalf.
…at transport Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… acp spawn Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… Windows stands Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The unix socket answered a no-secret-at-rest constraint that has been
re-weighed against maintainability and the Windows gap. cursor-agent now
gets the same loopback URL and bearer token every HTTP-capable Harness
gets, written into `<cwd>/.cursor/mcp.json` at mode 0600 because the
config file is the only way to reach it.
That deletes both halves of the second transport: `serve_unix` and
`Endpoint.sock` in the app, and `--sock`, `post_unix` and the `Transport`
enum in the shim, which is no longer on this path at all. It also deletes
the `.git/info/exclude` handling: ai-buddy writes a config in the cwd it
was given and what the project's VCS does about it is not its business.
Measured against cursor-agent 2026.01.23-916f423: `mcp list-tools`
returns all seven tools over the real endpoint; `${env:NAME}` is not
interpolated in an HTTP entry's `headers`, so the token is a literal;
`mcp enable` is ~380ms and adds no second approval for an unchanged
entry.
662 deletions, 240 insertions against the previous head.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The module doc claimed `enable` is dropped when the entry has not changed. `install_cursor` calls it unconditionally after a successful install, so a respawn pays the ~380ms every time. Approving twice is harmless rather than wasteful-and-wrong: an unchanged entry hashes to the id Cursor already holds, so no second approval is recorded. Documented instead of gated, because always approving survives a user who cleared their approvals and a conditional skip would not. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
b51ce19 to
872411a
Compare
omesser
left a comment
There was a problem hiding this comment.
Architect re-review — CLEARED
Tip: 872411abe85b49eecc830fbdc61f2414f28d717c · CI green (ubuntu / macos / windows + build; deploy skipped) · MERGEABLE/CLEAN
Prior CLEARED tip: f1308942.
Delta since prior clearance: one docs commit (docs(harness): Say that enable runs every attach, because it does) plus rebase onto current main. Tree vs main is still the same six files; mcp_http / mcp-server delta remains 0.
Soft #1 from prior review
Module doc no longer claims enable is dropped when the entry is unchanged. It now matches wiring: rewrite skips when JSON-equal; enable runs every attach (~380ms); approving an unchanged entry adds no second id. Soft #1 closed.
Hard gates (unchanged)
HTTP in harness-cwd mcp.json + mcp enable; no sock; no git exclude; dual path still Cursor’s define/approve split. No regression.
Remaining soft (non-blocking): DEVELOPMENT.md “Never written to a file” hedge; token-at-rest / approvals churn / Windows ACL / branch name.
CLEARED at 872411a. Do not merge without Oded’s explicit yes.
— Cursor agent (Architect), on @omesser's behalf.
Why
cursor-agent acpignores themcpServerswe hand it onsession/new, so every attach to it has run with no ai-buddy tools while the Harness tables said otherwise. Measured: its ACP handler never reads the field, and it loads servers only from an approved.cursor/mcp.json.It gets the same loopback URL and bearer token every HTTP-capable Harness gets (ADR-0023). The only difference is how it is handed them: written into its own config file, because that is the only channel it reads.
Why two mechanisms
Cursor splits the job in two and neither half does the other's.
.cursor/mcp.jsonis the only place a server can be defined.cursor-agent mcp --helplistslogin,list,list-tools,enable,disable. There is noadd.cursor-agent mcp enableis the only way to approve one, documented as "Add an MCP server to the local approved list" for a server already "configured in .cursor/mcp.json or ~/.cursor/mcp.json".So attach writes the file and then runs the CLI. That split is Cursor's design; ai-buddy obeys it rather than inventing it. The one alternative is writing
~/.cursor/projects/<slug>/mcp-approvals.jsonourselves, which drops a ~380ms spawn in exchange for depending on an undocumented file and reproducing a sha256 the vendor can change in any release. Not worth it against a documented CLI call that already works.What changed
Attach, in this order, before
cursor-agent acpis spawned, because approvals are read once percursor-agentprocess:{"url": …, "headers": {"Authorization": "Bearer …"}}undermcpServers."ai-buddy"in<cwd>/.cursor/mcp.json, beside whatever the user already has. A file that does not parse is left alone and the attach goes on without tools.chmod 600. The file now holds a live credential.cursor-agent mcp enable ai-buddyin the same directory.Detach removes our entry, and the file and directory when attach created them.
New module
src-tauri/src/cursor_mcp.rsowns that.mcp_http.rsand the shim crate are untouched — the shim is not on this path at all.Per-run, not one-time. The URL and the token are both new every app run, so the entry is rewritten and re-approved on each attach. That is the honest shape and the docs say so. It is the price of
cursor-agentusing the same transport as everything else. Within one app run the entry does not change and a re-attach costs only the spawn.What was deleted, and why
662 deletions against the previous head, 240 insertions. The PR went from 8 files / 989 additions to 6 files / 489 additions.
The unix socket transport, both halves.
serve_unixandEndpoint.sockinmcp_http.rs, and--sock,post_unixand theTransportenum incrates/mcp-server. Both files are now byte-identical tomain. That existed to keep the token off disk; the constraint was re-weighed against maintainability and the Windows gap and did not survive. A hand-rolled HTTP/1.1 client over a unix socket was the cost, andcursor-agenton Windows getting no tools was the cost, and neither is worth paying now.The
.git/info/excludehandling. ai-buddy writes a config in the cwd it was given. What the project's VCS does about it is not ai-buddy's business. Gone with its three tests and its git fixtures.Measured, against
cursor-agent2026.01.23-916f423End to end with the real code, no GUI and no stub agent. A temporary
#[ignore]probe incursor_mcp.rsstarted the app's realmcp_http::serve, called the realinstallandenable, then asked the real CLI what it could see. The probe is not in this diff.${env:NAME}is not interpolated in an HTTP entry'sheaders. An earlier round measured this on a stdio entry'senvblock; this is the other code path and it behaves the same. WithAI_BUDDY_MCP_TOKENexported intocursor-agent's own environment, the server received the literalBearer ${env:AI_BUDDY_MCP_TOKEN}and answered 401. Cursor's docs listheadersamong the interpolated fields, so this is a vendor mismatch. It is what forces the token to be a literal, and it closes the route to a stable entry.mcp enabletakes 372-511ms, three runs, and adds no second approval for an unchanged entry.~/.cursor/projects/<slug>/mcp-approvals.json, about 31 bytes each.cursor-agent mcp disabledoes not prune them; it marks the server never to load again, which would break the next attach, so detach does not call it.cursor-agentinstalls natively on Windows (irm 'https://cursor.com/install?win32=true' | iex), which is why the socket's Windows gap was a real gap and not a theoretical one.Unit coverage in
cursor_mcp.rs: a foreign server surviving a merge, an unchanged entry not rewriting the file and a new token rewriting it, the file being 0600 even when it was 0644 before, an unparsable file erroring and staying byte-identical, remove leaving a user's file and server alone, remove leaving no token on disk, andenableinvoked once in the cwd.The risk that remains
While a session is attached to a user-set Working directory, a live token sits in that project's
.cursor/mcp.json. It is owner-only on unix, it dies with the app run, and it authorises the seven tools and nothing else. Detach removes it. On Windows there are no mode bits to set there and the file keeps the project directory's ACL. Stated rather than engineered around.Notes
docs/DEVELOPMENT.mdcarries the operator-facing version of all of this, ADR-0026 records the decision, and the README's Harness table row now readshttp, through its own config.ADR-0026 said the endpoint goes in the environment and not a file, and named permissions, staleness and cleanup as what reversing it would cost. This is that reversal, scoped to one Harness, with all three paid: 0600, a per-run token, and removal on detach.
Closes #1020
🤖 Generated with Claude Code
— Claude Code agent, on @omesser's behalf.