Skip to content

fix(auth): stop MCP OAuth discovery from failing with 500 on Workers - #61

Merged
donnes merged 1 commit into
mainfrom
t3/fix-mcp-discovery-500
Dec 2, 2026
Merged

donnes merged 1 commit into
mainfrom
t3/fix-mcp-discovery-500

Conversation

@donnes

@donnes donnes commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Executor couldn't start a Spendle sign-in: its OAuth discovery got HTTP 500 from /.well-known/oauth-protected-resource/api/mcp, while the same URL answered 200 from elsewhere.

Production logs for those 500s show This promise was created by a request that has since ended, so it can never settle, thrown where Better Auth awaits its runtime schema check. That check is one promise per isolate, started in the background of the request that builds the auth instance. On Workers, when that request ends first (an unauthenticated POST /api/mcp answers 401 right away, which is what Executor's discovery sends first), the promise can never settle, and every later auth or discovery request in that isolate fails with 500 until Cloudflare recycles it.

getAuth already migrates the auth schema itself (once per deployment on Workers), so this turns Better Auth's runtime check off (advanced.database.validateSchema: false).

Testing

  • Proof: production Workers telemetry shows the 500s from Executor's discovery requests, each with the cross-request promise error at the schema-check line of the deployed bundle.
  • Local Workers runtime (vp build --mode qa, vp preview --mode qa, fresh D1): an unauthenticated MCP call (401), then the protected resource metadata, authorization server metadata and JWKS (200), QA sign-in and a signed-in page all work. Without the slow production D1 I could not reproduce the hang locally.
  • Web typecheck and lint pass, and 16 MCP and auth tests pass.

Created with Claude Opus 5.5 in Claude Code (T3 Code).

Better Auth's runtime schema check is one promise per isolate, started in the
background of the request that builds the instance. On Workers, a request that
ends first (an unauthenticated MCP call answers 401 at once) leaves it unable
to settle, and every later request in that isolate fails. getAuth already
migrates the schema, so the runtime check is off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@donnes
donnes merged commit a9a04f5 into main Dec 2, 2026
2 checks passed
@donnes
donnes deleted the t3/fix-mcp-discovery-500 branch December 2, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant