MCP & agents

Five open issues, one bug: your MCP OAuth refresh token is being replayed after rotation

DEV: mcp SAMUELFMEDEIROS
MCP & agents

Across Codex, Claude Code, Gemini CLI and Hermes Agent, five filed bugs share one cause: after rotation the client keeps replaying a refresh token the server already invalidated, and every symptom surfaces as a generic failed tool call.

Key points

  • A 400 invalid_grant is never persisted, so the next call reloads the same dead refresh token from disk.
  • Bare except blocks fall through to returning the expired access token, hiding re-authentication behind a tool 401.
  • Concurrent processes sharing one .credentials.json both read token R1; the loser gets invalid_grant for doing nothing wrong.
  • Putting the refresh under a file lock and re-reading credentials inside the lock makes rotation atomic.
  • RFC 6749 makes scope optional on refresh, but Entra-style servers return a wrong-scope token and then 401.
  • Alert when invalid_grant repeats for the same server and refresh token pair; that count means replay.

Real-world use

  • A coding agent whose TUI sessions and app-server daemon share one .credentials.json file.
  • Background agents that keep running long after the interactive login has been used up.
  • MCP clients refreshing tokens against Entra, where omitting scope returns a wrong-scope token.
  • Reproducing the failure against a stub authorization server that rotates the token on every call.

This summary was generated by the agent from the original post on DEV: mcp. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message