Repository navigation
Let a client on a command line register itself - #6
Merged
Merged
Conversation
`claude mcp add` could not connect: registration came back
web clients require https redirect URIs on non-loopback hosts:
http://localhost:60369/callback
OpenID Connect defaults a registration's `application_type` to `web`, and
a web client's redirect URIs must be https and non-loopback. The OAuth
provider applies that default — but MCP clients register under RFC 7591,
which has no such field, so a client is under no obligation to send one,
and a client running on somebody's machine has nowhere but loopback to
receive the redirect. So the flow died before the consent screen.
`nativeClientRegistration.ts` derives the field from the redirect URIs in
a `hooks.before` middleware, by SEP-837's rule — a loopback host or a
non-http(s) scheme means a native application — which is the same rule
the MCP client SDK applies when it fills the field in itself, so the two
cannot disagree about a client. A hook rather than a fork of the plugin:
the provider has no setting for this, and rewriting the request on its
way in leaves every one of its validations in force. A client that states
its type keeps what it stated, and registering still authorises nothing.
The end-to-end suite posts that registration as raw HTTP, because the
client SDK now sends the derived value and so cannot see the refusal, and
separately runs the whole flow on a loopback callback — the redirect URI
is checked again at authorize and at the token exchange.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMUJEj5inbsz7XKDrCU6Aa
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
htmlcsspdf | 6b1840c | Commit Preview URL Branch Preview URL |
Aug 31 2026, 09:23 PM |
afternoon
marked this pull request as ready for review
August 31, 2026 21:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adding the MCP server to a local Claude failed at registration:
What was wrong
OpenID Connect's registration spec defaults
application_typeto"web", and a web client's redirect URIs must be https and must not be loopback.@better-auth/oauth-providerapplies that default to every dynamic registration (applyOAuthClientRegistrationDefaults(body, "web")), then rejects the redirect URI.But MCP clients register under RFC 7591, which has no
application_typefield at all, so a client is under no obligation to send one — and a client running on somebody's machine has nowhere but loopback to receive the redirect. The flow died before a consent screen was ever reached.The change
src/server/nativeClientRegistration.ts— ahooks.beforemiddleware on/oauth2/registerthat derives the missing field from the redirect URIs, by SEP-837's rule: a loopback host or a non-http(s) scheme means a native application. That is the same rule the MCP client SDK applies when it fills the field in itself (deriveApplicationType), so server and client cannot disagree about what a client is.A hook rather than a fork of the plugin: the provider exposes no setting for the registration default, and rewriting the request on its way in leaves every one of its own validations in force — only
localhost,127.0.0.1and[::1]may be http, https loopback is still refused, private-use schemes must still be well-formed reverse-domain names. A client that states itsapplication_typekeeps what it stated. Registering still authorises nothing: every token comes from a person completing Google sign-in and the consent screen.Tests
src/server/nativeClientRegistration.test.ts— the inference itself, held to SEP-837's rule.e2e/mcpFlow.test.ts— posts the failing registration as raw HTTP (the client SDK now sends the derived value, so an SDK-driven flow cannot see the refusal), and separately runs the whole flow on a loopback callback, since the redirect URI is checked again at authorize and at the token exchange. Reverting the hook makes the first of these fail with the reported message.bun run check,bun run test:unit(430 passed) andbun run test:e2e(14 passed) are green.Generated by Claude Code