@devries-cameron20 / t3code Mirror · read-only / commits / 3e29748f96
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 12:15 UTC

fix(server): malformed MCP client registration returns an RFC 7591 error body (#35809)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 14, 2026 at 20:43 UTC 3e29748f969521bc7c9661d222b1e19689a8b771
2 files changed +30 -2
apps/server/src/auth/McpOAuth.test.ts
+12
@@ -258,6 +258,18 @@ it.effect("registers loopback and https clients and never redirects for an unver
258 );
259 expect(fiveLongCallbacks.status).toBe(201);
260
261 + for (const malformed of [
262 + { client_name: 42, redirect_uris: [REDIRECT] },
263 + { redirect_uris: REDIRECT },
264 + ]) {
265 + const response = yield* handler(postJson("/oauth/mcp/register", malformed));
266 + expect(response.status).toBe(400);
267 + expect(response.headers.get("content-type")).toMatch(/^application\/json/);
268 + expect(yield* json<{ error: string }>(response)).toMatchObject({
269 + error: expect.stringMatching(/^invalid_(client_metadata|redirect_uri)$/),
270 + });
271 + }
272 +
273 const registered = yield* register(handler);
274 expect(registered.status).toBe(201);
275 const { client_id: clientId } = (yield* json<unknown>(registered)) as { client_id: string };
apps/server/src/auth/mcpOAuthHttp.ts
+18 -2
@@ -2,6 +2,8 @@ import {
2 AuthMcpApprovalError,
3 AuthMcpAuthorizationRequest,
4 AuthMcpClientAccess,
5 + AuthMcpClientRegistration,
6 + AuthMcpRegistrationError,
7 EnvironmentHttpApi,
8 mcpClientScopes,
9 } from "@t3tools/contracts";
@@ -42,6 +44,10 @@ const noStore = HttpEffect.appendPreResponseHandler((_request, response) =>
44
45 const requestUrls = Effect.map(HttpServerRequest.HttpServerRequest, McpOAuth.requestUrls);
46 const decodeAuthorizationRequest = Schema.decodeEffect(AuthMcpAuthorizationRequest);
47 +// Decoded by the handler so malformed metadata gets the RFC 7591 error, not HttpApi's empty 400.
48 +const decodeClientRegistration = Schema.decodeUnknownEffect(
49 + Schema.fromJsonString(AuthMcpClientRegistration),
50 +);
51
52 /**
53 * An unverified client or redirect is reported, never redirected; any other problem goes back to
@@ -100,8 +106,18 @@ export const layer = HttpApiBuilder.group(
106 .handle("authorizationServer", () =>
107 requestUrls.pipe(Effect.map(McpOAuth.authorizationServerMetadata)),
108 )
103 - .handle("register", ({ payload }) =>
104 - oauth.register(payload).pipe(
109 + .handleRaw("register", ({ request }) =>
110 + request.text.pipe(
111 + Effect.orDie,
112 + Effect.flatMap(decodeClientRegistration),
113 + Effect.mapError(
114 + (cause) =>
115 + new AuthMcpRegistrationError({
116 + error: "invalid_client_metadata",
117 + error_description: `Invalid client metadata: ${cause.message}`,
118 + }),
119 + ),
120 + Effect.flatMap(oauth.register),
121 Effect.map((client) => ({
122 client_id: client.clientId,
123 client_name: client.name,