What changed: accc8c090 took Claude Code's names for a server's own
OAuth app (oauth.clientId, clientSecret, callbackPort) but sent
redirect_uri=http://127.0.0.1:<port>/callback. Claude Code sends
http://localhost:<port>/callback:
- code.claude.com/docs/en/mcp, "Use pre-configured OAuth credentials":
register http://localhost:PORT/callback; --callback-port fixes the
port to match it. Its version note says 2.1.229 sent 127.0.0.1 and
servers that match the registered URL exactly refused the sign-in,
so 2.1.231 went back to localhost.
- The installed Claude Code 2.1.296 binary builds
`http://localhost:${n}/callback` (default port 3118 / a random
free one, MCP_OAUTH_CALLBACK_PORT) and listens on 127.0.0.1 only.
So an app registered for Claude Code at an exact-match server was
refused by magpie. StartWith now sends localhost for a user's own app
and still listens on 127.0.0.1 alone, as Claude Code does, so the hosts
don't differ and the editor needs no note. magpie's own dynamic
registration keeps 127.0.0.1 (it registers that URL itself).
The no-registration error, the editor's hint (now
http://localhost[:port]/callback), its zh/zh-TW/ja/de translations,
the OAuthApp comment and docs/subsystems/library.md say localhost.
Run:
- New TestAppMadeForClaudeCode: the GitHub-shaped fake matching one
exact registered URL http://localhost:<port>/callback, at authorize
and at the token request. With the old mcpauth.go it fails (as do
the three GitHub tests now asserting localhost); with the fix all
pass. go test -race ./internal/mcpauth/...
- go test -tags nogui ./internal/library ./internal/gui
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
- GUI mcp-oauth-app (Chromium+WebKit, 1100/390, en zh zh-TW ja de,
22/22) and i18n-keys; with the hint's old 127.0.0.1 put back by hand,
mcp-oauth-app goes red (0/11 Chromium).
Not run: a real sign-in with a real OAuth app (none to use). GitHub's
docs say a loopback redirect needn't match the registered port but
don't say whether that holds for localhost as it does for 127.0.0.1;
if GitHub wants the port, the user sets Callback port and registers
http://localhost:<port>/callback, as Claude Code's docs also say.
What changed: GitHub's remote MCP server (api.githubcopilot.com/mcp/)
points to https://github.com/login/oauth, whose metadata has no
registration_endpoint, so magpie's sign-in, which always registered
itself (DCR), could never sign in to it. A server now carries an
optional OAuth app, `oauth: {clientId, clientSecret, callbackPort}`,
Claude Code's names for --client-id/--client-secret/--callback-port
(oauth.clientId in its .claude.json). mcpauth.StartWith signs in as
that app without registering: PKCE S256, a loopback callback
http://127.0.0.1:<port>/callback (any port unless callbackPort is set),
client_secret_post with a secret (basic only when the server lists
basic alone), "none" without one.
Without an app, a server with no registration endpoint now fails with
mcpauth.ErrNoRegistration, which says to make an OAuth app with the
vendor (GitHub's under Settings > Developer settings > OAuth Apps, with
http://127.0.0.1/callback) and give it under "OAuth app" in the editor.
The editor opens those fields with Client ID focused when that error
comes back. Filling them makes Sign in read "Save and sign in", and
Cancel asks before dropping them, as the earlier Cancel fix does.
GitHub answers token errors with 200 and {"error": ...}; tokenRequest
now reads a 2xx body with `error` as the error, and bad_refresh_token /
incorrect_client_credentials count as a dead sign-in as
invalid_grant/invalid_client do.
Secrets: the client secret sits in library.json like header and env
values. A backup without keys blanks it; WithSecrets puts this
computer's secret back only for the same client ID. No agent file is
given the app. The TUI editor, which doesn't show it, keeps it on save.
check() keeps it only on an HTTP server, requires a client ID when a
secret or port is given, and a port 1-65535.
Run (worktree at 98b5a02d1 + the two earlier commits):
- go test -race ./internal/mcpauth/... (new github_app_test.go: an
httptest fake built from GitHub's real PRM and AS metadata bytes:
no app -> ErrNoRegistration, sign-in as the app, wrong secret, fixed
callback port, bad refresh token)
- go test -tags nogui ./internal/library ./internal/tui ./internal/gui;
go test ./internal/gateway -run MCP
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
- GUI, Chromium and WebKit, 1100/390, en zh zh-TW ja de:
mcp-oauth-app (new, 22/22), mcp-editor-cancel, mcp-signin,
mcp-signin-health, library-mcp-health, i18n-keys - all pass
- Broken by hand, each went red: no 2xx error parse, GitHub codes out
of dead(), app ignored in StartWith, secret not blanked / not matched
by client ID in carry, check() without the non-HTTP rule; in the GUI,
oauth left out of the save, and the failed hook not opening the fields.
- Sandbox HOME, rebuilt magpie web, against the real GitHub server:
Sign in showed the new error and opened the fields; Save and sign in
saved the app and produced a real github.com/login/oauth/authorize
URL with the app's client_id, S256 and a 127.0.0.1 redirect, which
GitHub answered with its login page. .claude.json didn't hold the app.
Not run: a real GitHub sign-in to completion. There's no real OAuth app
to use, and I didn't make one on the owner's account. Claude Code's
callback says localhost where magpie's says 127.0.0.1, so an app made
for Claude Code needs its callback URL changed; that isn't bridged.