What was wrong, reproduced in a sandbox HOME with mcpauthtest's fake OAuth
server behind a sandbox magpie:
- A server no agent has is checked only on a click (#1597). Clicked before
its sign-in it said "needs sign-in"; after signing in, the page rechecked
only servers in use, so the row kept that result beside the new "Signed
in" tag. The page now rechecks any server it has a result for once its
key (sign-in included) changed.
- The check sent magpie's token but never renewed it on a 401, so an
expired access token with a good refresh token read "needs sign-in"
beside "Signed in". checkHTTP now renews once and asks again, as the
gateway's relay does.
- A server that refuses even a just-renewed token was still "Signed in".
mcpauth.Rejected marks such a sign-in run out, from the check and from
the gateway's /mcp/<name> relay; ServerHealth.SignIn carries the status
back (only for a server magpie has a sign-in record for) and the row's
tag turns to "Sign-in ran out".
mcpauthtest.Fake gains RefuseTokens for the last case.
Run:
- go test -tags nogui ./internal/mcpauth/... ./internal/library
./internal/gateway (HOME and GOCACHE in scratch): ok.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows on the
touched packages: clean.
- New TestCheckRenewsMagpiesSignIn, TestCheckSaysSignInRanOut,
TestMCPProxyRefusedAfterRenewalRunsOut. Broken by hand: renewal removed
from checkHTTP, Rejected removed from the check, and from the gateway;
each went red.
- New mcp-signin-health.test.cjs: Chromium and WebKit, en/zh/zh-TW/ja/de,
1100 and 390 wide, 22/22. Each of the two library.js changes reverted
on its own: 0/11 in Chromium. library-mcp-health, mcp-signin and
i18n-keys pass.
- Sandbox repro before and after with the fake server: both cases now
show one tag; forget+revoke shows "Sign-in ran out · needs sign-in".
Not run: a real vendor's server refusing a renewed token; the fake stands
in for it.
What changed: serveMCP (magpie's own web-search and vision MCP servers)
and the signed-in MCP proxy (/mcp/{name}) read the body through
readMCPBody, which reads one byte past the limit and answers 413 when the
body is longer, or when Content-Length already says so. Before, a plain
io.LimitReader ended at the limit as if the body had, so a valid JSON-RPC
message padded with whitespace past the limit, or followed there by a
second message, was parsed as its prefix and run: an analyze_image call
reached the image model, and the proxy sent the cut body on to the
signed-in server with the user's token. A body exactly at the limit still
works.
Why: #1766 (ggbdpq) reported it for the two own MCP routes with a patch;
the proxy's read was the same shape and is fixed beside them.
Run: TestOwnMCPRejectsOversizedBody (the reporter's test, extended to a
known Content-Length too) and the new TestMCPProxyRejectsOversizedBody
fail on the old search_mcp.go/mcp.go with HTTP 200 instead of 413, the
image model called 1 -> 5 times, and the proxied server seeing the cut
"tools/call"; they pass with the change. TestMCPProxy*, TestVisionMCP*,
TestSearchMCP* pass. Full suite and vets are recorded on the push.
Not done: the GUI's local /api handlers decode JSON through LimitReader
too; they take only the first JSON value whatever the length and are
not reachable by another machine, so they are left as they are.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>