Repository navigation
fix(mcp): Serve MCP from the app on loopback HTTP so a Harness's speak lands on screen (#470) - #491
Conversation
eded512 to
3f2706a
Compare
bdb3993 to
096aa2a
Compare
|
Rebased onto main, which changed what this needed in two ways a clean rebase hid. #497 landed on the same subject, making the app binary its own stdio MCP server when no sidecar is found. The two are halves of one thing and both restructured the same chooser, so the resolution keeps #497's launch shape and precedence byte for byte and puts the handshake decision above it. Precedence is now: a Harness that advertises the HTTP capability gets the app's loopback server with the live Instances, and anything else gets #497's chain of the environment override, then a sidecar, then the app binary re-executed. A session with no MCP server at all is no longer an outcome. Both routes were re-run for real. With the sidecar moved aside, hermes registered seven tools over the app binary's own stdio server and reached #505 renumbered the ADRs while this sat, which broke two things:
While renumbering I also rewrote the ADR against that guideline, which explicitly excludes file paths, type names and issue narrative from an ADR. It is now half the length and states the architecture: tools are dispatched inside the running app because the layer owning the Instances cannot exist outside the process, and the transport follows from that. The stub fallback is named as a consequence rather than buried. Verification after all of it: fmt, clippy with warnings denied, 299 tests in the shell and 455 in core, and every pre-commit hook including the ADR uniqueness one. — Claude Code, on @omesser's behalf. |
096aa2a to
9d3fdd9
Compare
9d3fdd9 to
2104c83
Compare
|
Rebased onto One conflict, in Nothing else needed resolving. Verification after the rebase: 326 tests in the shell, 454 in core, 23 and 2 in the smaller crates, 0 failed. Not re-run: the two live routes described in the comment above (hermes over the app binary's own stdio server, One thing to know for merge order. #501's branch turns the published — Claude Code, on @omesser's behalf. |
…k lands on screen The stdio server built its DispatchContext from stubs, so a `speak` from an attached Harness returned success and moved nothing. Dispatch now happens on the frame loop, where the Roster is.
2104c83 to
b05be5b
Compare
Closes #470 for the loopback path. A Harness's
speaknow reaches the buddy's bubble. #166 named this as its known blocker and #16 was closed on the promise to fix it.That is the exact string a real Claude Code process passed to
speak, drawn by the overlay. The shot is cropped to the bubble.The transport decision
The app serves MCP itself on loopback HTTP, and
ai-buddy-mcpstays the unchanged stdio fallback. #166 offered that or a shim that dials the app, and this is the smaller of the two: either way the endpoint has to live inside the app, because the roster is the handle the tools need and has no out-of-process form. Serving it directly needs no shim and no discovery file, since ACP'ssession/newalready carries a URL and headers.A plain listener and about two hundred lines rather than a web framework, because the specification permits a JSON response to a POST and nothing here streams. Recorded in the new ADR-0018, and ADR-0017's claim that there is no loopback server yet is replaced.
Security of the endpoint
127.0.0.1on an ephemeral port.Originheader is refused outright, so a browser cannot reach it.DebugnorSerialize, with a test that fails if either derive ever lands on it, so the token cannot reach a log by accident.What was actually observed, end to end
session/newon the wire carried that URL and anAuthorizationheader.claude -pagainst that URL and token listed the live roster, returning the same Instance id the app's own traces use rather than the empty stub one, then calledspeak.Two honest limits
speakis gated by the permission click, by design. In the first run the attached Harness did call it, and the request was held with no Chat surface on screen until the turn timed out. Only a click there may answer, per ADR-0003 and ADR-0010, and a click cannot be scripted. So the tool surface is provably reachable by the attached Harness; answering it is the user's. The on-screen proof went through the identical endpoint, token and dispatch path from a second real process.speakthere still returns success and moves nothing. That is now said plainly in the binary's own header and in ADR-0018, and closing it is the shim that Attaching real harnesses: per-harness MCP client config for Claude Code, opencode, Hermes, Pi, and Grok #166 owns.How to verify
cargo test -p ai-buddy -- mcp_http:: harness:: acp_wire::36 tests, thirteen new: the protocol, the token, origin and method gates, the no-Debug guard, a real socket round trip, the wire shape, and a speak reaching a frame's dialogue.
cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace,cargo test -p ai-buddy-mcp-serverandpre-commit run --all-filesall pass.Notes for the reviewer
getrandom, already in the lock file, for the token. A clock-derived token is guessable.harness.rsand in ADR-0017. Clean against fix(harness): Cancel the turn in flight for a newer wake instead of refusing it (#472) #485 and fix(director): Say that a dead Harness reads a typed key at the next launch (#469) #482, checked by trial merge.— Claude Code, on @omesser's behalf.