5050import io .modelcontextprotocol .modern .server .feature .CompletionsFeature ;
5151import io .modelcontextprotocol .modern .server .feature .McpChangeBroadcaster ;
5252import io .modelcontextprotocol .modern .server .feature .McpChangeFeed ;
53+ import io .modelcontextprotocol .modern .server .feature .McpSyncPrompt ;
5354import io .modelcontextprotocol .modern .server .feature .McpSyncPromptRepository ;
5455import io .modelcontextprotocol .modern .server .feature .McpSyncResourceRepository ;
56+ import io .modelcontextprotocol .modern .server .feature .McpSyncTool ;
5557import io .modelcontextprotocol .modern .server .feature .McpSyncToolRepository ;
5658import io .modelcontextprotocol .modern .server .feature .PromptsFeature ;
5759import io .modelcontextprotocol .modern .server .feature .PromptsPage ;
@@ -254,12 +256,9 @@ private static Handler<CallToolRequest, CallToolOutcome> stream(StreamingTool to
254256 return (ctx , request ) -> McpSyncResponse .streaming (notifier -> tool .run (ctx , request , notifier ));
255257 }
256258
257- private record ToolEntry (Tool tool , Handler <CallToolRequest , CallToolOutcome > handler ) {
258- }
259-
260259 private static final class ConformanceTools implements McpSyncToolRepository {
261260
262- private final Map <String , ToolEntry > tools = new LinkedHashMap <>();
261+ private final Map <String , McpSyncTool > tools = new LinkedHashMap <>();
263262
264263 ConformanceTools (McpChangeBroadcaster changes ) {
265264 add ("test_simple_text" , "Returns simple text content for testing" ,
@@ -465,27 +464,17 @@ private void add(String name, String description, Handler<CallToolRequest, CallT
465464 }
466465
467466 private void add (Tool tool , Handler <CallToolRequest , CallToolOutcome > handler ) {
468- this .tools .put (tool .name (), new ToolEntry (tool , handler ));
467+ this .tools .put (tool .name (), McpSyncTool . of (tool , handler :: handle ));
469468 }
470469
471470 @ Override
472471 public ToolsPage list (McpRequestContext ctx , String cursor ) {
473- return ToolsPage .of (this .tools .values ().stream ().map (ToolEntry ::tool ).toList ());
474- }
475-
476- @ Override
477- public Tool find (McpRequestContext ctx , String name ) {
478- ToolEntry entry = this .tools .get (name );
479- return entry != null ? entry .tool () : null ;
472+ return ToolsPage .of (this .tools .values ().stream ().map (McpSyncTool ::definition ).toList ());
480473 }
481474
482475 @ Override
483- public McpSyncResponse <CallToolOutcome > call (McpRequestContext ctx , CallToolRequest request ) {
484- ToolEntry entry = this .tools .get (request .name ());
485- if (entry == null ) {
486- throw McpException .invalidParams ("Unknown tool: " + request .name ());
487- }
488- return entry .handler ().handle (ctx , request );
476+ public McpSyncTool find (McpRequestContext ctx , String name ) {
477+ return this .tools .get (name );
489478 }
490479
491480 private static void sleep (long millis ) {
@@ -571,12 +560,9 @@ private static ReadResourceResult templateResource(String uri) {
571560
572561 }
573562
574- private record PromptEntry (Prompt prompt , Handler <GetPromptRequest , GetPromptOutcome > handler ) {
575- }
576-
577563 private static final class ConformancePrompts implements McpSyncPromptRepository {
578564
579- private final Map <String , PromptEntry > prompts = new LinkedHashMap <>();
565+ private final Map <String , McpSyncPrompt > prompts = new LinkedHashMap <>();
580566
581567 ConformancePrompts () {
582568 add (Prompt .builder ("test_simple_prompt" ).description ("A simple prompt for testing" ).build (),
@@ -637,7 +623,7 @@ private static final class ConformancePrompts implements McpSyncPromptRepository
637623 }
638624
639625 private void add (Prompt prompt , Handler <GetPromptRequest , GetPromptOutcome > handler ) {
640- this .prompts .put (prompt .name (), new PromptEntry (prompt , handler ));
626+ this .prompts .put (prompt .name (), McpSyncPrompt . of (prompt , handler :: handle ));
641627 }
642628
643629 private static GetPromptResult messages (PromptMessage ... messages ) {
@@ -646,22 +632,12 @@ private static GetPromptResult messages(PromptMessage... messages) {
646632
647633 @ Override
648634 public PromptsPage list (McpRequestContext ctx , String cursor ) {
649- return PromptsPage .of (this .prompts .values ().stream ().map (PromptEntry ::prompt ).toList ());
650- }
651-
652- @ Override
653- public Prompt find (McpRequestContext ctx , String name ) {
654- PromptEntry entry = this .prompts .get (name );
655- return entry != null ? entry .prompt () : null ;
635+ return PromptsPage .of (this .prompts .values ().stream ().map (McpSyncPrompt ::definition ).toList ());
656636 }
657637
658638 @ Override
659- public McpSyncResponse <GetPromptOutcome > get (McpRequestContext ctx , GetPromptRequest request ) {
660- PromptEntry entry = this .prompts .get (request .name ());
661- if (entry == null ) {
662- throw McpException .invalidParams ("Unknown prompt: " + request .name ());
663- }
664- return entry .handler ().handle (ctx , request );
639+ public McpSyncPrompt find (McpRequestContext ctx , String name ) {
640+ return this .prompts .get (name );
665641 }
666642
667643 }
0 commit comments