@@ -1092,6 +1092,61 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
10921092 ) ;
10931093 } ) ;
10941094
1095+ /***
1096+ * Test: Tool with all optional parameters called without arguments (Issue #400)
1097+ * @see https://github.com/modelcontextprotocol/typescript-sdk/issues/400
1098+ */
1099+ test ( 'should accept undefined arguments when all tool params are optional' , async ( ) => {
1100+ const mcpServer = new McpServer ( {
1101+ name : 'test server' ,
1102+ version : '1.0'
1103+ } ) ;
1104+ const client = new Client ( {
1105+ name : 'test client' ,
1106+ version : '1.0'
1107+ } ) ;
1108+
1109+ mcpServer . tool (
1110+ 'optional-params-tool' ,
1111+ {
1112+ limit : z . number ( ) . optional ( ) ,
1113+ offset : z . number ( ) . optional ( )
1114+ } ,
1115+ async ( { limit, offset } ) => ( {
1116+ content : [
1117+ {
1118+ type : 'text' ,
1119+ text : `limit: ${ limit ?? 'default' } , offset: ${ offset ?? 'default' } `
1120+ }
1121+ ]
1122+ } )
1123+ ) ;
1124+
1125+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
1126+
1127+ await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
1128+
1129+ // Call tool without arguments (arguments is undefined)
1130+ const result = await client . request (
1131+ {
1132+ method : 'tools/call' ,
1133+ params : {
1134+ name : 'optional-params-tool'
1135+ // arguments is intentionally omitted (undefined)
1136+ }
1137+ } ,
1138+ CallToolResultSchema
1139+ ) ;
1140+
1141+ expect ( result . isError ) . toBeUndefined ( ) ;
1142+ expect ( result . content ) . toEqual ( [
1143+ {
1144+ type : 'text' ,
1145+ text : 'limit: default, offset: default'
1146+ }
1147+ ] ) ;
1148+ } ) ;
1149+
10951150 /***
10961151 * Test: Preventing Duplicate Tool Registration
10971152 */
0 commit comments