Skip to content

[bug]: MCP OAuth discovery returns 500 on Vercel since the dynamic baseURL change. #466

Closed

Description

@Ayaan2907

What happened

Connecting any MCP client to https://orbit.noveum.ai/mcp fails at the OAuth
discovery step, so authentication can never start.

Claude Code, Cursor reports:

  SDK auth failed: HTTP 500 trying to load OAuth metadata from
  https://orbit.noveum.ai/.well-known/oauth-authorization-server

GET /.well-known/oauth-authorization-server returns 500 with an empty body and
no CORS headers. /.well-known/openid-configuration, which re-exports the same
handler, returns 500 too. The rest of the chain is healthy: /mcp returns a
correct 401 challenge and /.well-known/oauth-protected-resource returns 200,
so clients get exactly one step further before dying.


This is a regression from #463 (ad86fbd, "fix(auth): support login on protected
Vercel preview URLs"). It changed baseURL from a string to a dynamic config:

  baseURL: allowedHosts.length === 1 ? canonical.origin : { allowedHosts: [...] }

On Vercel, VERCEL_URL is always set, so allowedHosts always holds two or more
entries and baseURL is always the object form. better-auth can only resolve a
dynamic baseURL when the request is passed to the call, and this route is the
only auth.api.* call site in the repo that passes nothing:

  apps/web/src/app/.well-known/oauth-authorization-server/route.ts:9
  const metadata = await auth.api.getMcpOAuthConfig();

better-auth raises this during context resolution, before the mcp plugin's own
try/catch runs, so nothing catches it and Next returns a bare 500:

  APIError: Dynamic baseURL could not be resolved for this direct auth.api call.
  Pass `headers: request.headers` (or `request`) to the call, or add `fallback`
  to your baseURL config.

That also explains why only this one endpoint broke. getMCPProtectedResourceMetadata
reads ctx.context.baseURL, an already resolved string, while getMCPProviderMetadata
reads ctx.context.options.baseURL and requires typeof === "string".

Ruled out while narrowing this down: NEXT_PUBLIC_APP_URL (valid in prod, /llms.txt
emits https://orbit.noveum.ai/login), Redis and rate limiting (errors are swallowed,
still 200 under NODE_ENV=production), and a dependency bump (better-auth has been
pinned at 1.6.26 since 8 Aug).

What you expected instead

GET /.well-known/oauth-authorization-server returns 200 with the authorization
server metadata, so an MCP client can complete the OAuth flow and connect.

Steps to reproduce

No sign-in is needed, this is reachable unauthenticated.

Against production:

  1. curl -i https://orbit.noveum.ai/.well-known/oauth-authorization-server
  2. See HTTP 500, content-length 0, no CORS headers
  3. curl -i https://orbit.noveum.ai/.well-known/oauth-protected-resource
  4. See HTTP 200, confirming only the authorization server document is broken
  5. Add https://orbit.noveum.ai/mcp to any MCP client and watch auth fail at
    discovery

Locally, on main at or after ad86fbd:

  1. Set ORBIT_AUTH_ALLOWED_HOSTS=orbit.example.com in .env, which is what forces
    allowedHosts past one entry, exactly as VERCEL_URL does on every Vercel
    deployment
  2. bun run dev
  3. curl -i http://localhost:3000/.well-known/oauth-authorization-server
  4. See the same 500
  5. Unset ORBIT_AUTH_ALLOWED_HOSTS and repeat: 200 again, because baseURL falls
    back to the single-host string form

A plain bun run dev will NOT reproduce this. With one allowed host the dynamic
path never activates, which is why CI and local development both stayed green.

Where did you see this

orbit.noveum.ai

Which part of Orbit

MCP server

If this is a realtime problem

  • A "Reconnecting to live updates" banner appeared
  • More than one tab or browser was open
  • More than one user was in the workspace

Environment

Environment

- Orbit commit or version: upstream/main at 325a7c8; regression introduced by ad86fbd (#463)
- Bun version (bun --version): 1.3.10
- OS: macOS 15 (Darwin 25.5.0, arm64)
- Browser: n/a, reproduced with curl and MCP clients (Claude Code, opencode)

Logs, errors or screenshots

Image Image
$ curl -i https://orbit.noveum.ai/.well-known/oauth-authorization-server
HTTP/2 500
cache-control: public, max-age=0, must-revalidate
server: Vercel
x-matched-path: /.well-known/oauth-authorization-server
x-vercel-cache: MISS
x-vercel-id: sfo1::hnd1::76dqf-1789147176529-bdb7994e01c8
content-length: 0

$ curl -s https://orbit.noveum.ai/.well-known/oauth-protected-resource
{"resource":"https://orbit.noveum.ai/mcp","authorization_servers":["https://orbit.noveum.ai"],...}   # 200

$ curl -s -X POST https://orbit.noveum.ai/mcp -H 'Content-Type: application/json' -d '{...}'
HTTP/2 401
www-authenticate: Bearer resource_metadata="https://orbit.noveum.ai/.well-known/oauth-protected-resource/mcp"

# Reproduced against better-auth 1.6.26 with the two baseURL shapes:
baseURL as string   -> 200, issuer="https://orbit.noveum.ai"
baseURL as object   -> throws APIError: Dynamic baseURL could not be resolved for
                       this direct auth.api call. Pass `headers: request.headers`
                       (or `request`) to the call, or add `fallback` to your
                       baseURL config.

Before you submit

  • I searched the existing issues and this is not a duplicate
  • I can reproduce this consistently, or I have said how often it happens

Activity

  1. added
    bug
    needs triage
    on Sep 11, 2026
  2. Ayaan2907 commented on Sep 11, 2026

    @Ayaan2907
    ContributorAuthor

    Open to discuss if this can be reproduced by anyone else. Fix is on the way.

  3. changed the title [-][bug]: MCP OAuth discovery returns 500 on Vercel since the dynamic baseURL change in #463[/-] [+][bug]: MCP OAuth discovery returns 500 on Vercel since the dynamic baseURL change.[/+] on Sep 11, 2026
  4. added a commit that references this issue on Sep 17, 2026
    1862a09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions