@@ -736,22 +736,69 @@ class SamplingTool implements McpTool {
736736 }
737737
738738 @Override
739- public List<McpToolContent > process (McpRequest request ) {
740- var sampling = request. features(). sampling();
739+ public Function<McpRequest , List<McpToolContent > > tool () {
740+ return request - > {
741+ var sampling = request. features(). sampling();
741742
742- if (! sampling. enabled()) {
743- throw new McpToolErrorException (" This tool requires sampling feature" );
744- }
743+ if (! sampling. enabled()) {
744+ throw new McpToolErrorException (" This tool requires sampling feature" );
745+ }
745746
746- try {
747- McpSamplingResponse response = sampling. request(req - > req
748- .timeout(Duration . ofSeconds(10 ))
749- .systemPrompt(" You are a concise, helpful assistant." )
750- .addMessage(McpSamplingMessages . textContent(" Write a 3-line summary of Helidon MCP Sampling." , McpRole . USER )));
751- return List . of(McpToolContents . textContent(response. asTextMessage()));
752- } catch (McpSamplingException e) {
753- throw new McpToolErrorException (e. getMessage());
754- }
747+ try {
748+ var message = McpSamplingMessages . textContent(" Write a 3-line summary of Helidon MCP Sampling." , McpRole . USER );
749+ McpSamplingResponse response = sampling. request(req - > req
750+ .timeout(Duration . ofSeconds(10 ))
751+ .systemPrompt(" You are a concise, helpful assistant." )
752+ .addMessage(message));
753+ return List . of(McpToolContents . textContent(response. asTextMessage()));
754+ } catch (McpSamplingException e) {
755+ throw new McpToolErrorException (e. getMessage());
756+ }
757+ };
758+ }
759+ }
760+ ```
761+
762+ ### Roots
763+
764+ Roots establish the boundaries within the filesystem that define where servers are permitted to operate. They determine which
765+ directories and files a server can access. Servers can request the current list of roots from compatible clients and receive
766+ notifications whenever that list is updated.
767+
768+ #### Example
769+
770+ ``` java
771+ class RootNameTool implements McpTool {
772+ private List<McpRoot > roots;
773+
774+ @Override
775+ public String name () {
776+ return " roots-name-tool" ;
777+ }
778+
779+ @Override
780+ public String description () {
781+ return " Get the list of roots available" ;
782+ }
783+
784+ @Override
785+ public String schema () {
786+ return " " ;
787+ }
788+
789+ @Override
790+ public Function<McpRequest , List<McpToolContent > > tool () {
791+ return request - > {
792+ McpRoots roots = request. features(). roots();
793+ if (! roots. enabled()) {
794+ throw new McpToolErrorException (McpToolContents . textContent(" Roots are not supported by the client" ));
795+ }
796+ roots = request. features(). roots(). listRoots();
797+ McpRoot root = roots. getFirst();
798+ URI uri = root. uri();
799+ String name = root. name(). orElse(" Unknown" );
800+ return List . of(McpToolContents . textContent(" Server updated roots" ));
801+ };
755802 }
756803}
757804```
0 commit comments