Skip to content

Commit 3fe2443

Browse files
committed
feat(config): Add builder pattern support for configuration record classes
1 parent 5732792 commit 3fe2443

File tree

6 files changed

+504
-4
lines changed

6 files changed

+504
-4
lines changed

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,85 @@ public record McpServerCapabilities(
1818
*
1919
* <p>By default, all capabilities are set to {@code true}.
2020
*/
21+
@Deprecated
2122
public McpServerCapabilities() {
2223
this(true, true, true, true);
2324
}
25+
26+
/**
27+
* Creates a new instance of {@code Builder} to build {@code McpServerCapabilities}.
28+
*
29+
* @return A new instance of {@code Builder}.
30+
*/
31+
public static Builder builder() {
32+
return new Builder();
33+
}
34+
35+
/** Builder class for {@code McpServerCapabilities}. */
36+
public static class Builder {
37+
/** The resource capability. */
38+
private Boolean resource;
39+
40+
/** The prompt capability. */
41+
private Boolean prompt;
42+
43+
/** The tool capability. */
44+
private Boolean tool;
45+
46+
/** The completion capability. */
47+
private Boolean completion;
48+
49+
/**
50+
* Sets the resource capability.
51+
*
52+
* @param resource The resource capability.
53+
* @return This builder instance.
54+
*/
55+
public Builder resource(Boolean resource) {
56+
this.resource = resource;
57+
return this;
58+
}
59+
60+
/**
61+
* Sets the prompt capability.
62+
*
63+
* @param prompt The prompt capability.
64+
* @return This builder instance.
65+
*/
66+
public Builder prompt(Boolean prompt) {
67+
this.prompt = prompt;
68+
return this;
69+
}
70+
71+
/**
72+
* Sets the tool capability.
73+
*
74+
* @param tool The tool capability.
75+
* @return This builder instance.
76+
*/
77+
public Builder tool(Boolean tool) {
78+
this.tool = tool;
79+
return this;
80+
}
81+
82+
/**
83+
* Sets the completion capability.
84+
*
85+
* @param completion The completion capability.
86+
* @return This builder instance.
87+
*/
88+
public Builder completion(Boolean completion) {
89+
this.completion = completion;
90+
return this;
91+
}
92+
93+
/**
94+
* Builds an instance of {@code McpServerCapabilities} with the configured values.
95+
*
96+
* @return A new instance of {@code McpServerCapabilities}.
97+
*/
98+
public McpServerCapabilities build() {
99+
return new McpServerCapabilities(resource, prompt, tool, completion);
100+
}
101+
}
24102
}

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,71 @@ public record McpServerChangeNotification(
2121
*
2222
* <p>By default, all change notification flags are set to {@code true}.
2323
*/
24+
@Deprecated
2425
public McpServerChangeNotification() {
2526
this(true, true, true);
2627
}
28+
29+
/**
30+
* Creates a new instance of {@code Builder} to build {@code McpServerChangeNotification}.
31+
*
32+
* @return A new instance of {@code Builder}.
33+
*/
34+
public static Builder builder() {
35+
return new Builder();
36+
}
37+
38+
/** Builder class for {@code McpServerChangeNotification}. */
39+
public static class Builder {
40+
/** The resource change notification flag. */
41+
private Boolean resource;
42+
43+
/** The prompt change notification flag. */
44+
private Boolean prompt;
45+
46+
/** The tool change notification flag. */
47+
private Boolean tool;
48+
49+
/**
50+
* Sets the resource change notification flag.
51+
*
52+
* @param resource The resource change notification flag.
53+
* @return This builder instance.
54+
*/
55+
public Builder resource(Boolean resource) {
56+
this.resource = resource;
57+
return this;
58+
}
59+
60+
/**
61+
* Sets the prompt change notification flag.
62+
*
63+
* @param prompt The prompt change notification flag.
64+
* @return This builder instance.
65+
*/
66+
public Builder prompt(Boolean prompt) {
67+
this.prompt = prompt;
68+
return this;
69+
}
70+
71+
/**
72+
* Sets the tool change notification flag.
73+
*
74+
* @param tool The tool change notification flag.
75+
* @return This builder instance.
76+
*/
77+
public Builder tool(Boolean tool) {
78+
this.tool = tool;
79+
return this;
80+
}
81+
82+
/**
83+
* Builds an instance of {@code McpServerChangeNotification} with the configured values.
84+
*
85+
* @return A new instance of {@code McpServerChangeNotification}.
86+
*/
87+
public McpServerChangeNotification build() {
88+
return new McpServerChangeNotification(resource, prompt, tool);
89+
}
90+
}
2791
}

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

Lines changed: 203 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,206 @@ public record McpServerConfiguration(
2727
@JsonProperty("capabilities") McpServerCapabilities capabilities,
2828
@JsonProperty("change-notification") McpServerChangeNotification changeNotification,
2929
@JsonProperty("sse") McpServerSSE sse,
30-
@JsonProperty("streamable") McpServerStreamable streamable) {}
30+
@JsonProperty("streamable") McpServerStreamable streamable) {
31+
32+
/**
33+
* Creates a new instance of {@code Builder} to build {@code McpServerConfiguration}.
34+
*
35+
* @return A new instance of {@code Builder}.
36+
*/
37+
public static Builder builder() {
38+
return new Builder();
39+
}
40+
41+
/** Builder class for {@code McpServerConfiguration}. */
42+
public static class Builder {
43+
/** The profile. */
44+
private String profile;
45+
46+
/** The enabled status. */
47+
private Boolean enabled;
48+
49+
/** The server mode. */
50+
private ServerMode mode;
51+
52+
/** The server name. */
53+
private String name;
54+
55+
/** The server version. */
56+
private String version;
57+
58+
/** The server type. */
59+
private ServerType type;
60+
61+
/** The server instructions. */
62+
private String instructions;
63+
64+
/** The request timeout. */
65+
private Long requestTimeout;
66+
67+
/** The server capabilities. */
68+
private McpServerCapabilities capabilities;
69+
70+
/** The change notification configuration. */
71+
private McpServerChangeNotification changeNotification;
72+
73+
/** The SSE configuration. */
74+
private McpServerSSE sse;
75+
76+
/** The streamable configuration. */
77+
private McpServerStreamable streamable;
78+
79+
/**
80+
* Sets the profile.
81+
*
82+
* @param profile The profile.
83+
* @return This builder instance.
84+
*/
85+
public Builder profile(String profile) {
86+
this.profile = profile;
87+
return this;
88+
}
89+
90+
/**
91+
* Sets the enabled status.
92+
*
93+
* @param enabled The enabled status.
94+
* @return This builder instance.
95+
*/
96+
public Builder enabled(Boolean enabled) {
97+
this.enabled = enabled;
98+
return this;
99+
}
100+
101+
/**
102+
* Sets the server mode.
103+
*
104+
* @param mode The server mode.
105+
* @return This builder instance.
106+
*/
107+
public Builder mode(ServerMode mode) {
108+
this.mode = mode;
109+
return this;
110+
}
111+
112+
/**
113+
* Sets the server name.
114+
*
115+
* @param name The server name.
116+
* @return This builder instance.
117+
*/
118+
public Builder name(String name) {
119+
this.name = name;
120+
return this;
121+
}
122+
123+
/**
124+
* Sets the server version.
125+
*
126+
* @param version The server version.
127+
* @return This builder instance.
128+
*/
129+
public Builder version(String version) {
130+
this.version = version;
131+
return this;
132+
}
133+
134+
/**
135+
* Sets the server type.
136+
*
137+
* @param type The server type.
138+
* @return This builder instance.
139+
*/
140+
public Builder type(ServerType type) {
141+
this.type = type;
142+
return this;
143+
}
144+
145+
/**
146+
* Sets the server instructions.
147+
*
148+
* @param instructions The server instructions.
149+
* @return This builder instance.
150+
*/
151+
public Builder instructions(String instructions) {
152+
this.instructions = instructions;
153+
return this;
154+
}
155+
156+
/**
157+
* Sets the request timeout.
158+
*
159+
* @param requestTimeout The request timeout.
160+
* @return This builder instance.
161+
*/
162+
public Builder requestTimeout(Long requestTimeout) {
163+
this.requestTimeout = requestTimeout;
164+
return this;
165+
}
166+
167+
/**
168+
* Sets the server capabilities.
169+
*
170+
* @param capabilities The server capabilities.
171+
* @return This builder instance.
172+
*/
173+
public Builder capabilities(McpServerCapabilities capabilities) {
174+
this.capabilities = capabilities;
175+
return this;
176+
}
177+
178+
/**
179+
* Sets the change notification configuration.
180+
*
181+
* @param changeNotification The change notification configuration.
182+
* @return This builder instance.
183+
*/
184+
public Builder changeNotification(McpServerChangeNotification changeNotification) {
185+
this.changeNotification = changeNotification;
186+
return this;
187+
}
188+
189+
/**
190+
* Sets the SSE configuration.
191+
*
192+
* @param sse The SSE configuration.
193+
* @return This builder instance.
194+
*/
195+
public Builder sse(McpServerSSE sse) {
196+
this.sse = sse;
197+
return this;
198+
}
199+
200+
/**
201+
* Sets the streamable configuration.
202+
*
203+
* @param streamable The streamable configuration.
204+
* @return This builder instance.
205+
*/
206+
public Builder streamable(McpServerStreamable streamable) {
207+
this.streamable = streamable;
208+
return this;
209+
}
210+
211+
/**
212+
* Builds a new instance of {@code McpServerConfiguration}.
213+
*
214+
* @return A new instance of {@code McpServerConfiguration}.
215+
*/
216+
public McpServerConfiguration build() {
217+
return new McpServerConfiguration(
218+
profile,
219+
enabled,
220+
mode,
221+
name,
222+
version,
223+
type,
224+
instructions,
225+
requestTimeout,
226+
capabilities,
227+
changeNotification,
228+
sse,
229+
streamable);
230+
}
231+
}
232+
}

0 commit comments

Comments
 (0)