Skip to content

Commit 9925fd4

Browse files
committed
latest modifications
1 parent e87bfa6 commit 9925fd4

File tree

13 files changed

+263
-47
lines changed

13 files changed

+263
-47
lines changed

integrations/mcp/server/src/main/java/io/helidon/integrations/mcp/server/JsonSchema.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.function.Supplier;
2727

2828
import jakarta.json.Json;
29-
import jakarta.json.JsonObject;
3029
import jakarta.json.JsonObjectBuilder;
3130

3231
/**
@@ -99,24 +98,24 @@ public Builder addProperty(String propertyName, Consumer<SchemaObject.Builder> b
9998
return this;
10099
}
101100

102-
public Builder addStringProperty(String key) {
103-
object.addStringProperty(key);
101+
public Builder addString(String key) {
102+
object.addString(key);
104103
return this;
105104
}
106105

107-
public Builder addBooleanProperty(String key) {
108-
object.addBooleanProperty(key);
106+
public Builder addBoolean(String key) {
107+
object.addBoolean(key);
109108
return this;
110109
}
111110

112-
public Builder addNumberProperty(String key) {
113-
object.addNumberProperty(key);
111+
public Builder addNumber(String key) {
112+
object.addNumber(key);
114113
return this;
115114
}
116115

117116
//TODO - Replace by an enum ? Or use several method ?
118-
public Builder addArrayProperty(String key, String type) {
119-
object.addArrayProperty(key, type);
117+
public Builder addArray(String key, String type) {
118+
object.addArray(key, type);
120119
return this;
121120
}
122121

@@ -184,23 +183,23 @@ public Builder addProperty(String propertyName, Consumer<SchemaObject.Builder> b
184183
return this;
185184
}
186185

187-
public Builder addStringProperty(String key) {
186+
public Builder addString(String key) {
188187
properties.put(key, SchemaString.create());
189188
return this;
190189
}
191190

192-
public Builder addBooleanProperty(String key) {
191+
public Builder addBoolean(String key) {
193192
properties.put(key, SchemaBoolean.create());
194193
return this;
195194
}
196195

197-
public Builder addNumberProperty(String key) {
196+
public Builder addNumber(String key) {
198197
properties.put(key, SchemaNumber.create());
199198
return this;
200199
}
201200

202201
//TODO - Replace by an enum ? Or use several method ?
203-
public Builder addArrayProperty(String key, String type) {
202+
public Builder addArray(String key, String type) {
204203
properties.put(key, SchemaArray.create(type));
205204
return this;
206205
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.integrations.mcp.server;
18+
19+
/**
20+
* Mcp logging logger.
21+
*/
22+
public interface McpLogger {
23+
/**
24+
* Send a notification to the client.
25+
*
26+
* @param level notification level
27+
* @param message notification
28+
*/
29+
void log(Level level, String message);
30+
31+
/**
32+
* Send a debug notification to the client.
33+
*
34+
* @param message notification
35+
*/
36+
void debug(String message);
37+
38+
/**
39+
* Send an info notification to the client.
40+
*
41+
* @param message notification
42+
*/
43+
void info(String message);
44+
45+
/**
46+
* Send a notice notification to the client.
47+
*
48+
* @param message notification
49+
*/
50+
void notice(String message);
51+
52+
/**
53+
* Send a warning notification to the client.
54+
*
55+
* @param message notification
56+
*/
57+
void warn(String message);
58+
59+
/**
60+
* Send an error notification to the client.
61+
*
62+
* @param message notification
63+
*/
64+
void error(String message);
65+
66+
/**
67+
* Send a critical notification to the client.
68+
*
69+
* @param message notification
70+
*/
71+
void critical(String message);
72+
73+
/**
74+
* Send an alert notification to the client.
75+
*
76+
* @param message notification
77+
*/
78+
void alert(String message);
79+
80+
81+
static McpLogger getLogger(String name) {
82+
return new McpLoggerImpl(name);
83+
}
84+
85+
enum Level {
86+
DEBUG,
87+
INFO,
88+
NOTICE,
89+
WARNING,
90+
ERROR,
91+
CRITICAL,
92+
ALERT
93+
}
94+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.integrations.mcp.server;
18+
19+
class McpLoggerImpl implements McpLogger {
20+
private final String name;
21+
22+
McpLoggerImpl(String name) {
23+
this.name = name;
24+
}
25+
26+
public String name() {
27+
return name;
28+
}
29+
30+
@Override
31+
public void log(Level level, String message) {
32+
33+
}
34+
35+
@Override
36+
public void debug(String message) {
37+
log(Level.DEBUG, message);
38+
}
39+
40+
@Override
41+
public void info(String message) {
42+
log(Level.INFO, message);
43+
}
44+
45+
@Override
46+
public void notice(String message) {
47+
log(Level.NOTICE, message);
48+
}
49+
50+
@Override
51+
public void warn(String message) {
52+
log(Level.WARNING, message);
53+
}
54+
55+
@Override
56+
public void error(String message) {
57+
log(Level.ERROR, message);
58+
}
59+
60+
@Override
61+
public void critical(String message) {
62+
log(Level.CRITICAL, message);
63+
}
64+
65+
@Override
66+
public void alert(String message) {
67+
log(Level.ALERT, message);
68+
}
69+
}

integrations/mcp/server/src/test/java/io/helidon/integrations/mcp/server/JsonSchemaTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class JsonSchemaTest {
2828
void testSchemaString() {
2929
JsonObject schema = JsonSchema.builder()
3030
.id("foo")
31-
.addStringProperty("bar")
31+
.addString("bar")
3232
.build()
3333
.json()
3434
.build();
@@ -44,7 +44,7 @@ void testSchemaString() {
4444
void testSchemaBoolean() {
4545
JsonObject schema = JsonSchema.builder()
4646
.id("foo")
47-
.addBooleanProperty("bar")
47+
.addBoolean("bar")
4848
.build()
4949
.json()
5050
.build();
@@ -60,7 +60,7 @@ void testSchemaBoolean() {
6060
void testSchemaNumber() {
6161
JsonObject schema = JsonSchema.builder()
6262
.id("foo")
63-
.addNumberProperty("bar")
63+
.addNumber("bar")
6464
.build()
6565
.json()
6666
.build();
@@ -76,7 +76,7 @@ void testSchemaNumber() {
7676
void testSchemaArray() {
7777
JsonObject schema = JsonSchema.builder()
7878
.id("foo")
79-
.addArrayProperty("bar", "string")
79+
.addArray("bar", "string")
8080
.build()
8181
.json()
8282
.build();
@@ -97,10 +97,10 @@ void testSchemaArray() {
9797
void testNestedObject() {
9898
JsonObject schema = JsonSchema.builder()
9999
.id("foo")
100-
.addProperty("bar", properties -> properties.addStringProperty("string")
101-
.addBooleanProperty("boolean")
102-
.addNumberProperty("number")
103-
.addArrayProperty("array", "string"))
100+
.addProperty("bar", properties -> properties.addString("string")
101+
.addBoolean("boolean")
102+
.addNumber("number")
103+
.addArray("array", "string"))
104104
.build()
105105
.json()
106106
.build();

integrations/mcp/tests/demo/src/main/java/io/helidon/integrations/mcp/demo/McpWeatherClientTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public String description() {
5858
@Override
5959
public JsonSchema schema() {
6060
return JsonSchema.builder()
61-
.addStringProperty("state")
61+
.addString("state")
6262
.build();
6363
}
6464

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2025 Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.helidon.integrations.mcp.demo;
18+
19+
import io.helidon.integrations.mcp.server.JsonSchema;
20+
import io.helidon.integrations.mcp.server.McpLogger;
21+
import io.helidon.integrations.mcp.server.McpParameters;
22+
import io.helidon.integrations.mcp.server.Tool;
23+
import io.helidon.integrations.mcp.server.ToolContent;
24+
import io.helidon.integrations.mcp.server.ToolContents;
25+
26+
class McpWeatherLogging implements Tool {
27+
28+
private static final McpLogger LOGGER = McpLogger.getLogger(McpWeatherLogging.class.getName());
29+
30+
@Override
31+
public String name() {
32+
return "logging";
33+
}
34+
35+
@Override
36+
public String description() {
37+
return "Logging";
38+
}
39+
40+
@Override
41+
public JsonSchema schema() {
42+
return null;
43+
}
44+
45+
@Override
46+
public ToolContent process(McpParameters parameters) {
47+
48+
LOGGER.log(McpLogger.Level.DEBUG, "Notification with debug level");
49+
50+
LOGGER.info("Notification to the client");
51+
52+
return ToolContents.textContent("logged");
53+
}
54+
}

integrations/mcp/tests/demo/src/main/java/io/helidon/integrations/mcp/demo/McpWeatherParameters.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ public JsonSchema schema() {
3838
.id("my-id")
3939
.title("tool-weather-schema")
4040
.description("Schema describing town information requirements")
41-
.addStringProperty("name")
42-
.addProperty("location", location -> location
43-
.addNumberProperty("latitude")
44-
.addNumberProperty("longitude")
45-
.addRequired("latitude", "longitude"))
41+
.addProperty("town", town -> town
42+
.addString("name")
43+
.addProperty("location", location -> location
44+
.addNumber("latitude")
45+
.addNumber("longitude")
46+
.addRequired("latitude", "longitude"))
47+
.addArray("people", "string")
48+
.addBoolean("active")
49+
.addRequired("name", "location"))
4650
.build();
4751
}
4852

4953
@Override
5054
public ToolContent process(McpParameters parameters) {
51-
52-
String name = parameters.get("name").asString().orElse(null);
53-
5455
Town paris = parameters.get("town")
5556
.as(param -> new Town(
5657
param.get("name").asString().get(),

integrations/mcp/tests/demo/src/main/java/io/helidon/integrations/mcp/demo/McpWeatherServerBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ public static void main(String[] args) {
3333
WebServer.builder()
3434
.routing(routing -> routing.addFeature(
3535
McpHttpFeatureConfig.builder()
36+
.name("mcp-weather")
37+
.version("1.0.0")
3638
.addTool(tool -> tool.name("name")
3739
.description("description")
38-
.schema(schema -> schema.addStringProperty("schema"))
40+
.schema(schema -> schema.addString("schema"))
3941
.tool(param -> ToolContents.imageContent("base64", MediaTypes.TEXT_PLAIN)))
4042

4143
.addResource(resource -> resource.name("name")

integrations/mcp/tests/demo/src/main/java/io/helidon/integrations/mcp/demo/McpWeatherSimpleResource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public MediaType mediaType() {
4848
public ResourceContent read() {
4949
return ResourceContents.list(
5050
ResourceContents.textContent("text"),
51-
ResourceContents.binaryContent("base64", MediaTypes.TEXT_PLAIN)
52-
);
51+
ResourceContents.binaryContent("base64", MediaTypes.TEXT_PLAIN));
5352
}
5453
}

0 commit comments

Comments
 (0)