Repository navigation
Conversation
Coalesce refreshes for the current token source and let each OAuth caller wait with its own context. Wake waiters when a newer authorization supplies a token and keep bearer lookup cancellable across the stdio GitHub clients.
There was a problem hiding this comment.
🟡 Changes recommended
The tool guard lacks a cancellation regression test, leaving ignored HasTokenContext errors or use of a non-cancelable context undetected.
1 open issue
What changed in this PR
Makes stdio OAuth token-refresh waits cancellable while allowing the shared refresh to finish and preserve rotated credentials for the session.
Changes:
- Shares in-flight refreshes and wakes waiters when a newer authorization installs a token.
- Passes request contexts through the tool guard and REST, GraphQL, and raw-content token lookups.
- Adds cancellation and transport regression tests, and documents refresh ownership.
| File | Description |
|---|---|
internal/oauth/refresh_cancellation_test.go |
Tests cancellation, shared refreshes, and authorization replacement. |
internal/oauth/manager.go |
Adds context-aware token waits and shared-refresh coordination. |
internal/ghmcp/server.go |
Connects request contexts to outbound OAuth bearer lookups. |
internal/ghmcp/server_test.go |
Updates client setup for the OAuth provider parameter. |
internal/ghmcp/oauth.go |
Makes the tool guard’s token check cancellable. |
internal/ghmcp/oauth_test.go |
Updates authentication fakes and client setup. |
internal/ghmcp/oauth_refresh_transport_test.go |
Tests request cancellation, body closure, and host-scoped bearer handling. |
docs/oauth-login.md |
Explains shared refreshes and canceled request waits. |
Review effort: Max (adaptive)
|
@SamMorrowDrums could you review this stdio OAuth fix when you have a chance? A canceled request can stop waiting while active requests still get the result of the shared token refresh. The cancellation regression tests passed locally, and the Copilot review thread is resolved. If the diff looks good, could you also approve the fork workflows so CI can run? Would appreciate your feedback on this, thanks! |

Summary
Let canceled stdio MCP requests stop waiting for an OAuth token refresh. Concurrent requests can still receive the result of the same refresh and reuse the rotated credentials.
Why
When the session token expired, the stdio tool guard called
HasToken, which synchronously calledoauth2.TokenSource.Token. Authorization resume and the outbound bearer provider could enter the same path. The source uses an independent HTTP context for refresh. That is appropriate for the shared exchange, but it also meant a canceled caller could not return until the exchange released it.A gated token source reproduced the problem on
df32d7ec5786. BothAuthenticateandAwaitTokenremained blocked after cancellation while the refresh was held. An already-canceled call entered the source and returned success instead ofcontext.Canceled. Installing a newer authorization also left waiters blocked on the old source.What changed
MCP impact
Prompts tested (tool changes only)
The authorization tests use synthetic tokens and a gated refresh source. The outbound tests use the configured clients against a local HTTP fixture for REST, GraphQL, and raw content.
Security / limits
Tool renaming
Lint & tests
./script/linton Linux with golangci-lint v2.14.0../script/test(go test -race ./...) on Linux.go test -v ./..., the snapshot suite withUPDATE_TOOLSNAPS=true, and a CLI build. The verbose suite passed 32 packages, 1,225 top-level tests, and 7,997 subtests. The new OAuth manager and stdio transport tests each passed 100 consecutive runs. The tagged end-to-end package compiled with execution disabled.go mod tidy -diff, a CLI build, and regenerated documentation validation.Docs
Skills
Related work includes the stdio OAuth introduction, multi-round-trip OAuth migration, and GitHub's refresh token rotation documentation.
Implementation powered by Codex. Reviewed and Report written by Jon Zhang.