You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MCP OAuth sign-in fails on Clerk-backed servers: redirect_uri does not match pre-registered redirect urls #63408
Signing in to an MCP server that uses Clerk for OAuth (for example Octolens, https://app.octolens.com/api/mcp/v2) fails after clicking Allow:
{"error":"invalid_request","error_description":"... The 'redirect_uri' parameter does not match any of the OAuth 2.0 Client's pre-registered redirect urls."}
OpenCode registers http://127.0.0.1:PORT/callback through dynamic client registration and sends it on the authorize request. Clerk accepts it, but its consent page rewrites the redirect to http://localhost:PORT/callback, which isn't registered. Clerk also issues the code for the rewritten URI, so the token exchange has to send localhost too.
Setting "oauth": { "redirect_uri": "http://localhost:19876/callback" } on the server works around it.
Add { "type": "remote", "url": "https://app.octolens.com/api/mcp/v2" } as an MCP server with no oauth options.
Start sign-in and click Allow on Clerk's consent page.
Thanks for the detailed report. I couldn't reproduce this here because the failure only shows on Clerk's consent page, which needs a signed-in account on a Clerk-backed MCP server like Octolens. So this needs a maintainer who has such an account.
What I could check in the code on the latest dev (17b5826): when oauth.redirect_uri is not set, the MCP OAuth flow uses a loopback redirect of the form http://127.0.0.1:<port>/callback. That matches the first part of what you describe. The configured redirect_uri workaround you mention looks like the way around it for now.
Activity
opencodejr commentedon Nov 11, 2026
Thanks for the detailed report. I couldn't reproduce this here because the failure only shows on Clerk's consent page, which needs a signed-in account on a Clerk-backed MCP server like Octolens. So this needs a maintainer who has such an account.
What I could check in the code on the latest
dev(17b5826): whenoauth.redirect_uriis not set, the MCP OAuth flow uses a loopback redirect of the formhttp://127.0.0.1:<port>/callback. That matches the first part of what you describe. The configuredredirect_uriworkaround you mention looks like the way around it for now.