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): Gemini Spark can register its six MCP OAuth redirect URIs (#31319)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 14, 2026 at 20:41 UTC
f2839735efaa4a53a9532ffff64f68d308d43b91
2 files changed
+81
-2
apps/server/src/auth/McpOAuth.test.ts
+65
@@ -229,6 +229,34 @@ it.effect("registers loopback and https clients and never redirects for an unver
229
expect(response.status).toBe(400);
230
expect(yield* json<unknown>(response)).toMatchObject({ error: "invalid_redirect_uri" });
231
}
232
+ // JSON escaping can inflate the signed client_id past what an authorize URL can carry.
233
+ const oversized = yield* handler(
234
+ at("/oauth/mcp/register", {
235
+ method: "POST",
236
+ headers: { "content-type": "application/json" },
237
+ body: encodeJson({
238
+ redirect_uris: Array.from(
239
+ { length: 10 },
240
+ (_, index) => `https://bot.example/${index}/${'"'.repeat(480)}`,
241
+ ),
242
+ }),
243
+ }),
244
+ );
245
+ expect(oversized.status).toBe(400);
246
+ const fiveLongCallbacks = yield* handler(
247
+ at("/oauth/mcp/register", {
248
+ method: "POST",
249
+ headers: { "content-type": "application/json" },
250
+ body: encodeJson({
251
+ client_name: "A".repeat(100),
252
+ redirect_uris: Array.from(
253
+ { length: 5 },
254
+ (_, index) => `https://a.co/${index}/${"界".repeat(497)}`,
255
+ ),
256
+ }),
257
+ }),
258
+ );
259
+ expect(fiveLongCallbacks.status).toBe(201);
260
261
const registered = yield* register(handler);
262
expect(registered.status).toBe(201);
@@ -411,6 +439,43 @@ it.live("signs in a hosted agent with an https callback that asked for a client
439
),
440
);
441
442
+it.live("signs in Gemini, which registers six user-bound redirect URIs for one client", () =>
443
+ withRoutes((handler, auth) =>
444
+ Effect.gen(function* () {
445
+ const redirectUris = Array.from(
446
+ { length: 6 },
447
+ (_, index) =>
448
+ `https://oauth-redirect.googleusercontent.com/r/user_bound_custom-mcp-test${index}`,
449
+ );
450
+ const registered = yield* handler(
451
+ at("/oauth/mcp/register", {
452
+ method: "POST",
453
+ headers: { "content-type": "application/json" },
454
+ body: encodeJson({
455
+ client_name: "Google",
456
+ redirect_uris: redirectUris,
457
+ token_endpoint_auth_method: "client_secret_basic",
458
+ }),
459
+ }),
460
+ );
461
+ const client = (yield* json<unknown>(registered)) as { client_id: string };
462
+ expect(client).toMatchObject({ redirect_uris: redirectUris });
463
+ expect(registered.status).toBe(201);
464
+
465
+ const callbackUrl = redirectUris[5]!;
466
+ const params = authorizeParams(client.client_id, callbackUrl);
467
+ const pairing = yield* auth.issuePairingCredential();
468
+ const approved = yield* decide(handler, params, {
469
+ _tag: "pairing-code",
470
+ access: "approval-required",
471
+ code: pairing.credential,
472
+ });
473
+ const callback = new URL(approved.redirectTo!);
474
+ expect(`${callback.origin}${callback.pathname}`).toBe(callbackUrl);
475
+ }),
476
+ ),
477
+);
478
+
479
it.live("rejects a wrong PKCE verifier and spends the code", () =>
480
withRoutes((handler, auth) =>
481
Effect.gen(function* () {
apps/server/src/auth/McpOAuth.ts
+16
-2
@@ -54,8 +54,12 @@ import { requestUrl } from "../requestUrl.ts";
54
const SIGNING_SECRET_NAME = "mcp-oauth-signing-key";
55
const AUTHORIZATION_CODE_TTL_MS = 60_000;
56
const MAX_CLIENT_NAME_LENGTH = 100;
57
-const MAX_REDIRECT_URIS = 5;
57
+const MAX_REDIRECT_URIS = 10;
58
const MAX_REDIRECT_URI_LENGTH = 512;
59
+// The client_id rides in the authorize URL. Past the original five-URI limit, cap it to leave room
60
+// under Node's 16 KB header cap for an encoded redirect_uri and state.
61
+const MAX_UNBOUNDED_CLIENT_ID_REDIRECT_URIS = 5;
62
+const MAX_CLIENT_ID_LENGTH = 10_240;
63
const DEFAULT_CLIENT_NAME = "MCP client";
64
const LOOPBACK_HOSTNAMES = new Set(["localhost", "127.0.0.1", "[::1]"]);
65
const CODE_CHALLENGE_PATTERN = /^[A-Za-z0-9_-]{43}$/;
@@ -348,8 +352,18 @@ const make = Effect.gen(function* () {
352
"Linked environments is off on that machine. Turn it on in its Settings → Labs.",
353
});
354
}
355
+ const clientId = yield* signClientId(name, redirectUris, peerLink);
356
+ if (
357
+ redirectUris.length > MAX_UNBOUNDED_CLIENT_ID_REDIRECT_URIS &&
358
+ clientId.length > MAX_CLIENT_ID_LENGTH
359
+ ) {
360
+ return yield* new AuthMcpRegistrationError({
361
+ error: "invalid_redirect_uri",
362
+ error_description: "Redirect URIs are too long to fit in an authorization request.",
363
+ });
364
+ }
365
return {
352
- clientId: yield* signClientId(name, redirectUris, peerLink),
366
+ clientId,
367
name,
368
redirectUris,
369
peerLink,