@@ -11,6 +11,7 @@ import {
1111 PromptMessageSchema ,
1212 ResourceLinkSchema ,
1313 SamplingMessageSchema ,
14+ StringSchemaSchema ,
1415 SUPPORTED_PROTOCOL_VERSIONS ,
1516 ToolChoiceSchema ,
1617 ToolResultContentSchema ,
@@ -986,6 +987,18 @@ describe('Types', () => {
986987 } ) ;
987988
988989 describe ( 'ElicitRequestFormParamsSchema' , ( ) => {
990+ test ( 'preserves string pattern constraints in property schemas' , ( ) => {
991+ const stringResult = StringSchemaSchema . safeParse ( {
992+ type : 'string' ,
993+ pattern : '^[A-Za-z]+$'
994+ } ) ;
995+
996+ expect ( stringResult . success ) . toBe ( true ) ;
997+ if ( stringResult . success ) {
998+ expect ( stringResult . data . pattern ) . toBe ( '^[A-Za-z]+$' ) ;
999+ }
1000+ } ) ;
1001+
9891002 test ( 'accepts requestedSchema with extra JSON Schema metadata keys' , ( ) => {
9901003 // Mirrors what z.toJSONSchema() emits — includes $schema, additionalProperties, etc.
9911004 // See https://github.com/modelcontextprotocol/typescript-sdk/issues/1362
@@ -995,7 +1008,7 @@ describe('Types', () => {
9951008 $schema : 'https://json-schema.org/draft/2020-12/schema' ,
9961009 type : 'object' ,
9971010 properties : {
998- name : { type : 'string' }
1011+ name : { type : 'string' , pattern : '^[A-Za-z]+$' }
9991012 } ,
10001013 required : [ 'name' ] ,
10011014 additionalProperties : false
@@ -1008,6 +1021,9 @@ describe('Types', () => {
10081021 expect ( result . data . requestedSchema . type ) . toBe ( 'object' ) ;
10091022 expect ( result . data . requestedSchema . $schema ) . toBe ( 'https://json-schema.org/draft/2020-12/schema' ) ;
10101023 expect ( result . data . requestedSchema . additionalProperties ) . toBe ( false ) ;
1024+ expect ( result . data . requestedSchema . properties . name ) . toEqual (
1025+ expect . objectContaining ( { type : 'string' , pattern : '^[A-Za-z]+$' } )
1026+ ) ;
10111027 }
10121028 } ) ;
10131029 } ) ;
0 commit comments