Skip to content

Commit 42893d4

Browse files
Dev MCP: Allow enable/disable of methods
Signed-off-by: Phillip Kruger <[email protected]>
1 parent 5324eab commit 42893d4

File tree

25 files changed

+544
-225
lines changed

25 files changed

+544
-225
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.quarkus.runtime.annotations;
2+
3+
import static java.lang.annotation.ElementType.METHOD;
4+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
5+
6+
import java.lang.annotation.Documented;
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.Target;
9+
10+
/**
11+
* Enable a JsonRPC Method for MCP by default
12+
*/
13+
@Retention(RUNTIME)
14+
@Target({ METHOD })
15+
@Documented
16+
public @interface DevMCPEnableByDefault {
17+
18+
}

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/DevUIContent.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ public class DevUIContent {
1111
private final byte[] template;
1212
private final Map<String, Object> data;
1313
private final Map<String, String> descriptions;
14+
private final Map<String, String> mcpDefaultEnabled;
1415
private final Map<String, String> contentTypes;
1516

1617
private DevUIContent(DevUIContent.Builder builder) {
1718
this.fileName = builder.fileName;
1819
this.template = builder.template;
1920
this.data = builder.data;
2021
this.descriptions = builder.descriptions;
22+
this.mcpDefaultEnabled = builder.mcpDefaultEnabled;
2123
this.contentTypes = builder.contentTypes;
2224
}
2325

@@ -37,6 +39,10 @@ public Map<String, String> getDescriptions() {
3739
return descriptions;
3840
}
3941

42+
public Map<String, String> getMcpDefaultEnables() {
43+
return mcpDefaultEnabled;
44+
}
45+
4046
public Map<String, String> getContentTypes() {
4147
return contentTypes;
4248
}
@@ -51,6 +57,7 @@ public static class Builder {
5157
private Map<String, Object> data;
5258
private Map<String, String> descriptions;
5359
private Map<String, String> contentTypes;
60+
private Map<String, String> mcpDefaultEnabled;
5461

5562
private Builder() {
5663
this.data = new HashMap<>();
@@ -88,6 +95,11 @@ public Builder descriptions(Map<String, String> descriptions) {
8895
return this;
8996
}
9097

98+
public Builder mcpDefaultEnables(Map<String, String> mcpDefaultEnabled) {
99+
this.mcpDefaultEnabled = mcpDefaultEnabled;
100+
return this;
101+
}
102+
91103
public Builder contentTypes(Map<String, String> contentTypes) {
92104
this.contentTypes = contentTypes;
93105
return this;

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/buildtime/BuildTimeActionBuildItem.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,31 @@ public SubscriptionBuilder subscriptionBuilder() {
6161
@Deprecated
6262
public <T> void addAction(String methodName,
6363
Function<Map<String, String>, T> action) {
64-
this.addAction(new DeploymentJsonRpcMethod(methodName, null, Usage.onlyDevUI(), action));
64+
this.addAction(new DeploymentJsonRpcMethod(methodName, null, Usage.onlyDevUI(), true, action));
6565
}
6666

6767
@Deprecated
6868
public <T> void addAssistantAction(String methodName,
6969
BiFunction<Object, Map<String, String>, T> action) {
70-
this.addAction(new DeploymentJsonRpcMethod(methodName, null, Usage.onlyDevUI(), action));
70+
this.addAction(new DeploymentJsonRpcMethod(methodName, null, Usage.onlyDevUI(), true, action));
7171
}
7272

7373
@Deprecated
7474
public <T> void addAction(String methodName,
7575
RuntimeValue runtimeValue) {
76-
this.addAction(new RecordedJsonRpcMethod(methodName, null, Usage.onlyDevUI(), runtimeValue));
76+
this.addAction(new RecordedJsonRpcMethod(methodName, null, Usage.onlyDevUI(), true, runtimeValue));
7777
}
7878

7979
@Deprecated
8080
public <T> void addSubscription(String methodName,
8181
Function<Map<String, String>, T> action) {
82-
this.addSubscription(new DeploymentJsonRpcMethod(methodName, null, Usage.onlyDevUI(), action));
82+
this.addSubscription(new DeploymentJsonRpcMethod(methodName, null, Usage.onlyDevUI(), true, action));
8383
}
8484

8585
@Deprecated
8686
public <T> void addSubscription(String methodName,
8787
RuntimeValue runtimeValue) {
88-
this.addSubscription(new RecordedJsonRpcMethod(methodName, null, Usage.onlyDevUI(), runtimeValue));
88+
this.addSubscription(new RecordedJsonRpcMethod(methodName, null, Usage.onlyDevUI(), true, runtimeValue));
8989
}
9090

9191
private BuildTimeActionBuildItem addAction(DeploymentJsonRpcMethod deploymentJsonRpcMethod) {
@@ -116,6 +116,7 @@ public final class ActionBuilder {
116116
private Function<Map<String, String>, ?> function;
117117
private BiFunction<Object, Map<String, String>, ?> assistantFunction;
118118
private RuntimeValue<?> runtimeValue;
119+
private boolean mcpEnabledByDefault = false;
119120

120121
public ActionBuilder methodName(String methodName) {
121122
this.methodName = methodName;
@@ -141,6 +142,11 @@ public ActionBuilder usage(EnumSet<Usage> usage) {
141142
return this;
142143
}
143144

145+
public ActionBuilder enableMcpFuctionByDefault() {
146+
this.mcpEnabledByDefault = true;
147+
return this;
148+
}
149+
144150
public <T> ActionBuilder function(Function<Map<String, String>, T> function) {
145151
if (this.runtimeValue != null || this.assistantFunction != null)
146152
throw new IllegalStateException("Only one of runtimeValue, function or assistantFunction is allowed");
@@ -170,13 +176,17 @@ public BuildTimeActionBuildItem build() {
170176
if (function != null) {
171177
return addAction(
172178
new DeploymentJsonRpcMethod(methodName, description, parameters, autoUsage(usage, description),
179+
mcpEnabledByDefault,
173180
function));
174181
} else if (runtimeValue != null) {
175182
return addAction(
176-
new RecordedJsonRpcMethod(methodName, description, autoUsage(usage, description), runtimeValue));
183+
new RecordedJsonRpcMethod(methodName, description, autoUsage(usage, description),
184+
mcpEnabledByDefault,
185+
runtimeValue));
177186
} else if (assistantFunction != null) {
178187
return addAction(
179188
new DeploymentJsonRpcMethod(methodName, description, parameters, autoUsage(usage, description),
189+
mcpEnabledByDefault,
180190
assistantFunction));
181191
} else {
182192
throw new IllegalStateException("Either function, assistantFunction or runtimeValue must be provided");
@@ -189,6 +199,7 @@ public final class SubscriptionBuilder {
189199
private String description;
190200
private Map<String, AbstractJsonRpcMethod.Parameter> parameters = new LinkedHashMap<>();;
191201
private EnumSet<Usage> usage;
202+
private boolean mcpEnabledByDefault = false;
192203
private Function<Map<String, String>, ?> function;
193204
private RuntimeValue<?> runtimeValue;
194205

@@ -216,6 +227,11 @@ public SubscriptionBuilder usage(EnumSet<Usage> usage) {
216227
return this;
217228
}
218229

230+
public SubscriptionBuilder enableMcpFuctionByDefault() {
231+
this.mcpEnabledByDefault = true;
232+
return this;
233+
}
234+
219235
public <T> SubscriptionBuilder function(Function<Map<String, String>, T> function) {
220236
this.function = function;
221237
return this;
@@ -233,10 +249,12 @@ public void build() {
233249
parameters = null;
234250
if (function != null) {
235251
addSubscription(new DeploymentJsonRpcMethod(methodName, description, parameters, autoUsage(usage, description),
252+
mcpEnabledByDefault,
236253
function));
237254
} else if (runtimeValue != null) {
238255
addSubscription(
239-
new RecordedJsonRpcMethod(methodName, description, autoUsage(usage, description), runtimeValue));
256+
new RecordedJsonRpcMethod(methodName, description, autoUsage(usage, description), mcpEnabledByDefault,
257+
runtimeValue));
240258
} else {
241259
throw new IllegalStateException("Either function or runtimeValue must be provided");
242260
}

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/buildtime/BuildTimeData.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class BuildTimeData {
77
private Object content;
88
private String description;
99
private String contentType = "application/json"; // default
10+
private boolean mcpEnabledByDefault = false;
1011

1112
public BuildTimeData() {
1213

@@ -21,9 +22,16 @@ public BuildTimeData(Object content, String description) {
2122
this.description = description;
2223
}
2324

24-
public BuildTimeData(Object content, String description, String contentType) {
25+
public BuildTimeData(Object content, String description, boolean mcpEnabledByDefault) {
2526
this.content = content;
2627
this.description = description;
28+
this.mcpEnabledByDefault = mcpEnabledByDefault;
29+
}
30+
31+
public BuildTimeData(Object content, String description, boolean mcpEnabledByDefault, String contentType) {
32+
this.content = content;
33+
this.description = description;
34+
this.mcpEnabledByDefault = mcpEnabledByDefault;
2735
this.contentType = contentType;
2836
}
2937

@@ -50,4 +58,12 @@ public String getContentType() {
5058
public void setContentType(String contentType) {
5159
this.contentType = contentType;
5260
}
61+
62+
public boolean isMcpEnabledByDefault() {
63+
return mcpEnabledByDefault;
64+
}
65+
66+
public void setMcpEnabledByDefault(boolean mcpEnabledByDefault) {
67+
this.mcpEnabledByDefault = mcpEnabledByDefault;
68+
}
5369
}

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/buildtime/QuteTemplateBuildItem.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,34 @@ public List<TemplateData> getTemplateDatas() {
3333
}
3434

3535
public void add(String templatename, Map<String, Object> data) {
36-
templateDatas.add(new TemplateData(templatename, templatename, data, Map.of(), Map.of())); // By default the template is used for only one file.
36+
templateDatas.add(new TemplateData(templatename, templatename, data, Map.of(), Map.of(), Map.of())); // By default the template is used for only one file.
3737
}
3838

3939
public void add(String templatename, String fileName, Map<String, Object> data, Map<String, String> descriptions,
40+
Map<String, String> mcpDefaultEnabled,
4041
Map<String, String> contentTypes) {
41-
templateDatas.add(new TemplateData(templatename, fileName, data, descriptions, contentTypes));
42+
templateDatas.add(new TemplateData(templatename, fileName, data, descriptions, mcpDefaultEnabled, contentTypes));
4243
}
4344

4445
public static class TemplateData {
4546
final String templateName;
4647
final String fileName;
4748
final Map<String, Object> data;
4849
final Map<String, String> descriptions;
50+
final Map<String, String> mcpDefaultEnabled;
4951
final Map<String, String> contentTypes;
5052

51-
private TemplateData(String templateName, String fileName, Map<String, Object> data, Map<String, String> descriptions,
53+
private TemplateData(String templateName,
54+
String fileName,
55+
Map<String, Object> data,
56+
Map<String, String> descriptions,
57+
Map<String, String> mcpDefaultEnabled,
5258
Map<String, String> contentTypes) {
5359
this.templateName = templateName;
5460
this.fileName = fileName;
5561
this.data = data;
5662
this.descriptions = descriptions;
63+
this.mcpDefaultEnabled = mcpDefaultEnabled;
5764
this.contentTypes = contentTypes;
5865
}
5966

@@ -73,6 +80,10 @@ public Map<String, String> getDescriptions() {
7380
return descriptions;
7481
}
7582

83+
public Map<String, String> getMcpDefaultEnables() {
84+
return mcpDefaultEnabled;
85+
}
86+
7687
public Map<String, String> getContentTypes() {
7788
return contentTypes;
7889
}

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/buildtime/jsonrpc/AbstractJsonRpcMethod.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ public abstract class AbstractJsonRpcMethod {
1515
private String description;
1616
private Map<String, Parameter> parameters;
1717
private EnumSet<Usage> usage;
18+
private boolean mcpEnabledByDefault = false;
1819

1920
public AbstractJsonRpcMethod() {
2021
}
2122

2223
public AbstractJsonRpcMethod(String methodName, String description,
23-
EnumSet<Usage> usage) {
24+
EnumSet<Usage> usage, boolean mcpEnabledByDefault) {
2425
this.methodName = methodName;
2526
this.description = description;
2627
this.usage = usage;
28+
this.mcpEnabledByDefault = mcpEnabledByDefault;
2729
}
2830

2931
public AbstractJsonRpcMethod(String methodName, String description, Map<String, Parameter> parameters,
30-
EnumSet<Usage> usage) {
32+
EnumSet<Usage> usage, boolean mcpEnabledByDefault) {
3133
this.methodName = methodName;
3234
this.description = description;
3335
this.parameters = parameters;
3436
this.usage = usage;
37+
this.mcpEnabledByDefault = mcpEnabledByDefault;
3538
}
3639

3740
public String getMethodName() {
@@ -82,6 +85,14 @@ public void setUsage(EnumSet<Usage> usage) {
8285
this.usage = usage;
8386
}
8487

88+
public boolean isMcpEnabledByDefault() {
89+
return mcpEnabledByDefault;
90+
}
91+
92+
public void setMcpEnabledByDefault(boolean mcpEnabledByDefault) {
93+
this.mcpEnabledByDefault = mcpEnabledByDefault;
94+
}
95+
8596
public static class Parameter {
8697
private Class<?> type;
8798
private String description;

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/buildtime/jsonrpc/DeploymentJsonRpcMethod.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,38 @@ public DeploymentJsonRpcMethod() {
2121
public DeploymentJsonRpcMethod(String methodName,
2222
String description,
2323
EnumSet<Usage> usage,
24+
boolean mcpEnabledByDefault,
2425
Function<Map<String, String>, ?> action) {
25-
super(methodName, description, usage);
26+
super(methodName, description, usage, mcpEnabledByDefault);
2627
this.action = action;
2728
}
2829

2930
public DeploymentJsonRpcMethod(String methodName,
3031
String description,
3132
Map<String, Parameter> parameters,
3233
EnumSet<Usage> usage,
34+
boolean mcpEnabledByDefault,
3335
Function<Map<String, String>, ?> action) {
34-
super(methodName, description, parameters, usage);
36+
super(methodName, description, parameters, usage, mcpEnabledByDefault);
3537
this.action = action;
3638
}
3739

3840
public DeploymentJsonRpcMethod(String methodName,
3941
String description,
4042
EnumSet<Usage> usage,
43+
boolean mcpEnabledByDefault,
4144
BiFunction<Object, Map<String, String>, ?> assistantAction) {
42-
super(methodName, description, usage);
45+
super(methodName, description, usage, mcpEnabledByDefault);
4346
this.assistantAction = assistantAction;
4447
}
4548

4649
public DeploymentJsonRpcMethod(String methodName,
4750
String description,
4851
Map<String, Parameter> parameters,
4952
EnumSet<Usage> usage,
53+
boolean mcpEnabledByDefault,
5054
BiFunction<Object, Map<String, String>, ?> assistantAction) {
51-
super(methodName, description, parameters, usage);
55+
super(methodName, description, parameters, usage, mcpEnabledByDefault);
5256
this.assistantAction = assistantAction;
5357
}
5458

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/buildtime/jsonrpc/RecordedJsonRpcMethod.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ public RecordedJsonRpcMethod() {
1818
public RecordedJsonRpcMethod(String methodName,
1919
String description,
2020
EnumSet<Usage> usage,
21+
boolean mcpEnabledByDefault,
2122
RuntimeValue runtimeValue) {
22-
super(methodName, description, usage);
23+
super(methodName, description, usage, mcpEnabledByDefault);
2324
this.runtimeValue = runtimeValue;
2425
}
2526

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/buildtime/jsonrpc/RuntimeJsonRpcMethod.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ public RuntimeJsonRpcMethod(String methodName,
2222
String description,
2323
Map<String, Parameter> parameters,
2424
EnumSet<Usage> usage,
25+
boolean mcpEnabledByDefault,
2526
Class<?> bean,
2627
boolean blocking,
2728
boolean nonBlocking) {
28-
super(methodName, description, parameters, usage);
29+
super(methodName, description, parameters, usage, mcpEnabledByDefault);
2930
this.bean = bean;
3031
this.blocking = blocking;
3132
this.nonBlocking = nonBlocking;

extensions/devui/deployment-spi/src/main/java/io/quarkus/devui/spi/page/AbstractPageBuildItem.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public void addBuildTimeData(String fieldName, Object fieldData, String descript
6262
this.buildTimeData.put(fieldName, new BuildTimeData(fieldData, description));
6363
}
6464

65+
public void addBuildTimeData(String fieldName, Object fieldData, String description, boolean mcpEnabledByDefault) {
66+
this.buildTimeData.put(fieldName, new BuildTimeData(fieldData, description, mcpEnabledByDefault));
67+
}
68+
6569
public Map<String, BuildTimeData> getBuildTimeData() {
6670
return this.buildTimeData;
6771
}

0 commit comments

Comments
 (0)