GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): read nested OAuth error bodies so a dead MCP refresh token is discarded by rekram1-node · Pull Request #62839 · anomalyco/opencode

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 9, 2026

Copy link
Copy Markdown
Member

Follow-up to #62827.

Problem

ElevenLabs' remote MCP server returns token-endpoint errors nested FastAPI-style:

HTTP 400
{"detail":{"error":"invalid_grant","error_description":"Invalid refresh token"}}

The MCP SDK's parseErrorResponse only reads a top-level error, so it took a revoked refresh token for a server_error. auth() then kept the dead token instead of invalidating it, and every new connection (each Location start, reconnect or credential switch) sent the same refresh again and ended in needs_auth.

Change

  • Extend our existing @modelcontextprotocol/[email protected] patch: in parseErrorResponse (dist/index.mjs and dist/index.cjs), when the body has no top-level string error but has an object detail with a string error, parse detail instead. Everything else is unchanged.
  • Every path that parses token-endpoint errors (locked refresh, logins) now sees invalid_grant, and the SDK's existing invalidation discards the dead credential.
  • No feature flag: bug fix.

Tests

packages/core/test/mcp-oauth.test.ts connects three times with a stored credential to a server that always answers 401, behind a token endpoint that rejects the refresh:

  • A nested detail.error of invalid_grant (default protocol and protocol: "auto") sends one refresh and removes the credential. Without the patch it sends three and keeps it.
  • A top-level {"error":"invalid_grant"} behaves the same as before.
  • {"detail":"oops"} stays a server_error and keeps the credential.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" font-family="ui-monospace,monospace" font-size="10">
  <style>
    .o{animation:o 4s ease-in-out infinite}
    .i{animation:i 4s ease-in-out infinite}
    .x{animation:x 4s ease-in-out infinite}
    @keyframes o{0%,25%{opacity:1}45%,90%{opacity:.2}100%{opacity:1}}
    @keyframes i{0%,25%{transform:translate(0,0)}45%,90%{transform:translate(-26px,-12px)}100%{transform:translate(0,0)}}
    @keyframes x{0%,50%{opacity:0}62%,90%{opacity:1}100%{opacity:0}}
    @media (prefers-reduced-motion:reduce){.o,.i,.x{animation:none}.o{opacity:.2}.i{transform:translate(-26px,-12px)}.x{opacity:1}}
  </style>
  <rect x="10" y="12" width="150" height="48" rx="5" opacity=".5"/>
  <text x="20" y="30" fill="currentColor" stroke="none" class="o">detail:{</text>
  <text x="46" y="44" fill="currentColor" stroke="none" class="i">error: invalid_grant</text>
  <text x="20" y="56" fill="currentColor" stroke="none" class="o">}</text>
  <path d="M168 36h20M182 30l6 6-6 6" opacity=".5"/>
  <g class="x"><rect x="198" y="22" width="22" height="28" rx="3"/><path d="M204 30l10 12M214 30l-10 12"/></g>
</svg>

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rekram1-node
fix(core): read nested OAuth error bodies so a dead MCP refresh token…
e3bf290
… is discarded
@github-actions github-actions Bot added the contributor label Nov 9, 2026
opencodejr[bot]
opencodejr Bot reviewed Nov 9, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is sound and I recommend merging. I ran the new tests against the base, and the two nested-detail cases fail there (extra refreshes). With this change all 36 tests in mcp-oauth.test.ts pass, and typecheck:tsc for packages/core passes. The new check only applies when the body has no top-level string error and detail is an object with a string error. Other bodies are parsed as before, including FastAPI's {"detail":[...]} validation errors.

Public API: unchanged (only how the SDK parses token-endpoint errors changes).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

This branch has not been deployed

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

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@rekram1-node
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.