Skip to content

fix(mcp): refresh expired OAuth tokens deterministically - #108299

Open
SmartBoostKG wants to merge 1 commit into
NousResearch:mainfrom
SmartBoostKG:fix/mcp-expired-token-refresh
Open

SmartBoostKG wants to merge 1 commit into
NousResearch:mainfrom
SmartBoostKG:fix/mcp-expired-token-refresh

Conversation

@SmartBoostKG

Copy link
Copy Markdown

Summary

  • reload expired stored MCP OAuth tokens with a negative TTL instead of zero
  • prevent the SDK's inclusive expiry check from briefly accepting stale tokens on coarse Windows clocks
  • cover both absolute expires_at and legacy file-mtime reconstruction paths

Without this boundary fix, an expired bearer token can be sent first, receive 401, and fall into full browser authorization even when a refresh token is available.

Verification

  • uv run --extra dev --frozen pytest tests/tools/test_mcp_oauth*.py -q — 102 passed, 1 skipped
  • uv run --extra dev --frozen ruff check tools/mcp_oauth.py tests/tools/test_mcp_oauth_cold_load_expiry.py — passed
  • reproduced against an expired Trello MCP token: refresh endpoint returned 200, followed by a successful MCP connection without browser authorization

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth comp/tools Tool registry, model_tools, toolsets area/auth Authentication, OAuth, credential pools labels Sep 11, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Related: #62309 already carries this exact clamp (expires_in -> -1 on both the expires_at and legacy-mtime paths) as its Fix A, plus a proactive refresh timer. #67833 fixes the idle-expired refresh from the reconnect side. Flagging so reviewers can consolidate rather than merge overlapping edits to _rebase_expires_in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants