@@ -28,6 +28,25 @@ function createLatch() {
2828 } ;
2929}
3030
31+ async function expectInvalidParams ( promise : Promise < unknown > , expectedMessages : Array < string | RegExp > = [ ] ) {
32+ let caught : unknown ;
33+ try {
34+ await promise ;
35+ } catch ( error ) {
36+ caught = error ;
37+ }
38+
39+ expect ( caught ) . toMatchObject ( { code : ProtocolErrorCode . InvalidParams } ) ;
40+ const message = caught instanceof Error ? caught . message : String ( caught ) ;
41+ for ( const expected of expectedMessages ) {
42+ if ( expected instanceof RegExp ) {
43+ expect ( message ) . toMatch ( expected ) ;
44+ } else {
45+ expect ( message ) . toContain ( expected ) ;
46+ }
47+ }
48+ }
49+
3150describe ( 'Zod v4' , ( ) => {
3251 describe ( 'McpServer' , ( ) => {
3352 /***
@@ -1212,25 +1231,18 @@ describe('Zod v4', () => {
12121231
12131232 await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
12141233
1215- const result = await client . request ( {
1216- method : 'tools/call' ,
1217- params : {
1218- name : 'test' ,
1219- arguments : {
1234+ await expectInvalidParams (
1235+ client . request ( {
1236+ method : 'tools/call' ,
1237+ params : {
12201238 name : 'test' ,
1221- value : 'not a number'
1222- }
1223- }
1224- } ) ;
1225-
1226- expect ( result . isError ) . toBe ( true ) ;
1227- expect ( result . content ) . toEqual (
1228- expect . arrayContaining ( [
1229- {
1230- type : 'text' ,
1231- text : expect . stringContaining ( 'Input validation error: Invalid arguments for tool test' )
1239+ arguments : {
1240+ name : 'test' ,
1241+ value : 'not a number'
1242+ }
12321243 }
1233- ] )
1244+ } ) ,
1245+ [ 'Input validation error: Invalid arguments for tool test' ]
12341246 ) ;
12351247 } ) ;
12361248
@@ -5149,22 +5161,15 @@ describe('Zod v4', () => {
51495161 await server . connect ( serverTransport ) ;
51505162 await client . connect ( clientTransport ) ;
51515163
5152- const invalidTypeResult = await client . callTool ( {
5153- name : 'union-test' ,
5154- arguments : {
5155- type : 'a' ,
5156- value : 123
5157- }
5158- } ) ;
5159-
5160- expect ( invalidTypeResult . isError ) . toBe ( true ) ;
5161- expect ( invalidTypeResult . content ) . toEqual (
5162- expect . arrayContaining ( [
5163- expect . objectContaining ( {
5164- type : 'text' ,
5165- text : expect . stringContaining ( 'Input validation error' )
5166- } )
5167- ] )
5164+ await expectInvalidParams (
5165+ client . callTool ( {
5166+ name : 'union-test' ,
5167+ arguments : {
5168+ type : 'a' ,
5169+ value : 123
5170+ }
5171+ } ) ,
5172+ [ 'Input validation error' ]
51685173 ) ;
51695174 } ) ;
51705175 } ) ;
@@ -6407,40 +6412,26 @@ describe('Zod v4', () => {
64076412 await server . connect ( serverTransport ) ;
64086413 await client . connect ( clientTransport ) ;
64096414
6410- const invalidTypeResult = await client . callTool ( {
6411- name : 'union-test' ,
6412- arguments : {
6413- type : 'a' ,
6414- value : 123
6415- }
6416- } ) ;
6417-
6418- expect ( invalidTypeResult . isError ) . toBe ( true ) ;
6419- expect ( invalidTypeResult . content ) . toEqual (
6420- expect . arrayContaining ( [
6421- expect . objectContaining ( {
6422- type : 'text' ,
6423- text : expect . stringContaining ( 'Input validation error' )
6424- } )
6425- ] )
6415+ await expectInvalidParams (
6416+ client . callTool ( {
6417+ name : 'union-test' ,
6418+ arguments : {
6419+ type : 'a' ,
6420+ value : 123
6421+ }
6422+ } ) ,
6423+ [ 'Input validation error' ]
64266424 ) ;
64276425
6428- const invalidDiscriminatorResult = await client . callTool ( {
6429- name : 'union-test' ,
6430- arguments : {
6431- type : 'c' ,
6432- value : 'test'
6433- }
6434- } ) ;
6435-
6436- expect ( invalidDiscriminatorResult . isError ) . toBe ( true ) ;
6437- expect ( invalidDiscriminatorResult . content ) . toEqual (
6438- expect . arrayContaining ( [
6439- expect . objectContaining ( {
6440- type : 'text' ,
6441- text : expect . stringContaining ( 'Input validation error' )
6442- } )
6443- ] )
6426+ await expectInvalidParams (
6427+ client . callTool ( {
6428+ name : 'union-test' ,
6429+ arguments : {
6430+ type : 'c' ,
6431+ value : 'test'
6432+ }
6433+ } ) ,
6434+ [ 'Input validation error' ]
64446435 ) ;
64456436 } ) ;
64466437 } ) ;
0 commit comments