1111import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
1212import io .modelcontextprotocol .json .McpJsonDefaults ;
1313import io .modelcontextprotocol .json .McpJsonMapper ;
14- import io .modelcontextprotocol .modern .McpException ;
1514import io .modelcontextprotocol .modern .McpSchema .AudioContent ;
1615import io .modelcontextprotocol .modern .McpSchema .BlobResourceContents ;
1716import io .modelcontextprotocol .modern .McpSchema .CallToolOutcome ;
@@ -255,6 +254,15 @@ private static Handler<CallToolRequest, CallToolOutcome> stream(StreamingTool to
255254 return (ctx , request ) -> McpSyncResponse .streaming (notifier -> tool .run (ctx , request , notifier ));
256255 }
257256
257+ private static final ClientCapabilities .Elicitation FORM = new ClientCapabilities .Elicitation (
258+ new ClientCapabilities .Elicitation .Form (), null );
259+
260+ private static final ClientCapabilities ELICITATION = ClientCapabilities .builder ().elicitation (FORM ).build ();
261+
262+ private static final ClientCapabilities SAMPLING = ClientCapabilities .builder ().sampling ().build ();
263+
264+ private static final ClientCapabilities ROOTS = ClientCapabilities .builder ().roots ().build ();
265+
258266 private static final class ConformanceTools implements McpSyncToolRepository {
259267
260268 private final Map <String , McpSyncTool > tools = new LinkedHashMap <>();
@@ -316,12 +324,8 @@ private static final class ConformanceTools implements McpSyncToolRepository {
316324 .build (), respond ((ctx , req ) -> text ("ok" )));
317325
318326 // SEP-2575 diagnostic tools
319- add ("test_missing_capability" , "Test tool requiring sampling" , (ctx , req ) -> {
320- if (!ctx .clientCapabilities ().supportsSampling ()) {
321- throw McpException .missingClientCapability (ClientCapabilities .builder ().sampling ().build ());
322- }
323- return McpSyncResponse .result (text ("Success" ));
324- });
327+ add ("test_missing_capability" , "Test tool requiring sampling" , SAMPLING ,
328+ respond ((ctx , req ) -> text ("Success" )));
325329 add ("test_streaming_elicitation" , "Diagnostic tool validating response progress streams" ,
326330 stream ((ctx , req , notifier ) -> {
327331 notifier .progress (50 , 100.0 , null );
@@ -342,7 +346,7 @@ private static final class ConformanceTools implements McpSyncToolRepository {
342346
343347 // SEP-2322 MRTR tools
344348 add ("test_input_required_result_elicitation" , "MRTR: returns InputRequiredResult with elicitation request" ,
345- respond ((ctx , req ) -> {
349+ ELICITATION , respond ((ctx , req ) -> {
346350 Map <String , Object > content = acceptedContent (req .inputResponses (), "user_name" );
347351 if (content == null || !(content .get ("name" ) instanceof String name )) {
348352 return InputRequiredResult .builder ()
@@ -352,7 +356,7 @@ private static final class ConformanceTools implements McpSyncToolRepository {
352356 return text ("Hello, " + name + "!" );
353357 }));
354358 add ("test_input_required_result_sampling" , "MRTR: returns InputRequiredResult with sampling request" ,
355- respond ((ctx , req ) -> {
359+ SAMPLING , respond ((ctx , req ) -> {
356360 Map <String , Object > response = responseObject (req .inputResponses (), "capital_question" );
357361 if (response == null ) {
358362 return InputRequiredResult .builder ()
@@ -364,15 +368,15 @@ private static final class ConformanceTools implements McpSyncToolRepository {
364368 return text ("Sampling result: " + answer );
365369 }));
366370 add ("test_input_required_result_list_roots" , "MRTR: returns InputRequiredResult with roots/list request" ,
367- respond ((ctx , req ) -> {
371+ ROOTS , respond ((ctx , req ) -> {
368372 Map <String , Object > response = responseObject (req .inputResponses (), "client_roots" );
369373 if (response == null || !(response .get ("roots" ) instanceof List <?> roots )) {
370374 return InputRequiredResult .builder ().listRoots ("client_roots" ).build ();
371375 }
372376 return text ("Found " + roots .size () + " root(s): " + roots );
373377 }));
374378 add ("test_input_required_result_request_state" , "MRTR: returns InputRequiredResult with requestState" ,
375- respond ((ctx , req ) -> {
379+ ELICITATION , respond ((ctx , req ) -> {
376380 Map <String , Object > content = acceptedContent (req .inputResponses (), "confirm" );
377381 if ("request-state" .equals (req .requestState ()) && content != null
378382 && Boolean .TRUE .equals (content .get ("ok" ))) {
@@ -384,7 +388,8 @@ private static final class ConformanceTools implements McpSyncToolRepository {
384388 .build ();
385389 }));
386390 add ("test_input_required_result_multiple_inputs" ,
387- "MRTR: returns InputRequiredResult with multiple input requests" , respond ((ctx , req ) -> {
391+ "MRTR: returns InputRequiredResult with multiple input requests" ,
392+ ClientCapabilities .builder ().elicitation (FORM ).sampling ().roots ().build (), respond ((ctx , req ) -> {
388393 Map <String , Object > user = acceptedContent (req .inputResponses (), "user_name" );
389394 Map <String , Object > greeting = responseObject (req .inputResponses (), "greeting" );
390395 Map <String , Object > roots = responseObject (req .inputResponses (), "client_roots" );
@@ -400,7 +405,7 @@ private static final class ConformanceTools implements McpSyncToolRepository {
400405 .requestState ("multiple-inputs" )
401406 .build ();
402407 }));
403- add ("test_input_required_result_multi_round" , "MRTR: multi-round InputRequiredResult workflow" ,
408+ add ("test_input_required_result_multi_round" , "MRTR: multi-round InputRequiredResult workflow" , ELICITATION ,
404409 respond ((ctx , req ) -> {
405410 String state = req .requestState ();
406411 if (state != null && state .startsWith ("round-1" )) {
@@ -427,7 +432,7 @@ private static final class ConformanceTools implements McpSyncToolRepository {
427432 // Integrity protection comes from the server's RequestStateCodec: a tampered
428433 // requestState is rejected before this handler runs.
429434 add ("test_input_required_result_tampered_state" , "MRTR: HMAC-signed requestState integrity test" ,
430- respond ((ctx , req ) -> {
435+ ELICITATION , respond ((ctx , req ) -> {
431436 if ("tamper-test" .equals (req .requestState ())
432437 && responseObject (req .inputResponses (), "confirm" ) != null ) {
433438 return text ("integrity-ok: state verified" );
@@ -459,11 +464,21 @@ && responseObject(req.inputResponses(), "confirm") != null) {
459464 }
460465
461466 private void add (String name , String description , Handler <CallToolRequest , CallToolOutcome > handler ) {
462- add (Tool .builder (name , EMPTY_JSON_SCHEMA ).description (description ).build (), handler );
467+ add (name , description , ClientCapabilities .NONE , handler );
468+ }
469+
470+ private void add (String name , String description , ClientCapabilities requiredCapabilities ,
471+ Handler <CallToolRequest , CallToolOutcome > handler ) {
472+ add (Tool .builder (name , EMPTY_JSON_SCHEMA ).description (description ).build (), requiredCapabilities , handler );
463473 }
464474
465475 private void add (Tool tool , Handler <CallToolRequest , CallToolOutcome > handler ) {
466- this .tools .put (tool .name (), McpSyncTool .of (tool , handler ::handle ));
476+ add (tool , ClientCapabilities .NONE , handler );
477+ }
478+
479+ private void add (Tool tool , ClientCapabilities requiredCapabilities ,
480+ Handler <CallToolRequest , CallToolOutcome > handler ) {
481+ this .tools .put (tool .name (), McpSyncTool .of (tool , requiredCapabilities , handler ::handle ));
467482 }
468483
469484 @ Override
@@ -608,7 +623,7 @@ private static final class ConformancePrompts implements McpSyncPromptRepository
608623 .build ())));
609624 add (Prompt .builder ("test_input_required_result_prompt" )
610625 .description ("MRTR: prompt that requires elicitation input" )
611- .build (), respond ((ctx , req ) -> {
626+ .build (), ELICITATION , respond ((ctx , req ) -> {
612627 Map <String , Object > content = acceptedContent (req .inputResponses (), "user_context" );
613628 if (content == null || !(content .get ("context" ) instanceof String context )) {
614629 return InputRequiredResult .builder ()
@@ -622,7 +637,12 @@ private static final class ConformancePrompts implements McpSyncPromptRepository
622637 }
623638
624639 private void add (Prompt prompt , Handler <GetPromptRequest , GetPromptOutcome > handler ) {
625- this .prompts .put (prompt .name (), McpSyncPrompt .of (prompt , handler ::handle ));
640+ add (prompt , ClientCapabilities .NONE , handler );
641+ }
642+
643+ private void add (Prompt prompt , ClientCapabilities requiredCapabilities ,
644+ Handler <GetPromptRequest , GetPromptOutcome > handler ) {
645+ this .prompts .put (prompt .name (), McpSyncPrompt .of (prompt , requiredCapabilities , handler ::handle ));
626646 }
627647
628648 private static GetPromptResult messages (PromptMessage ... messages ) {
0 commit comments