Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/elicit-string-pattern.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/core': patch
---

Preserve `pattern` constraints on elicitation string property schemas during request validation.
1 change: 1 addition & 0 deletions packages/core/src/types/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ export const StringSchemaSchema = z.object({
description: z.string().optional(),
minLength: z.number().optional(),
maxLength: z.number().optional(),
pattern: z.string().optional(),
format: z.enum(['email', 'uri', 'date', 'date-time']).optional(),
default: z.string().optional()
});
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/spec.types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ type _K_EmbeddedResource = Assert<AssertExactKeys<SDKTypes.EmbeddedResource, Spe
type _K_ResourceLink = Assert<AssertExactKeys<SDKTypes.ResourceLink, SpecTypes.ResourceLink>>;
type _K_PromptMessage = Assert<AssertExactKeys<SDKTypes.PromptMessage, SpecTypes.PromptMessage>>;
type _K_BooleanSchema = Assert<AssertExactKeys<SDKTypes.BooleanSchema, SpecTypes.BooleanSchema>>;
// @ts-expect-error The written 2025-11-25 elicitation spec includes StringSchema.pattern, but generated spec types lag it.
type _K_StringSchema = Assert<AssertExactKeys<SDKTypes.StringSchema, SpecTypes.StringSchema>>;
type _K_NumberSchema = Assert<AssertExactKeys<SDKTypes.NumberSchema, SpecTypes.NumberSchema>>;
type _K_UntitledSingleSelectEnumSchema = Assert<
Expand Down
18 changes: 17 additions & 1 deletion packages/core/test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PromptMessageSchema,
ResourceLinkSchema,
SamplingMessageSchema,
StringSchemaSchema,
SUPPORTED_PROTOCOL_VERSIONS,
ToolChoiceSchema,
ToolResultContentSchema,
Expand Down Expand Up @@ -986,6 +987,18 @@ describe('Types', () => {
});

describe('ElicitRequestFormParamsSchema', () => {
test('preserves string pattern constraints in property schemas', () => {
const stringResult = StringSchemaSchema.safeParse({
type: 'string',
pattern: '^[A-Za-z]+$'
});

expect(stringResult.success).toBe(true);
if (stringResult.success) {
expect(stringResult.data.pattern).toBe('^[A-Za-z]+$');
}
});

test('accepts requestedSchema with extra JSON Schema metadata keys', () => {
// Mirrors what z.toJSONSchema() emits — includes $schema, additionalProperties, etc.
// See https://github.com/modelcontextprotocol/typescript-sdk/issues/1362
Expand All @@ -995,7 +1008,7 @@ describe('Types', () => {
$schema: 'https://json-schema.org/draft/2020-12/schema',
type: 'object',
properties: {
name: { type: 'string' }
name: { type: 'string', pattern: '^[A-Za-z]+$' }
},
required: ['name'],
additionalProperties: false
Expand All @@ -1008,6 +1021,9 @@ describe('Types', () => {
expect(result.data.requestedSchema.type).toBe('object');
expect(result.data.requestedSchema.$schema).toBe('https://json-schema.org/draft/2020-12/schema');
expect(result.data.requestedSchema.additionalProperties).toBe(false);
expect(result.data.requestedSchema.properties.name).toEqual(
expect.objectContaining({ type: 'string', pattern: '^[A-Za-z]+$' })
);
}
});
});
Expand Down
Loading