gemini-cli - 💡(How to fix) Fix When mcp access token is expired, gemini cli calls /mcp with "initialize" method before /token and causes refresh token to be wiped out [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#25248Fetched 2026-04-13 05:45:28
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
labeled ×2

Code Example

> /about
│                                                                              │
About Gemini CLI│                                                                              │
CLI Version                0.37.1Git Commit                 3b2d4f100                                         │
Model                      Auto (Gemini 2.5)Sandbox                    no sandbox                                        │
OS                         linux                                             │
Auth Method                Signed in with Google (####)Tier                       Gemini Code Assist EnterpriseGCP Project                ####                                     │
RAW_BUFFERClick to expand / collapse

What happened?

usually when the access token of a mcp is expired, gemini cli pings /token endpoint and gets a new access token with the given refresh token. However, when I restart my computer with the access token expired and run "gemini" command in my terminal, the first endpoint called is /mcp with method "initialize" instead of /token, causing the refresh token to be wiped out from mcp-oauth-tokens.json

What did you expect to happen?

the first endpoint called to be /token when computer just restarted

Client information

<details> <summary>Client Information</summary>

Run gemini to enter the interactive CLI, then run the /about command.

> /about
│                                                                              │
│ About Gemini CLI                                                             │
│                                                                              │
│ CLI Version                0.37.1                                            │
│ Git Commit                 3b2d4f100                                         │
│ Model                      Auto (Gemini 2.5)                                 │
│ Sandbox                    no sandbox                                        │
│ OS                         linux                                             │
│ Auth Method                Signed in with Google (####)      │
│ Tier                       Gemini Code Assist Enterprise                     │
│ GCP Project                ####                                     │
</details>

Login information

google account

Anything else we need to know?

No response

extent analysis

TL;DR

The issue can be mitigated by ensuring the /token endpoint is called before /mcp when the access token is expired, potentially by modifying the Gemini CLI's behavior on startup.

Guidance

  • Investigate the Gemini CLI's startup logic to determine why /mcp is called before /token when the access token is expired.
  • Consider adding a check for expired access tokens on startup and calling the /token endpoint to refresh the token before proceeding.
  • Review the mcp-oauth-tokens.json file handling to ensure it is not being overwritten or cleared unnecessarily.
  • Look into potential configuration options or environment variables that may influence the Gemini CLI's behavior in this scenario.

Notes

The exact solution may depend on the internal implementation of the Gemini CLI, which is not provided in the issue. Additionally, the behavior may vary depending on the specific version of the CLI and other environmental factors.

Recommendation

Apply workaround: Modify the Gemini CLI's startup logic or configuration to prioritize calling the /token endpoint when the access token is expired, to prevent the refresh token from being lost.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING