Skip to content

Let a client on a command line register itself - #6

Merged
afternoon merged 1 commit into
mainfrom
claude/mcp-https-redirect-uri-cc9b65
Aug 31, 2026
Merged

afternoon merged 1 commit into
mainfrom
claude/mcp-https-redirect-uri-cc9b65

Conversation

@afternoon

Copy link
Copy Markdown
Owner

Adding the MCP server to a local Claude failed at registration:

Couldn't complete authentication for "htmlcsspdf": SDK auth failed:
web clients require https redirect URIs on non-loopback hosts:
http://localhost:60369/callback

What was wrong

OpenID Connect's registration spec defaults application_type to "web", and a web client's redirect URIs must be https and must not be loopback. @better-auth/oauth-provider applies 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_type field 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 — a hooks.before middleware on /oauth2/register that 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.1 and [::1] may be http, https loopback is still refused, private-use schemes must still be well-formed reverse-domain names. A client that states its application_type keeps 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) and bun run test:e2e (14 passed) are green.


Generated by Claude Code

`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
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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
afternoon marked this pull request as ready for review August 31, 2026 21:27
@afternoon
afternoon merged commit 69d9dd6 into main Aug 31, 2026
2 checks passed
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.

2 participants