anomalyco / anomalyco/opencode
Remote MCP OAuth tokens never refreshed; restart loses auth state (IBKR connector)
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Remote MCP OAuth tokens never refreshed; restart loses auth state
What happens
- A remote MCP server (IBKR
mcp-public, OAuth via browser flow) works right after activation, then starts failing minutes later with401 after successful authenticationon every endpoint — snapshots, search, everything. - Restarting opencode flips the server back to
needs_authon its own. - Re-authenticating does not reliably revive the running session.
Evidence from my machine (Windows, global opencode.jsonc, type: remote, no custom headers)
~/.local/share/opencode/mcp-auth.jsonholds the entry with dynamically registeredclientInfo,serverUrl, and atokensobject containingaccessToken,refreshToken,expiresAt,scope. So both tokens persist — the refresh just never fires.- Stored access-token lifetimes are on the order of tens of minutes, so any session longer than that hits this wall.
- Same IBKR sessions stay alive fine when driven from other MCP clients, so this is the client's refresh handling, not the authorization server.
Expected
- Silent
refresh_tokengrant before expiry; running session picks up the rotated token without re-auth or restart.
Related (same symptom family)
- #34582 — refresh token present but never used, manual re-auth required after expiry
- #21702 — running session keeps stale token after re-auth; only restart helps
- #16893 — restart loses OAuth state, no automatic re-auth flow
Happy to pull redacted mcp debug output if useful — token values stay with me.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing remote MCP OAuth handling from the persisted entry in ~/.local/share/opencode/mcp-auth.json through token expiry and the running session. Done means an access token is refreshed before expiry, rotated credentials are used by active endpoints, and restarting opencode preserves authentication without manual re-authentication.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100