Skip to content

Commit a3de232

Browse files
committed
Improving API
1 parent 87f31e7 commit a3de232

File tree

23 files changed

+648
-436
lines changed

23 files changed

+648
-436
lines changed

integrations/mcp/server/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<groupId>io.helidon.http.media</groupId>
4343
<artifactId>helidon-http-media-jackson</artifactId>
4444
</dependency>
45+
<dependency>
46+
<groupId>io.helidon.http.media</groupId>
47+
<artifactId>helidon-http-media-jsonp</artifactId>
48+
</dependency>
4549
<dependency>
4650
<groupId>io.helidon.webserver.testing.junit5</groupId>
4751
<artifactId>helidon-webserver-testing-junit5</artifactId>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
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+
117
package io.helidon.integrations.mcp.server;
218

19+
/**
20+
* Server capabilities.
21+
*/
322
public enum Capability {
23+
/**
24+
* Notify clients when list of {@link Tool} changes.
25+
*/
426
TOOL_LIST_CHANGED,
27+
/**
28+
* Notify clients when list of {@link Resource} changes
29+
*/
530
RESOURCE_LIST_CHANGED,
31+
/**
32+
* Allow clients to subscribe to a {@link Resource} and be notified when its content changes.
33+
*/
634
RESOURCE_SUBSCRIBE,
35+
/**
36+
* Notify clients when list of {@link Prompt} changes.
37+
*/
738
PROMPT_LIST_CHANGED,
39+
/**
40+
* Enable logging capability.
41+
*/
842
LOGGING,
43+
/**
44+
* Enable completion capability.
45+
*/
946
COMPLETION,
47+
/**
48+
* Enable pagination capability.
49+
*/
1050
PAGINATION
1151
}

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

Lines changed: 0 additions & 104 deletions
This file was deleted.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
import java.util.ArrayList;
20+
import java.util.HashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.UUID;
24+
25+
import jakarta.json.Json;
26+
import jakarta.json.JsonArrayBuilder;
27+
import jakarta.json.JsonObjectBuilder;
28+
29+
/**
30+
* Tool input schema description.
31+
*/
32+
public class JsonSchema {
33+
34+
private final Map<String, Object> schema = new HashMap<>();
35+
36+
private JsonSchema(Builder builder) {
37+
schema.put("id", builder.id);
38+
schema.put("type", builder.type);
39+
40+
JsonArrayBuilder array = Json.createArrayBuilder();
41+
builder.required.forEach(array::add);
42+
schema.put("required", array);
43+
44+
JsonObjectBuilder properties = Json.createObjectBuilder();
45+
builder.properties.forEach(properties::add);
46+
}
47+
48+
public static Builder builder() {
49+
return new Builder();
50+
}
51+
52+
public static class Builder {
53+
54+
private final String type;
55+
private final String id;
56+
private final List<String> required;
57+
private final Map<String, String> properties;
58+
59+
private Builder() {
60+
this.id = "jsonSchema-" + UUID.randomUUID();
61+
this.type = "object";
62+
this.required = new ArrayList<>();
63+
this.properties = new HashMap<>();
64+
}
65+
66+
public Builder object(String key, Class<?> type, boolean required) {
67+
this.properties.put(key, type.toString());
68+
if (required) {
69+
this.required.add(key);
70+
}
71+
return this;
72+
}
73+
74+
public Builder object(String key, Class<?> type) {
75+
this.properties.put(key, type.toString());
76+
this.required.add(key);
77+
return this;
78+
}
79+
80+
public JsonSchema build() {
81+
return new JsonSchema(this);
82+
}
83+
84+
}
85+
86+
}

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

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package io.helidon.integrations.mcp.server;
1818

19-
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Repeatable;
2020
import java.lang.annotation.Retention;
2121
import java.lang.annotation.Target;
2222

@@ -26,61 +26,125 @@
2626
import static java.lang.annotation.RetentionPolicy.RUNTIME;
2727

2828
/**
29-
* This interface contains a set of annotations for defining MCP declarative server.
29+
* This interface contains a set of annotations to define an MCP declarative server.
3030
*/
3131
public final class Mcp {
3232

33+
/**
34+
* Annotation to define a MCP server.
35+
*/
3336
@Target(TYPE)
3437
@Retention(RUNTIME)
3538
public @interface Server {
3639
String value() default "Helidon MCP Server";
3740
}
3841

42+
/**
43+
* Annotation to define the {@link Server} capabilities.
44+
*/
3945
@Target(TYPE)
4046
@Retention(RUNTIME)
47+
@Repeatable(Capabilities.class)
4148
public @interface Capability {
42-
io.helidon.integrations.mcp.server.Capability[] value();
49+
io.helidon.integrations.mcp.server.Capability value();
4350
}
4451

52+
/**
53+
* Set of {@link Capability}.
54+
*/
55+
@Target(TYPE)
56+
@Retention(RUNTIME)
57+
public @interface Capabilities {
58+
Capability[] value();
59+
}
60+
61+
/**
62+
* Annotation to describe an MCP component such as {@link Tool}, {@link Prompt} and {@link Resource}.
63+
*/
4564
@Target({TYPE, METHOD})
4665
@Retention(RUNTIME)
4766
public @interface Description {
4867
String value();
4968
}
5069

70+
/**
71+
* Annotation to define the {@link Server} version.
72+
*/
5173
@Target(TYPE)
5274
@Retention(RUNTIME)
5375
public @interface Version {
5476
String value();
5577
}
5678

79+
/**
80+
* Annotation to define an MCP Tool.
81+
*/
5782
@Target(METHOD)
5883
@Retention(RUNTIME)
59-
public @interface Prompt {
84+
public @interface Tool {
6085
String value() default "";
6186
}
6287

88+
/**
89+
* Annotation to manually register classes containing {@link Tool}.
90+
*/
91+
@Target(TYPE)
92+
@Retention(RUNTIME)
93+
public @interface Tools {
94+
Class<?>[] value();
95+
}
96+
97+
/**
98+
* Annotation to define an MCP Prompt.
99+
*/
63100
@Target(METHOD)
64101
@Retention(RUNTIME)
65-
public @interface Tool {
102+
public @interface Prompt {
66103
String value() default "";
67104
}
68105

69-
@Target(PARAMETER)
106+
/**
107+
* Annotation to manually register classes containing {@link Prompt}.
108+
*/
109+
@Target(TYPE)
70110
@Retention(RUNTIME)
71-
public @interface Param {
72-
String value();
111+
public @interface Prompts {
112+
Class<?>[] value();
73113
}
74114

115+
/**
116+
* Annotation to define an MCP resource.
117+
*/
75118
@Target(METHOD)
76119
@Retention(RUNTIME)
77120
public @interface Resource {
78121
String value() default "";
79122
}
80123

124+
/**
125+
* Annotation to manually register classes containing {@link Resource}.
126+
*/
127+
@Target(TYPE)
128+
@Retention(RUNTIME)
129+
public @interface Resources {
130+
Class<?>[] value();
131+
}
132+
133+
/**
134+
* Annotation to define a {@link Resource} URI
135+
*/
81136
@Target(METHOD)
82137
@Retention(RUNTIME)
83138
public @interface URI {
84139
String value();
85140
}
141+
142+
/**
143+
* Annotation to define a {@link Tool} and {@link Prompt} argument.
144+
*/
145+
@Target(PARAMETER)
146+
@Retention(RUNTIME)
147+
public @interface Param {
148+
String value();
149+
}
86150
}

0 commit comments

Comments
 (0)