Skip to content

Commit f25dd38

Browse files
committed
feat(config): Add getDefault() methods for configuration record classes and update default values
1 parent b3c8f09 commit f25dd38

File tree

10 files changed

+116
-35
lines changed

10 files changed

+116
-35
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,29 @@ public record McpServerCapabilities(
1515
@JsonProperty("completion") Boolean completion) {
1616

1717
/**
18-
* Creates a new instance of {@code McpServerCapabilities} with default values.
18+
* Creates a new instance of {@code Builder} to build {@code McpServerCapabilities}.
1919
*
20-
* <p>By default, all capabilities are set to {@code true}.
20+
* @return A new instance of {@code Builder}.
2121
*/
22-
@Deprecated
23-
public McpServerCapabilities() {
24-
this(true, true, true, true, true);
22+
public static Builder builder() {
23+
return new Builder();
2524
}
2625

2726
/**
28-
* Creates a new instance of {@code Builder} to build {@code McpServerCapabilities}.
27+
* Returns the default capabilities of the MCP server.
2928
*
30-
* @return A new instance of {@code Builder}.
29+
* <p>By default, all capabilities are set to {@code true}.
30+
*
31+
* @return The default capabilities of the MCP server.
3132
*/
32-
public static Builder builder() {
33-
return new Builder();
33+
public static McpServerCapabilities getDefault() {
34+
return builder()
35+
.resource(true)
36+
.subscribeResource(true)
37+
.prompt(true)
38+
.tool(true)
39+
.completion(true)
40+
.build();
3441
}
3542

3643
/** Builder class for {@code McpServerCapabilities}. */

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@ public record McpServerChangeNotification(
1717
@JsonProperty("tool") Boolean tool) {
1818

1919
/**
20-
* Creates a new instance of {@code McpServerChangeNotification} with default values.
20+
* Creates a new instance of {@code Builder} to build {@code McpServerChangeNotification}.
2121
*
22-
* <p>By default, all change notification flags are set to {@code true}.
22+
* @return A new instance of {@code Builder}.
2323
*/
24-
@Deprecated
25-
public McpServerChangeNotification() {
26-
this(true, true, true);
24+
public static Builder builder() {
25+
return new Builder();
2726
}
2827

2928
/**
30-
* Creates a new instance of {@code Builder} to build {@code McpServerChangeNotification}.
29+
* Returns the default change notification of the MCP server.
3130
*
32-
* @return A new instance of {@code Builder}.
31+
* <p>By default, all change notification flags are set to {@code true}.
32+
*
33+
* @return The default change notification of the MCP server.
3334
*/
34-
public static Builder builder() {
35-
return new Builder();
35+
public static McpServerChangeNotification getDefault() {
36+
return builder().resource(true).prompt(true).tool(true).build();
3637
}
3738

3839
/** Builder class for {@code McpServerChangeNotification}. */

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.github.codeboyzhou.mcp.declarative.enums.ServerMode;
55
import com.github.codeboyzhou.mcp.declarative.enums.ServerType;
6+
import com.github.codeboyzhou.mcp.declarative.util.StringHelper;
67

78
/**
89
* This record represents the configuration of an MCP (Model Context Protocol) server.
@@ -38,6 +39,35 @@ public static Builder builder() {
3839
return new Builder();
3940
}
4041

42+
/**
43+
* Returns the default configuration of the MCP server.
44+
*
45+
* <p>By default, the enabled status is {@code true}, the server mode is {@link
46+
* ServerMode#STREAMABLE}, the server name is "mcp-server", the server version is "1.0.0", the
47+
* server type is {@link ServerType#SYNC}, the server instructions is {@link StringHelper#EMPTY},
48+
* the request timeout is 20000 milliseconds, the capabilities is {@link
49+
* McpServerCapabilities#getDefault()}, the change notification is {@link
50+
* McpServerChangeNotification#getDefault()}, the SSE is {@link McpServerSSE#getDefault()}, and
51+
* the streamable is {@link McpServerStreamable#getDefault()}.
52+
*
53+
* @return The default configuration of the MCP server.
54+
*/
55+
public static McpServerConfiguration getDefault() {
56+
return builder()
57+
.enabled(true)
58+
.mode(ServerMode.STREAMABLE)
59+
.name("mcp-server")
60+
.version("1.0.0")
61+
.type(ServerType.SYNC)
62+
.instructions(StringHelper.EMPTY)
63+
.requestTimeout(20000L)
64+
.capabilities(McpServerCapabilities.getDefault())
65+
.changeNotification(McpServerChangeNotification.getDefault())
66+
.sse(McpServerSSE.getDefault())
67+
.streamable(McpServerStreamable.getDefault())
68+
.build();
69+
}
70+
4171
/** Builder class for {@code McpServerConfiguration}. */
4272
public static class Builder {
4373
/** The profile. */

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

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

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.github.codeboyzhou.mcp.declarative.util.StringHelper;
45

56
/**
67
* This record represents the Server-Sent Events (SSE) configuration for an MCP (Model Context
@@ -27,6 +28,23 @@ public static Builder builder() {
2728
return new Builder();
2829
}
2930

31+
/**
32+
* Returns the default SSE configuration of the MCP server.
33+
*
34+
* <p>By default, the message endpoint is "/mcp/message", the endpoint is "/sse", the base URL is
35+
* {@link StringHelper#EMPTY}, and the port is 8080.
36+
*
37+
* @return The default SSE configuration of the MCP server.
38+
*/
39+
public static McpServerSSE getDefault() {
40+
return builder()
41+
.messageEndpoint("/mcp/message")
42+
.endpoint("/sse")
43+
.baseUrl(StringHelper.EMPTY)
44+
.port(8080)
45+
.build();
46+
}
47+
3048
/** Builder class for {@code McpServerSSE}. */
3149
public static class Builder {
3250
/** The message endpoint. */

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ public static Builder builder() {
2828
return new Builder();
2929
}
3030

31+
/**
32+
* Returns the default streamable http server configuration of the MCP server.
33+
*
34+
* <p>By default, the MCP endpoint is "/mcp/streamable", the disallow delete flag is {@code
35+
* false}, the keep-alive interval is 10000 milliseconds, and the port is 8080.
36+
*
37+
* @return The default streamable http server configuration of the MCP server.
38+
*/
39+
public static McpServerStreamable getDefault() {
40+
return builder()
41+
.mcpEndpoint("/mcp")
42+
.disallowDelete(false)
43+
.keepAliveInterval(0L)
44+
.port(8080)
45+
.build();
46+
}
47+
3148
/** Builder class for {@code McpServerStreamable}. */
3249
public static class Builder {
3350
/** The MCP endpoint. */

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,24 @@ public static class Builder<T extends Builder<T>> {
121121
/** The version of the MCP server. Default value is {@code "1.0.0"}. */
122122
protected String version = "1.0.0";
123123

124-
/** The instructions of the MCP server. Default value is {@code ""}. */
124+
/** The instructions of the MCP server. Default value is {@link StringHelper#EMPTY}. */
125125
protected String instructions = StringHelper.EMPTY;
126126

127127
/** The request timeout of the MCP server. Default value is {@code 20} seconds. */
128128
protected Duration requestTimeout = Duration.ofSeconds(20);
129129

130-
/** The capabilities of the MCP server. Default value is {@code new McpServerCapabilities()}. */
131-
protected McpServerCapabilities capabilities = new McpServerCapabilities();
130+
/**
131+
* The capabilities of the MCP server. Default value is {@link
132+
* McpServerCapabilities#getDefault()}.
133+
*/
134+
protected McpServerCapabilities capabilities = McpServerCapabilities.getDefault();
132135

133136
/**
134-
* The change notification of the MCP server. Default value is {@code new
135-
* McpServerChangeNotification()}.
137+
* The change notification of the MCP server. Default value is {@link
138+
* McpServerChangeNotification#getDefault()}.
136139
*/
137-
protected McpServerChangeNotification changeNotification = new McpServerChangeNotification();
140+
protected McpServerChangeNotification changeNotification =
141+
McpServerChangeNotification.getDefault();
138142

139143
/**
140144
* Returns the self reference of the builder, which is used to chain the method calls and ensure

src/main/resources/mcp-server.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ name: mcp-server
44
version: 1.0.0
55
type: SYNC
66
instructions: You are a helpful AI assistant
7-
request-timeout: 20000
7+
request-timeout: 60000
88
capabilities:
99
resource: true
10+
subscribe-resource: true
1011
prompt: true
1112
tool: true
1213
completion: true
@@ -18,4 +19,4 @@ streamable:
1819
mcp-endpoint: /mcp/message
1920
disallow-delete: true
2021
keep-alive-interval: 30000
21-
port: 8080
22+
port: 9000

src/test/java/com/github/codeboyzhou/mcp/declarative/McpServersTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ void testStartStreamableServer_shouldSucceed() {
111111
}
112112
}
113113

114+
@Test
115+
void testStartServer_useDefaultConfigFileName_shouldSucceed() {
116+
String configFileName = "mcp-server.yml";
117+
McpConfigurationLoader configLoader = new McpConfigurationLoader(configFileName);
118+
McpServerConfiguration configuration = configLoader.loadConfig();
119+
assertEquals(ServerMode.STREAMABLE, configuration.mode());
120+
assertDoesNotThrow(() -> servers.startServer());
121+
}
122+
114123
@Test
115124
void testStartServer_disabledMCP_shouldSucceed() {
116125
String configFileName = "test-mcp-server-disabled.yml";
@@ -153,15 +162,6 @@ void testStartServer_enableUnknownMode_shouldThrowException() {
153162
assertThrows(McpServerConfigurationException.class, () -> servers.startServer(configFileName));
154163
}
155164

156-
@Test
157-
void testStartServer_useDefaultConfigFileName_shouldSucceed() {
158-
String configFileName = "mcp-server.yml";
159-
McpConfigurationLoader configLoader = new McpConfigurationLoader(configFileName);
160-
McpServerConfiguration configuration = configLoader.loadConfig();
161-
assertEquals(ServerMode.STREAMABLE, configuration.mode());
162-
assertDoesNotThrow(() -> servers.startServer());
163-
}
164-
165165
private void verify(McpSyncClient client) {
166166
verifyServerInfo(client);
167167
verifyResourcesRegistered(client);

src/test/resources/test-mcp-server-enable-unknown-mode.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ instructions: You are a helpful AI assistant
77
request-timeout: 60000
88
capabilities:
99
resource: true
10+
subscribe-resource: true
1011
prompt: true
1112
tool: true
13+
completion: true
1214
change-notification:
1315
resource: true
1416
prompt: true

src/test/resources/test-mcp-server-with-profile-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ instructions: You are a helpful AI assistant (dev profile)
44
request-timeout: 60000
55
capabilities:
66
resource: false
7+
subscribe-resource: false
78
change-notification:
89
resource: false
910
streamable:

0 commit comments

Comments
 (0)