Skip to content

Commit 7493fe7

Browse files
committed
feat(server): Integrate McpServerCapabilities and McpServerChangeNotification config into McpServerInfo
1 parent 1b7f3bf commit 7493fe7

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

src/main/java/com/github/codeboyzhou/mcp/declarative/configuration/McpServerCapabilities.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@
55
public record McpServerCapabilities(
66
@JsonProperty("resource") boolean resource,
77
@JsonProperty("prompt") boolean prompt,
8-
@JsonProperty("tool") boolean tool) {}
8+
@JsonProperty("tool") boolean tool) {
9+
10+
public McpServerCapabilities() {
11+
this(true, true, true);
12+
}
13+
}

src/main/java/com/github/codeboyzhou/mcp/declarative/configuration/McpServerChangeNotification.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@
55
public record McpServerChangeNotification(
66
@JsonProperty("resource") boolean resource,
77
@JsonProperty("prompt") boolean prompt,
8-
@JsonProperty("tool") boolean tool) {}
8+
@JsonProperty("tool") boolean tool) {
9+
10+
public McpServerChangeNotification() {
11+
this(true, true, true);
12+
}
13+
}

src/main/java/com/github/codeboyzhou/mcp/declarative/server/McpServerInfo.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.codeboyzhou.mcp.declarative.server;
22

3+
import com.github.codeboyzhou.mcp.declarative.configuration.McpServerCapabilities;
4+
import com.github.codeboyzhou.mcp.declarative.configuration.McpServerChangeNotification;
35
import com.github.codeboyzhou.mcp.declarative.util.Strings;
46
import java.time.Duration;
57

@@ -13,11 +15,17 @@ public class McpServerInfo {
1315

1416
private final Duration requestTimeout;
1517

18+
private final McpServerCapabilities capabilities;
19+
20+
private final McpServerChangeNotification changeNotification;
21+
1622
protected McpServerInfo(Builder<?> builder) {
1723
this.name = builder.name;
1824
this.version = builder.version;
1925
this.instructions = builder.instructions;
2026
this.requestTimeout = builder.requestTimeout;
27+
this.capabilities = builder.capabilities;
28+
this.changeNotification = builder.changeNotification;
2129
}
2230

2331
public static Builder<?> builder() {
@@ -40,6 +48,14 @@ public Duration requestTimeout() {
4048
return requestTimeout;
4149
}
4250

51+
public McpServerCapabilities capabilities() {
52+
return capabilities;
53+
}
54+
55+
public McpServerChangeNotification changeNotification() {
56+
return changeNotification;
57+
}
58+
4359
@SuppressWarnings("unchecked")
4460
public static class Builder<T extends Builder<T>> {
4561

@@ -51,6 +67,10 @@ public static class Builder<T extends Builder<T>> {
5167

5268
protected Duration requestTimeout = Duration.ofSeconds(20);
5369

70+
protected McpServerCapabilities capabilities = new McpServerCapabilities();
71+
72+
protected McpServerChangeNotification changeNotification = new McpServerChangeNotification();
73+
5474
protected T self() {
5575
return (T) this;
5676
}
@@ -78,5 +98,15 @@ public T requestTimeout(Duration requestTimeout) {
7898
this.requestTimeout = requestTimeout;
7999
return self();
80100
}
101+
102+
public T capabilities(McpServerCapabilities capabilities) {
103+
this.capabilities = capabilities;
104+
return self();
105+
}
106+
107+
public T changeNotification(McpServerChangeNotification changeNotification) {
108+
this.changeNotification = changeNotification;
109+
return self();
110+
}
81111
}
82112
}

src/main/java/com/github/codeboyzhou/mcp/declarative/server/factory/AbstractMcpServerFactory.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.github.codeboyzhou.mcp.declarative.server.factory;
22

33
import com.github.codeboyzhou.mcp.declarative.common.NamedThreadFactory;
4+
import com.github.codeboyzhou.mcp.declarative.configuration.McpServerCapabilities;
5+
import com.github.codeboyzhou.mcp.declarative.configuration.McpServerChangeNotification;
46
import com.github.codeboyzhou.mcp.declarative.server.McpServerInfo;
57
import com.github.codeboyzhou.mcp.declarative.server.component.McpServerComponentRegister;
68
import io.modelcontextprotocol.server.McpSyncServer;
@@ -18,18 +20,26 @@ public void startServer(S serverInfo) {
1820
McpSyncServer server =
1921
sync(serverInfo)
2022
.serverInfo(serverInfo.name(), serverInfo.version())
21-
.capabilities(serverCapabilities())
23+
.capabilities(serverCapabilities(serverInfo))
2224
.instructions(serverInfo.instructions())
2325
.requestTimeout(serverInfo.requestTimeout())
2426
.build();
2527
McpServerComponentRegister.of(server).registerComponents();
2628
}
2729

28-
private McpSchema.ServerCapabilities serverCapabilities() {
29-
return McpSchema.ServerCapabilities.builder()
30-
.resources(true, true)
31-
.prompts(true)
32-
.tools(true)
33-
.build();
30+
private McpSchema.ServerCapabilities serverCapabilities(S serverInfo) {
31+
McpSchema.ServerCapabilities.Builder capabilities = McpSchema.ServerCapabilities.builder();
32+
McpServerCapabilities capabilitiesConfig = serverInfo.capabilities();
33+
McpServerChangeNotification serverChangeNotification = serverInfo.changeNotification();
34+
if (capabilitiesConfig.resource()) {
35+
capabilities.resources(true, serverChangeNotification.resource());
36+
}
37+
if (capabilitiesConfig.prompt()) {
38+
capabilities.prompts(serverChangeNotification.prompt());
39+
}
40+
if (capabilitiesConfig.tool()) {
41+
capabilities.tools(serverChangeNotification.tool());
42+
}
43+
return capabilities.build();
3444
}
3545
}

0 commit comments

Comments
 (0)