26
26
import io .modelcontextprotocol .server .McpServerFeatures .AsyncToolSpecification ;
27
27
import io .modelcontextprotocol .server .McpServerFeatures .SyncToolSpecification ;
28
28
import io .modelcontextprotocol .server .McpSyncServerExchange ;
29
+ import io .modelcontextprotocol .spec .McpSchema ;
29
30
import io .modelcontextprotocol .spec .McpSchema .CallToolResult ;
30
31
import io .modelcontextprotocol .spec .McpSchema .Implementation ;
31
32
import io .modelcontextprotocol .spec .McpSchema .ListToolsResult ;
@@ -226,7 +227,10 @@ void toSyncToolSpecificationShouldConvertSingleCallback() {
226
227
assertThat (toolSpecification ).isNotNull ();
227
228
assertThat (toolSpecification .tool ().name ()).isEqualTo ("test" );
228
229
229
- CallToolResult result = toolSpecification .call ().apply (mock (McpSyncServerExchange .class ), Map .of ());
230
+ McpSchema .CallToolRequest mockRequest = mock (McpSchema .CallToolRequest .class );
231
+ when (mockRequest .arguments ()).thenReturn (Map .of ());
232
+
233
+ CallToolResult result = toolSpecification .callHandler ().apply (mock (McpSyncServerExchange .class ), mockRequest );
230
234
TextContent content = (TextContent ) result .content ().get (0 );
231
235
assertThat (content .text ()).isEqualTo ("success" );
232
236
assertThat (result .isError ()).isFalse ();
@@ -239,7 +243,11 @@ void toSyncToolSpecificationShouldHandleError() {
239
243
SyncToolSpecification toolSpecification = McpToolUtils .toSyncToolSpecification (callback );
240
244
241
245
assertThat (toolSpecification ).isNotNull ();
242
- CallToolResult result = toolSpecification .call ().apply (mock (McpSyncServerExchange .class ), Map .of ());
246
+
247
+ McpSchema .CallToolRequest mockRequest = mock (McpSchema .CallToolRequest .class );
248
+ when (mockRequest .arguments ()).thenReturn (Map .of ());
249
+
250
+ CallToolResult result = toolSpecification .callHandler ().apply (mock (McpSyncServerExchange .class ), mockRequest );
243
251
TextContent content = (TextContent ) result .content ().get (0 );
244
252
assertThat (content .text ()).isEqualTo ("error" );
245
253
assertThat (result .isError ()).isTrue ();
@@ -267,7 +275,10 @@ void toAsyncToolSpecificationShouldConvertSingleCallback() {
267
275
assertThat (toolSpecification ).isNotNull ();
268
276
assertThat (toolSpecification .tool ().name ()).isEqualTo ("test" );
269
277
270
- StepVerifier .create (toolSpecification .call ().apply (mock (McpAsyncServerExchange .class ), Map .of ()))
278
+ McpSchema .CallToolRequest mockRequest = mock (McpSchema .CallToolRequest .class );
279
+ when (mockRequest .arguments ()).thenReturn (Map .of ());
280
+
281
+ StepVerifier .create (toolSpecification .callHandler ().apply (mock (McpAsyncServerExchange .class ), mockRequest ))
271
282
.assertNext (result -> {
272
283
TextContent content = (TextContent ) result .content ().get (0 );
273
284
assertThat (content .text ()).isEqualTo ("success" );
@@ -283,7 +294,11 @@ void toAsyncToolSpecificationShouldHandleError() {
283
294
AsyncToolSpecification toolSpecification = McpToolUtils .toAsyncToolSpecification (callback );
284
295
285
296
assertThat (toolSpecification ).isNotNull ();
286
- StepVerifier .create (toolSpecification .call ().apply (mock (McpAsyncServerExchange .class ), Map .of ()))
297
+
298
+ McpSchema .CallToolRequest mockRequest = mock (McpSchema .CallToolRequest .class );
299
+ when (mockRequest .arguments ()).thenReturn (Map .of ());
300
+
301
+ StepVerifier .create (toolSpecification .callHandler ().apply (mock (McpAsyncServerExchange .class ), mockRequest ))
287
302
.assertNext (result -> {
288
303
TextContent content = (TextContent ) result .content ().get (0 );
289
304
assertThat (content .text ()).isEqualTo ("error" );
0 commit comments