88b4c00ea11c8653cada22e11edf20ab1594de43
14
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
1a7aa76b4b |
mcpauth: an MCP sign-in canceled while its token is being fetched no longer saves the late token or replaces the server's sign-in (#1750, ggbdpq)
Cancel set the flow canceled, but a callback already trading its code
went on to write mcp-signins.json and call Changed when the token came
back, so a sign-in the user had ended was saved, and an existing
sign-in to that server was replaced. The callback's write now happens
under the flow's lock only while the flow is live (flow.keep), so
Cancel or the timeout and the commit can't both win; a commit that wins
still tells the agents before the flow says done.
ggbdpq's patch (46440adc), cherry-picked unchanged.
Run (reviewer): TestCanceledMCPCallbackDoesNotSave (real discovery,
registration, PKCE and loopback callback against mcpauthtest, the token
reply held until Cancel) fails on the old mcpauth.go in both cases
("saved credentials", "redistributed credentials 1 times") and passes
with it, -race -count=5; go test -race ./internal/mcpauth/... ok.
Not tried with a real MCP server's OAuth.
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
|
||
|
|
4537e92093 |
mcpauth: an assigned method magpie can do is checked to sign in and renew, both ways round (#1490)
The previous commit refuses at registration a method the server assigns that magpie can't send. The owner asked on #1490 that an assignment magpie can do be shown still to work; no test did. One now does, for the code exchange and a renewal after the access token is refused: - asked none, assigned client_secret_basic with a secret; - asked none, assigned client_secret_post with a secret; - asked client_secret_post, assigned none with no secret (a public client), which sends no secret; - asked client_secret_basic (the only one listed), assigned post. The fake's registration took an assigned method only when its metadata listed it, so "none" assigned to a server listing only post was turned away as invalid_client_metadata; a method the server assigns is one it supports, so with Assign set it is taken. Run (sandbox HOME, private GOCACHE): the new test and TestSignInRefusesAssignedSecretJWT, TestSignInBySecretBasic; go test -race ./internal/mcpauth/... and ./internal/library (which signs in through the fake) pass. Broken by hand: with register ignoring the response's token_endpoint_auth_method the new test fails at the first case ("the token endpoint answered 400: invalid_grant"); without the previous commit's check TestSignInRefusesAssignedSecretJWT fails ("the sign-in page was opened for a client magpie can't authenticate as"). Co-authored-by: ggbdpq <ggbdpq@gmail.com> |
||
|
|
c89a0f9d95 |
mcpauth: a server that registers magpie for a client authentication magpie can't do is said no at the registration
What changed: register took the registration response's token_endpoint_auth_method as it came. RFC 7591's response lets the server assign another of the methods it supports than the one asked for, and one assigned that magpie can't send (client_secret_jwt, private_key_jwt, tls_client_auth) opened the sign-in page all the same: the failure came at the code exchange, after the browser round trip, as "the token endpoint answered 400: invalid_grant", and every renewal would fail the same way. A method outside none, client_secret_post and client_secret_basic is now refused at the registration, before the browser is opened, with the request side's own wording. An assignment magpie can do (a server handing client_secret_basic and a secret for a client that asked none) still works as before. mcpauthtest.Fake gains Assign: a server that registers the client for another of the methods its metadata lists, giving a secret and taking the token endpoint's word for it. Without it set, the fake answers as it did. Run: - TestSignInRefusesAssignedSecretJWT (new) fails on the old register: "the sign-in page was opened for a client magpie can't authenticate as: http://127.0.0.1:…/oauth/authorize?…" — and passes now, Start saying the server registered magpie for client_secret_jwt, which magpie can't do. - go test -tags nogui -count=1 ./internal/mcpauth/... ok, every existing case unchanged; full go test -tags nogui ./... under a temp HOME ok except testenv's TestOffline, red the same on the untouched baseline (loopback proxy escapes this machine). - gofmt -l clean; go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet clean; go build, GOOS=linux go build -tags nogui, GOOS=windows go build ok. - Not tried against a real authorization server that assigns a method: none is known in the wild; this is the response-side half of #1490's class, set by RFC 7591. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> |
||
|
|
e0ecf01610 |
mcpauth: an MCP server's own OAuth app is called back at Claude Code's http://localhost:<port>/callback, so an app made for Claude Code signs magpie in as it is (新v学员 on Discord)
What changed:
|
||
|
|
accc8c0903 |
library: an MCP server whose sign-in has no client registration (GitHub's) is signed in to as the user's own OAuth app (新v学员 on Discord)
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
|
||
|
|
eb1fab34c7 |
library, gateway: an MCP server magpie is signed in to no longer shows "Signed in" beside "needs sign-in" (新v学员 on Discord)
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. |
||
|
|
206dc085be |
provider: a magpie run from a terminal that only lists accounts no longer writes logins.json, and every change to it is made under a lock the gateway holds too, so a token the gateway just refreshed is never written back over (#1674, FaintGhost)
Every CLI command that reached Logins() (magpie ls, providers, sessions,
usage) ran rememberLogins, whose 30-second throttle (loginsSeenAt) lives
in the process, so in a new process it never held: each run moved Seen on
for the signed-in Codex and Claude accounts and wrote logins.json back.
loginsMu was an in-process mutex, so that read-modify-write could
interleave with the gateway's renewSavedLogin: the CLI reads, the gateway
writes a refreshed sign-in, the CLI writes what it read. Codex/OpenAI
refresh tokens are single use, so the account would be signed out.
- rememberLogins writes nothing when the only change is Seen and the saved
Seen is less than seenEvery (10 minutes) old (onlySeenMoved, comparing
with what was read, IDs and order normalised as writeLogins writes them;
sortLogins is split out of writeLogins for that).
- internal/filelock (new): davsync's TryLock/Unlock (flock; LockFileEx on
Windows) moved here and davsync uses it; Lock(path, wait) and
filelock.Mutex, a sync.Mutex that also holds the OS lock on a lock file.
A lock another magpie holds is waited for up to filelock.Wait (10s),
then gone on without, as before, so a stuck magpie never hangs others.
- loginsMu is a filelock.Mutex on logins.json.lock, so all 107 existing
Lock sites (every writeLogins is under one) are cross-process with no
change at the call sites. Taking it calls filememo.Look (new), so the
read under it isn't a parse filememo.Hold kept from before another
magpie's write. savedTokenMu holds logins.json.renew.lock the same way:
two magpies never refresh one saved account at once.
- Siblings: caller-keys.json (access.mu: magpie keys from the CLI vs the
window; a lost revoke would bring a key back) and mcp-signins.json
(mcpauth.fileMu, plus mcp-signins.json.renew.lock around renew, since
library's MCP check renews from the CLI too) get the same lock.
plugin-auth.json already has one (plugin-auth.json.lock, shared with
host.js). Not covered: providers.json (33 store sites with no
in-process lock either; user-entered keys, nothing refreshed there),
migrations.json/settings.json (no credentials), and the agents' own
files (~/.codex/auth.json etc.: the agent itself writes them without
any lock of ours, so a magpie-only lock can't make them safe).
Tests:
- TestReadOnlyRunLeavesLogins: Codex and Claude signed in, Seen a minute
old, file time set back; three "new processes" of Logins("")/codex/
claude/All() leave logins.json's bytes and mtime as they were. Seen an
hour old is written; Codex's own refresh is written at once.
- TestLoginsKeepAnotherMagpiesWrite: between this process's read and write
(beforeLoginsWrite hook) a second test process (TestLoginsOtherMagpie,
os.Args[0] -test.run) renews the saved work@ account's refresh token;
both the renewed token and this process's change are in the file.
- TestLoginsReadAfreshUnderLock: with filememo.Hold held, a write
filememo never heard of is seen by a read under loginsMu.
- TestLockAcrossProcesses (filelock): a holder subprocess makes Lock wait
and give up after its wait; killed, the lock is free; a Mutex holds it.
Broken by hand: onlySeenMoved bypassed -> TestReadOnlyRunLeavesLogins
FAIL "a run that only listed the accounts wrote logins.json"; the file
lock taken out of filelock.Mutex.Lock -> TestLoginsKeepAnotherMagpiesWrite
FAIL "the other magpie's renewed sign-in was written over"; Locked hook
emptied -> TestLoginsReadAfreshUnderLock FAIL. Each restored, green.
Ran: gofmt -l (nothing); go vet ./..., GOOS=linux go vet -tags nogui
./..., GOOS=windows go vet ./...; go build, GOOS=linux go build -tags
nogui, GOOS=windows go build; go test -tags nogui -count=1 ./... under a
temp HOME with pinned caches: all ok but internal/provider, whose
TestReadOnlyRunLeavesLogins failed at that point from its own fixture
(two rewrites of one size given the same mtime read as unchanged by
filememo); fixed in the test, then internal/provider, access, mcpauth,
filememo, filelock and davsync -count=1 all ok, and the three new provider
tests -race -count=10 ok.
Not tried: the reporter's Linux arm64 box with a real systemd gateway and
real Codex accounts; Windows (LockFileEx path) only vetted and built, not
run on the Windows box.
|
||
|
|
8902ec2179 |
library: a server that admits only the apps it lists says so at Sign in, and leaves the sign-in to each agent (#1619, Xichun123)
Figma's remote MCP server (mcp.figma.com/mcp) allow-lists clients by the client_name they register with: its registration endpoint (api.figma.com/v1/oauth/mcp/register) answered a plain registration named Magpie 403 with the bare body "Forbidden" (tried once, by hand). The Library's Sign in then showed "registering magpie with the server's sign-in failed (403): Forbidden", which reads as a fault to retry. magpie doesn't register under another client's name. A 401 or 403 from registration is now mcpauth.ErrClientRefused: the server's sign-in admits only the apps it lists and turned magpie away; the agents given it still have the server's own address, so each signs in itself (in Claude Code, /mcp). That address is what they already get while magpie isn't signed in (library.through), so Claude Code, a client Figma lists, signs in there with its own registration. The message is translated into zh, zh-TW, ja and de. Other registration failures keep their status and body. docs/subsystems/library.md says it. Run: TestSignInRefusedByAnAllowListLeavesItToTheAgents (new, through library.SignInServer against mcpauthtest serving Figma's 403 bytes) fails without the change with the reporter's exact "registering magpie with the server's sign-in failed (403): Forbidden", passes with it, and checks claude, codex and cursor keep the server's own URL. mcp-signin.test.cjs (Figma case added) passes in Chromium and WebKit, en and zh; gui-ja, gui-de, gui-zh-tw and i18n-keys pass. go test -tags nogui ./internal/mcpauth/... ./internal/library/ ./internal/gui/ ok under a temp HOME; gofmt -l clean; GOOS=linux and GOOS=windows go vet ok. Not tried: Claude Code's own /mcp sign-in to Figma (no Figma account here). |
||
|
|
89271cd4e8 |
provider, plugin, settings: accounts left all zero by a crash are read from their last good copy, and every state file is flushed before it is renamed in (#1505, Zhangwier)
Zhangwier's Windows machine went down hard, and logins.json (10783 bytes)
and plugin-auth.json (29926 bytes) came back at full length with every byte
0x00. Every account was gone. The rename had reached the disk before the
data. magpie then read "no accounts", and its next write would have made
that final.
What changed:
- Flushed before rename: steady.WriteFile writes a temp file, fsyncs it,
then renames it in. A failed write or flush removes the temp file and
leaves the old file as it was. edit.WriteAtomic, Kiro's writer, the
Codex session rewrite and the plugin host's writeDurable (host.js)
flush the same way. So do writePrivate (providers, logins, migrations),
settings, profiles, plugins.json, plugin-auth.json and mcp-signins.json.
- A last good generation: before each write, lastgood.Keep keeps the
valid file there as <file>.bak. A file that isn't valid is copied aside
as <file>.bad-<time>, with -2, -3 when two land in one second (O_EXCL),
and is never overwritten before that copy exists. The .bak lags one
write behind on purpose, since a crash zeroes the latest write.
- A failed read is unknown, never empty. On a cold start, logins.json,
providers.json, migrations.json, settings.json, profiles.json,
plugins.json, plugin-auth.json (Go and the host) and mcp-signins.json
are read from their .bak when they don't read. The recovery is logged
and listed in /api/state's recovered, and the window says it once in
every language. With no good .bak, a sign-out leaves plugin-auth.json
and mcp-signins.json as they are (the host's changeAuth no longer
writes {} over them). magpie's own sign-out returns the error, and a
sign-in copies the bad file aside before writing.
- caller-keys.json is flushed but never read from a .bak. A key revoked
in the last write would come back, so a store that doesn't read still
refuses every key, as its tests require.
ggbdpq's patch (f230bcae) is where the fsync-before-rename in
writePrivate, writeWhole and writeAuth came from. This change puts it in
one shared helper and reaches every other writer of magpie's state. The
JS write cleans up its temp file. The .bak recovery, the .bad copies and
the GUI notice are added here.
What was run:
- New tests, built from the literal case (10783 and 29926 zero bytes):
- internal/lastgood
- provider: TestZeroedLogins*, TestZeroedMigrations*,
TestZeroedProviders*, TestWritePrivateSyncsBeforeRename
- plugin: TestZeroedPluginAuth* against the real bun host,
TestPluginAuthSyncedBeforeRename with a plugin that makes fsync fail,
TestZeroedPluginList*
- TestZeroedSettings*, TestZeroedProfiles*, TestZeroedMCPSignIns*
- steady TestWriteFileSyncsBeforeRename, edit
TestWriteAtomicSyncsBeforeRename
- gui recovered-file.test.cjs (en/zh/zh-TW/ja/de, Chromium and WebKit)
- Broken by hand, each going red:
- Without the sync: the steady, edit, writePrivate and host fsync tests.
- Without the .bak fallback: every TestZeroed* test.
- The old changeAuth writes "{}\n" over the zeros.
- The old readLogins default.
- KeepBad without suffixes fails the one-second test.
- Without recoveredOnce, the GUI test fails 5/5.
- macOS: go test -tags nogui ./... in a sandbox HOME. The only failures
were the two access tests (then fixed by not recovering caller keys) and
TestProvidersCmdSaysUnreadable, which now removes the .bak to test the
no-backup case. Both packages were rerun and pass. gofmt -l prints
nothing. go vet, and GOOS=linux and GOOS=windows go vet -tags nogui, are
clean on the touched packages.
- GUI: recovered-file, whats-new, click-scroll, gui-de, gui-ja,
gui-zh-tw and i18n-keys pass.
- Windows box (cross-compiled test exes, sandboxed USERPROFILE/APPDATA):
lastgood, steady, provider, plugin (real bun host), settings, mcpauth,
edit and access pass. In profile, TestProfileSwitchesModelList and
TestOldProfileKeepsModelList fail the same on origin/main (filed as
#1517).
Reported-by: Zhangwier
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
|
||
|
|
c606da5f8b |
mcpauth: a server whose token endpoint takes a secret only by client_secret_basic is signed in to by it, whatever its metadata lists first (#1490, ggbdpq)
register took token_endpoint_auth_methods_supported[0] whenever the list
had no "none", and moved it to client_secret_post only when that was
listed. A server listing ["private_key_jwt", "client_secret_basic"] passed
the "magpie can do one of these" check and then had magpie registered for
private_key_jwt, which it can't do: the registration is refused
(invalid_client_metadata) or, if taken, the code exchange is. RFC 8414's
list has no order of preference.
What changed:
- register picks client_secret_post where listed, else
client_secret_basic, else says the server takes only what magpie can't
do, as before. "none" is still taken first.
- mcpauthtest.Fake gets AuthMethods: its metadata lists them, a
registration it can't honour without jwks or a certificate is refused,
a client registered for a secret is given one, and the token endpoint
checks it as registered.
Run:
- TestSignInBySecretBasic fails with the old register ("registering
magpie with the server's sign-in failed (400): invalid_client_metadata
... private_key_jwt") and passes now.
- go test -tags nogui ./internal/mcpauth/... ./internal/library/...
./internal/gateway/... under a temp HOME; gofmt -l; GOOS=linux and
GOOS=windows go vet -tags nogui.
- Not tried against a real authorization server that lists methods this
way; the reporter found none in the wild either.
Patch by ggbdpq in #1490, taken as is.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
|
||
|
|
21702d01ff |
Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows. * Makefile: know magpie's folder by its go.mod, so paths with spaces work The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs. * i18n: German for the strings main added since, with a parity test 75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system. * appdir: ignore relative folder variables when reading, keep them for children CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder. * Sandbox the tests main added since internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE. * agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over. * i18n: German for the Library's multi-select and System One's decision API The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes. * appdir: tidy the import into magpie's group; say what Go makes of /c/x The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x. |
||
|
|
778dc8dc41 | gui, mcp: Sign in in an MCP server's editor signs in to the server the form shows, saving it first, and a server that needs no sign-in is said to work as it is (lc on Discord: exa mcp 无法OAuth使用,x-api-key + key也无法使用 agent使用的是omp) — Exa signs in only at mcp.exa.ai/mcp?login (401 with resource_metadata, auth.exa.ai, S256, dynamic registration); plain /mcp answers without one. Sign in sent only the name, so the backend probed the saved URL: a URL just changed to ?login, unsaved, got "this server answers without a sign-in: there is nothing to sign in to". Now Sign in saves the form first when its name, transport, URL or headers aren't the saved server's, leaves the dialog open, and signs in to it; a server being added, or one switched to HTTP, has Sign in too, and a later Save is of the server as saved. mcpauth.ErrNoSignIn says the server already works without signing in, so the agents can use it as it is, a key goes in Headers and a server that signs in at another address (Exa's ?login) needs that URL; the GUI shows it in Chinese. The gateway's /mcp/<name> relay already kept the signed-in URL's query (?login reaches the server) and passed the Library's headers (x-api-key) on, dropping only the gateway's own key: TestMCPProxyKeepsQueryAndHeaders holds it (the fake now records the query). omp reads magpie's mcp.json entry as written (type/url/headers, discovery/builtin.ts) and sends headers on every request (mcp/transports/http.ts): with omp 18.4.9's own client under a temp HOME, mcp.exa.ai/mcp with x-api-key listed Exa's tools and ?login without a sign-in got the 401, so the encoder is unchanged. mcp-signin.test.cjs (webkit, en and zh): an unchanged Exa says it works as it is, with nothing saved; its URL changed to ?login, Sign in saves it then signs in, the dialog stays and no click moves the page; old code started the sign-in without saving. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestProvidersAnswerWhileListsComeIn, a timing test that passes on rerun; library and mcp GUI tests pass in webkit (chromium didn't launch here). Not tried: a real Exa OAuth sign-in in magpie, or omp through magpie's relay with a real account. | ||
|
|
dd03e431c1 | mcpauth: a sign-in asks for offline_access when the authorization server offers it, so Vercel's MCP stays signed in (#615: "vercel老是掉"; Neon, Notion and Supabase stay) — mcp.vercel.com's resource metadata names only the scope "openid" (its 401 names none), and magpie asked for exactly that; its authorization server, https://vercel.com, is an OpenID provider whose scopes_supported lists offline_access, and Vercel's docs say that scope is what issues a refresh token (access tokens last an hour; refresh tokens 30 days, single use, rotated). So magpie's Vercel sign-in had no refresh token, and an hour later Token found it due with nothing to renew it by and marked it dead: "sign in again". Neon (no scopes, refresh by default), Notion ("default") and Supabase (its own scopes) give a refresh token without it. Now discovery adds offline_access to the scope asked for (authorize and registration) when the authorization server's metadata lists it and the scope named any; a sign-in that names no scope keeps the server's default. A rotated refresh token was already saved. The test fake gains OpenID, a Vercel-like server (resource names only "openid", no scope in the 401, refresh token only with offline_access); TestSignInAsksForOfflineAccess fails on the old code (scope "openid", no refresh token, ErrExpired at the first renewal) and passes. A Vercel sign-in made before this has no refresh token and has to be made again once. go vet, builds (darwin, GOOS=linux -tags nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestProvidersAnswerWhileListsComeIn and TestUserPath, timing tests that pass alone. Not tried with a real Vercel account. | ||
|
|
bf0f3e3f73 | library: a remote MCP server signed in once in magpie is used by every agent without signing in again (#615) — a streamable-HTTP server behind OAuth (Neon, Notion, Supabase) had each agent run its own sign-in. The server's editor now has Sign in: magpie finds the authorization server from the server's 401 (RFC 9728 protected-resource metadata, RFC 8414/OIDC metadata, else the 2025-03 /authorize, /token, /register at its origin), registers itself (RFC 7591, a 127.0.0.1 redirect), opens the browser with PKCE S256 and the resource, and keeps the tokens in mcp-signins.json beside its other account secrets (0600, never the keychain). While signed in, the agents are given the gateway's /mcp/<name> for that server, without the Authorization the library has for it; the gateway passes POST (JSON or event stream), the GET stream and DELETE on with the Mcp-Session-Id and magpie's token, renews it 2 minutes before it runs out and once on a 401, one renewal per server at a time, and a sign-in the server won't renew is answered 502 "sign in to it again" (never a 401 the agent would act on). Signing out, a new URL or an SSE server gives the agents the server's own address as before; a rename keeps the sign-in and removing the server drops it. /mcp/ is local-only or LAN-shared with the key, and refuses a request with an Origin or a Host not naming this computer, so a web page can't borrow the sign-in through the browser (form posts, DNS rebinding), and isn't counted as busy or key-limited. WSL agents are given their distro's gateway address. The row says Signed in or Sign-in ran out; zh strings added. Tests: TestSignIn, TestSignInWithoutMetadata, TestSignInPage, TestNothingToSignIn, TestTokenRenewsBeforeItRunsOut (8 calls, 1 renewal), TestRenewRefused, TestRenewRefusedForGood, TestMCPProxy, TestMCPProxyStaysHere, TestMCPProxyNotForWebPages (fails without the Origin/Host check), TestSignedInServerGoesThroughMagpie against a local fake OAuth+MCP server; mcp-signin.test.cjs (webkit, en and zh). Not tried against a real Neon/Notion/Supabase sign-in. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. |