Files
magpie/internal/claudebridge
yetone cb25d3861b gateway: a Claude subscription's tool calls reach their run on a MAGPIE_ADDR that isn't loopback (#1546, jiayeZhu)
With MAGPIE_ADDR pinned to a concrete address outside 127/8 and gateway
keys on, the Claude subscription bridge's MCP helper posted its tool
calls to http://<that address>/_magpie/claude-mcp/<token> with no key.
lanGuard answered 401, the call never reached the run, and every turn
of tool results found "no run waiting" and started a new Claude Code
told the whole conversation; the reporter's cache hits fell from ~95%
to ~30%.

- lanGuard lets that callback in by its run's own token: a POST to
  /_magpie/claude-mcp/<token> whose token (24 random bytes) is one a
  live run registered (addCallback in startRun, dropCallback in
  removeRun), compared in constant time. No path is exempt on its own:
  an unknown, ended, truncated, extended, percent-encoded or GET form
  is still asked for a key, and so is every other route.
- The helper is handed the callback URL in a 0600 file in the run's
  own temp dir rather than as an argument; RunMCP reads a path as that
  file. The test fakes read it from there.
- docs: claude-subscription-bridge, gateway-routing's HTTP surface and
  reference.md's network section say how the callback is let in.

Run:
- TestClaudeToolCallbackOnANonLoopbackAddress (new): a gateway behind
  lanGuard on this machine's own non-loopback IP, MAGPIE_ADDR set to
  it, fake Claude Code making a real helper call; red on the old guard
  with the reporter's "refused POST /_magpie/claude-mcp/... no API key
  was sent" line, green now.
- TestOnlyALiveRunsCallbackSkipsTheKey (new) and
  TestNetworkGatewayGuardsEveryRoute (now also tried with a live run's
  token as a Bearer key): red with a blanket path exemption put in by
  hand, green now.
- Real use: sandbox HOME, magpie serve on MAGPIE_ADDR=10.0.0.111:3561
  with a gateway key, a fake claude driving the real claude-mcp-helper.
  origin/main: callback refused, "tool results no run waiting", a new
  Claude Code told the whole conversation. This build: the result
  reached the same process (pid unchanged), nothing refused, a made-up
  token still 401.
- go test -tags nogui ./... (full suite), gofmt -l, GOOS=linux and
  GOOS=windows go vet -tags nogui on internal/gateway and
  internal/claudebridge.
2026-10-11 05:50:04 +08:00
..