fix(core): refresh MCP OAuth with stored client ID#27889
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where auto-discovered MCP servers without a static client ID in their configuration failed to refresh their OAuth tokens. By utilizing the client ID already persisted in the token metadata, the system can now successfully perform token refreshes, preventing unnecessary credential deletion and connection failures. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
📊 PR Size: size/M
|
There was a problem hiding this comment.
Code Review
This pull request updates the MCP OAuth provider to fall back to the stored client ID (credentials.clientId) when refreshing an expired token if the current configuration does not provide one. This fallback is applied in both getValidToken and getValidTokenWithMetadata flows, and corresponding unit tests have been added to verify this behavior. There are no review comments, so I have no feedback to provide.
|
@he-yufeng currently having this issue when gemini cli tries to refresh token from a MCP that implements DCR: This PR will fix this, right? |

Summary
Fix the MCP OAuth refresh path used after
/mcp authwhen an auto-discovered server has no staticoauth.clientIdin settings.The CLI already persists the discovered client ID in token metadata, but
getValidTokenWithMetadata()refreshed with the original server config. For auto-discovered providers that config can still have no client ID, so refresh failed, the freshly stored credentials were deleted, and the restarted MCP connection had no bearer token to attach.Details
This supersedes #27752, which had the same fix but was auto-closed by the repository PR rate limiter while I had seven open PRs.
Related Issues
Fixes #27745
How to Validate
Validated on Windows with:
npm test --workspace @google/gemini-cli-core -- src/mcp/oauth-provider.test.tsnpm run typecheck --workspace @google/gemini-cli-corenpm run lint --workspace @google/gemini-cli-core -- --max-warnings 0git diff --checkExpected result: the focused OAuth provider suite passes, the core package type-checks and lints, and the patch has no whitespace errors.
Pre-Merge Checklist