Skip to content

Commit caa2550

Browse files
Allow empty string as valid URL in DCR workflow (modelcontextprotocol#987)
1 parent 8f4150e commit caa2550

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/shared/auth.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { describe, it, expect } from '@jest/globals';
2-
import { SafeUrlSchema, OAuthMetadataSchema, OpenIdProviderMetadataSchema, OAuthClientMetadataSchema } from './auth.js';
2+
import {
3+
SafeUrlSchema,
4+
OAuthMetadataSchema,
5+
OpenIdProviderMetadataSchema,
6+
OAuthClientMetadataSchema,
7+
OptionalSafeUrlSchema
8+
} from './auth.js';
39

410
describe('SafeUrlSchema', () => {
511
it('accepts valid HTTPS URLs', () => {
@@ -26,6 +32,12 @@ describe('SafeUrlSchema', () => {
2632
});
2733
});
2834

35+
describe('OptionalSafeUrlSchema', () => {
36+
it('accepts empty string and transforms it to undefined', () => {
37+
expect(OptionalSafeUrlSchema.parse('')).toBe(undefined);
38+
});
39+
});
40+
2941
describe('OAuthMetadataSchema', () => {
3042
it('validates complete OAuth metadata', () => {
3143
const metadata = {

src/shared/auth.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ export const OAuthErrorResponseSchema = z.object({
151151
error_uri: z.string().optional()
152152
});
153153

154+
/**
155+
* Optional version of SafeUrlSchema that allows empty string for retrocompatibility on tos_uri and logo_uri
156+
*/
157+
export const OptionalSafeUrlSchema = SafeUrlSchema.optional().or(z.literal('').transform(() => undefined));
158+
154159
/**
155160
* RFC 7591 OAuth 2.0 Dynamic Client Registration metadata
156161
*/
@@ -162,10 +167,10 @@ export const OAuthClientMetadataSchema = z
162167
response_types: z.array(z.string()).optional(),
163168
client_name: z.string().optional(),
164169
client_uri: SafeUrlSchema.optional(),
165-
logo_uri: SafeUrlSchema.optional(),
170+
logo_uri: OptionalSafeUrlSchema,
166171
scope: z.string().optional(),
167172
contacts: z.array(z.string()).optional(),
168-
tos_uri: SafeUrlSchema.optional(),
173+
tos_uri: OptionalSafeUrlSchema,
169174
policy_uri: z.string().optional(),
170175
jwks_uri: SafeUrlSchema.optional(),
171176
jwks: z.any().optional(),

0 commit comments

Comments
 (0)