Files
magpie/docs
ggbdpq 655d23f790 library: an MCP server signed in to in Codex itself says so instead of "needs sign-in" (#3508)
A server signed in to with `codex mcp login` was still "needs sign-in"
in the Library. Codex keeps those tokens in its keyring, or in a
.credentials.json of CODEX_HOME when its config's
mcp_oauth_credentials_store is file or the keyring is missing, and the
check read no such file.

It now reads it for each Codex target, beside the config.toml the
target already has, a distro's too (codexCredentialsOf, readCodex in
mcp_agent_signin.go). The file holds an entry per server under the key
codex-rs's compute_store_key makes of its name and a 16 hex of the
hash of its config, each entry naming its server and URL with the
tokens flattened into it (its FallbackTokenEntry, read from codex-rs's
rmcp-client/src/oauth.rs — not the StoredOAuthTokens of the login's
memory the report guessed at). An entry of the server's name and URL
with an access or refresh token names Codex in
ServerHealth.AgentSignIn, and the row says "signed in in Codex"
instead of "needs sign-in". An entry with neither token, one of the
executor's (executor_owned: codex answers no host's lookup with it),
another URL by the same name, and a file that can't be read or parsed
name nobody, so the row stays "needs sign-in". The keyring itself is
never read. A stopped distro has no target and isn't started. The
sign-ins are already part of the check's cache key, and the page names
any agent's id in the row, so mcp_check.go and the GUI needed nothing.

Run:
- TestCheckNamesCodexSignedInItself (internal/library): agent.FakeWSL
  forces the Windows+WSL switch (Ubuntu running, its home a temp root),
  sandbox HOME/USERPROFILE, CODEX_HOME cleared, a real httptest server
  answering 401 with WWW-Authenticate.
- Broken by hand, each red with a FAIL naming the behavior:
  - the old behavior (the reader names nobody): codexCredentialsOf
    returns "": "signed in in codex@wsl:Ubuntu, the check says
    {State:auth ... AgentSignIn:[]}".
  - counting an executor's entry: "only the executor's sign-in
    counted".
  - counting an entry with no token: "a sign-in with no token counted".
- gofmt -l (nothing); go vet on darwin, GOOS=linux -tags nogui and
  GOOS=windows for ./internal/library; go build darwin, GOOS=windows
  and GOOS=linux -tags nogui ./...; go test -tags nogui -count=1
  ./internal/library: ok (71s); the two sign-in tests also with -race:
  ok.

Codex's file format was read from codex-rs's source (rmcp-client/src/
oauth.rs, oauth/resolved_store.rs, core/src/config/mod.rs).

Not tried: a real `codex mcp login` (no .credentials.json on this
machine, whose Codex keeps its MCP tokens in the keyring, which is
never read); the test's file is built from codex-rs's writer
(save_oauth_tokens_to_file, its FallbackTokenEntry), and the WSL
distro's file is a temp root behind a FakeWSL probe.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 16:43:21 +08:00
..