Skip to content

Commit 1c3b091

Browse files
committed
review changes
1 parent e1605c8 commit 1c3b091

File tree

4 files changed

+31
-40
lines changed

4 files changed

+31
-40
lines changed

docs/mcp-declarative/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,11 @@ Below is an example of a tool that uses the Roots feature. `McpRoots` object can
532532

533533
```java
534534
@Mcp.Tool("Request MCP Roots to the connected client.")
535-
List<McpToolContent> rootsTool(McpRoots roots) {
536-
if (!roots.enabled()) {
537-
throw new McpToolErrorException(McpToolContents.textContent("Roots are not supported by the client"));
535+
List<McpToolContent> rootsTool(McpRoots mcpRoots) {
536+
if (!mcpRoots.enabled()) {
537+
throw new McpToolErrorException("Roots are not supported by the client");
538538
}
539-
roots = request.features().roots().listRoots();
539+
List<McpRoot> roots = mcpRoots.listRoots();
540540
McpRoot root = roots.getFirst();
541541
URI uri = root.uri();
542542
String name = root.name().orElse("Unknown");

docs/mcp/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,6 @@ notifications whenever that list is updated.
769769

770770
```java
771771
class RootNameTool implements McpTool {
772-
private List<McpRoot> roots;
773-
774772
@Override
775773
public String name() {
776774
return "roots-name-tool";
@@ -791,9 +789,9 @@ class RootNameTool implements McpTool {
791789
return request -> {
792790
McpRoots mcpRoots = request.features().roots();
793791
if (!mcpRoots.enabled()) {
794-
throw new McpToolErrorException(McpToolContents.textContent("Roots are not supported by the client"));
792+
throw new McpToolErrorException("Roots are not supported by the client");
795793
}
796-
roots = mcpRoots.listRoots();
794+
List<McpRoot> roots = mcpRoots.listRoots();
797795
McpRoot root = roots.getFirst();
798796
URI uri = root.uri();
799797
String name = root.name().orElse("Unknown");

server/src/main/java/io/helidon/extensions/mcp/server/McpJsonRpc.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static List<McpRoot> parseRoots(JsonObject response) {
674674
.mapToObj(roots::getJsonObject)
675675
.map(root -> McpRoot.builder()
676676
.uri(URI.create(root.getString("uri")))
677-
.name(findString(root, "name"))
677+
.name(Optional.ofNullable(root.getString("name", null)))
678678
.build())
679679
.toList();
680680
}
@@ -704,13 +704,6 @@ private static Optional<JsonValue> find(JsonObject object, String key) {
704704
return Optional.empty();
705705
}
706706

707-
private static Optional<String> findString(JsonObject object, String key) {
708-
if (object.containsKey(key)) {
709-
return Optional.of(object.getString(key));
710-
}
711-
return Optional.empty();
712-
}
713-
714707
private static boolean isJsonObject(JsonValue value) {
715708
return JsonValue.ValueType.OBJECT.equals(value.getValueType());
716709
}

tests/declarative/src/main/java/io/helidon/extensions/mcp/tests/declarative/McpRootsServer.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,71 +32,71 @@
3232
@Mcp.Server
3333
@Mcp.Path("/roots")
3434
class McpRootsServer {
35-
@Mcp.Tool("Sampling tool")
36-
List<McpToolContent> tool(McpRoots sampling) {
35+
@Mcp.Tool("Roots tool")
36+
List<McpToolContent> tool(McpRoots roots) {
3737
return List.of(McpToolContents.textContent(""));
3838
}
3939

40-
@Mcp.Tool("Sampling tool")
41-
List<McpToolContent> tool1(McpRoots sampling, String value) {
40+
@Mcp.Tool("Roots tool")
41+
List<McpToolContent> tool1(McpRoots roots, String value) {
4242
return List.of(McpToolContents.textContent(""));
4343
}
4444

45-
@Mcp.Tool("Sampling tool")
46-
String tool2(McpRoots sampling) {
45+
@Mcp.Tool("Roots tool")
46+
String tool2(McpRoots roots) {
4747
return "";
4848
}
4949

50-
@Mcp.Tool("Sampling tool")
51-
String tool3(McpRoots sampling, String value) {
50+
@Mcp.Tool("Roots tool")
51+
String tool3(McpRoots roots, String value) {
5252
return "";
5353
}
5454

55-
@Mcp.Prompt("Sampling prompt")
56-
List<McpPromptContent> prompt(McpRoots sampling) {
55+
@Mcp.Prompt("Roots prompt")
56+
List<McpPromptContent> prompt(McpRoots roots) {
5757
return List.of(McpPromptContents.textContent("", McpRole.USER));
5858
}
5959

60-
@Mcp.Prompt("Sampling prompt")
61-
List<McpPromptContent> prompt1(McpRoots sampling, String value) {
60+
@Mcp.Prompt("Roots prompt")
61+
List<McpPromptContent> prompt1(McpRoots roots, String value) {
6262
return List.of(McpPromptContents.textContent("", McpRole.USER));
6363
}
6464

65-
@Mcp.Prompt("Sampling prompt")
66-
String prompt2(McpRoots sampling) {
65+
@Mcp.Prompt("Roots prompt")
66+
String prompt2(McpRoots roots) {
6767
return "";
6868
}
6969

70-
@Mcp.Prompt("Sampling prompt")
71-
String prompt3(McpRoots sampling, String value) {
70+
@Mcp.Prompt("Roots prompt")
71+
String prompt3(McpRoots roots, String value) {
7272
return "";
7373
}
7474

7575
@Mcp.Resource(uri = "https://resource",
76-
description = "Sampling resource",
76+
description = "Roots resource",
7777
mediaType = MediaTypes.TEXT_PLAIN_VALUE)
78-
List<McpResourceContent> resource(McpRoots sampling) {
78+
List<McpResourceContent> resource(McpRoots roots) {
7979
return List.of(McpResourceContents.textContent(""));
8080
}
8181

8282
@Mcp.Resource(uri = "https://resource1",
83-
description = "Sampling resource",
83+
description = "Roots resource",
8484
mediaType = MediaTypes.TEXT_PLAIN_VALUE)
85-
List<McpResourceContent> resource1(McpRoots sampling, McpRequest request) {
85+
List<McpResourceContent> resource1(McpRoots roots, McpRequest request) {
8686
return List.of(McpResourceContents.textContent(""));
8787
}
8888

8989
@Mcp.Resource(uri = "https://resource2",
90-
description = "Sampling resource",
90+
description = "Roots resource",
9191
mediaType = MediaTypes.TEXT_PLAIN_VALUE)
92-
String resource2(McpRoots sampling) {
92+
String resource2(McpRoots roots) {
9393
return "";
9494
}
9595

9696
@Mcp.Resource(uri = "https://resource3",
97-
description = "Sampling resource",
97+
description = "Roots resource",
9898
mediaType = MediaTypes.TEXT_PLAIN_VALUE)
99-
String resource3(McpRoots sampling, McpRequest request) {
99+
String resource3(McpRoots roots, McpRequest request) {
100100
return "";
101101
}
102102
}

0 commit comments

Comments
 (0)