Skip to content

Commit 3d78502

Browse files
committed
chore(comment): Add Java doc comments
1 parent 1cb8333 commit 3d78502

File tree

59 files changed

+1556
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1556
-17
lines changed

src/main/java/com/github/codeboyzhou/mcp/declarative/McpServers.java

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,51 @@
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

21-
public class McpServers {
21+
/**
22+
* This class is a singleton that provides methods to start MCP servers.
23+
*
24+
* @apiNote Example usage:
25+
* <pre>{@code
26+
* McpServerInfo serverInfo = McpServerInfo.builder().build();
27+
* McpServers.run(MyApplication.class, args).startStdioServer(serverInfo);
28+
*
29+
* McpSseServerInfo sseServerInfo = McpSseServerInfo.builder().build();
30+
* McpServers.run(MyApplication.class, args).startSseServer(sseServerInfo);
31+
*
32+
* McpStreamableServerInfo streamableServerInfo = McpStreamableServerInfo.builder().build();
33+
* McpServers.run(MyApplication.class, args).startStreamableServer(streamableServerInfo);
34+
*
35+
* McpServers.run(MyApplication.class, args).startServer("mcp-server-config.yml");
36+
*
37+
* McpServers.run(MyApplication.class, args).startServer();
38+
* }</pre>
39+
*
40+
* @see <a href="https://codeboyzhou.github.io/mcp-declarative-java-sdk/getting-started">MCP
41+
* Declarative Java SDK Documentation</a>
42+
* @author codeboyzhou
43+
*/
44+
public final class McpServers {
2245

2346
private static final Logger log = LoggerFactory.getLogger(McpServers.class);
2447

48+
/** The singleton instance of McpServers. */
2549
private static final McpServers INSTANCE = new McpServers();
2650

51+
/** The dependency injector used to inject server components. */
2752
private static DependencyInjector injector;
2853

29-
private McpServers() {
30-
// Using singleton design pattern should have private constructor
31-
}
54+
/**
55+
* The constructor of McpServers. Using singleton design pattern should have private constructor.
56+
*/
57+
private McpServers() {}
3258

59+
/**
60+
* Initializes the McpServers instance with the specified application main class and arguments.
61+
*
62+
* @param applicationMainClass the main class of the application
63+
* @param args the arguments passed to the application
64+
* @return the singleton instance of McpServers
65+
*/
3366
public static McpServers run(Class<?> applicationMainClass, String[] args) {
3467
GuiceInjectorModule module = new GuiceInjectorModule(applicationMainClass);
3568
DependencyInjector injector = new GuiceDependencyInjector(Guice.createInjector(module));
@@ -38,29 +71,55 @@ public static McpServers run(Class<?> applicationMainClass, String[] args) {
3871
return INSTANCE;
3972
}
4073

74+
/**
75+
* Starts a standard input/output (stdio) server with the specified server info.
76+
*
77+
* @param serverInfo the server info for the stdio server
78+
*/
4179
public void startStdioServer(McpServerInfo serverInfo) {
4280
injector.getInstance(McpStdioServer.class).start(serverInfo);
4381
}
4482

83+
/**
84+
* Starts a http server-sent events (sse) server with the specified server info.
85+
*
86+
* @param serverInfo the server info for the sse server
87+
*/
4588
public void startSseServer(McpSseServerInfo serverInfo) {
4689
injector.getInstance(McpSseServer.class).start(serverInfo);
4790
}
4891

92+
/**
93+
* Starts a streamable http server with the specified server info.
94+
*
95+
* @param serverInfo the server info for the streamable server
96+
*/
4997
public void startStreamableServer(McpStreamableServerInfo serverInfo) {
5098
injector.getInstance(McpStreamableServer.class).start(serverInfo);
5199
}
52100

101+
/**
102+
* Starts a server with the specified configuration file name.
103+
*
104+
* @param configFileName the name of the configuration file
105+
*/
53106
public void startServer(String configFileName) {
54107
Assert.notNull(configFileName, "configFileName must not be null");
55108
YAMLConfigurationLoader configLoader = new YAMLConfigurationLoader(configFileName);
56109
doStartServer(configLoader.loadConfig());
57110
}
58111

112+
/** Starts a server with the default configuration file name. */
59113
public void startServer() {
60114
YAMLConfigurationLoader configLoader = new YAMLConfigurationLoader();
61115
doStartServer(configLoader.loadConfig());
62116
}
63117

118+
/**
119+
* Starts a server with the specified server configuration.
120+
*
121+
* @param configuration the server configuration
122+
*/
64123
private void doStartServer(McpServerConfiguration configuration) {
65124
if (configuration.enabled()) {
66125
ConfigurableMcpServerFactory.getServer(configuration).startServer();

src/main/java/com/github/codeboyzhou/mcp/declarative/annotation/McpI18nEnabled.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55
import java.lang.annotation.RetentionPolicy;
66
import java.lang.annotation.Target;
77

8+
/**
9+
* This annotation is used to mark a class as i18n enabled.
10+
*
11+
* <p>When the main class of MCP (Model Context Protocol) server application is annotated with
12+
* {@code @McpI18nEnabled}, it indicates that the server application supports internationalization
13+
* (i18n) for tool/prompt/resource methods. This allows for the translation of tool/prompt/resource
14+
* titles and descriptions into different languages.
15+
*
16+
* <p>Note: This annotation is only applicable to the main class of the MCP server application.
17+
*
18+
* @apiNote Example usage:
19+
* <pre>{@code
20+
* @McpI18nEnabled
21+
* public class MyMcpServerApplication {
22+
* // Application logic...
23+
* }
24+
* }</pre>
25+
*
26+
* @author codeboyzhou
27+
*/
828
@Target(ElementType.TYPE)
929
@Retention(RetentionPolicy.RUNTIME)
1030
public @interface McpI18nEnabled {}

src/main/java/com/github/codeboyzhou/mcp/declarative/annotation/McpJsonSchemaDefinition.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
import java.lang.annotation.RetentionPolicy;
66
import java.lang.annotation.Target;
77

8+
/**
9+
* This annotation is used to define the complex JSON schema type (such as custom Java data classes)
10+
* for an MCP (Model Context Protocol) server.
11+
*
12+
* <p>By using this annotation, you can define custom JSON schema types that are not natively
13+
* supported by the MCP protocol. This allows you to use more complex data models in your MCP
14+
* server.
15+
*
16+
* @see McpJsonSchemaDefinitionProperty
17+
* @author codeboyzhou
18+
*/
819
@Target(ElementType.TYPE)
920
@Retention(RetentionPolicy.RUNTIME)
1021
public @interface McpJsonSchemaDefinition {}

src/main/java/com/github/codeboyzhou/mcp/declarative/annotation/McpJsonSchemaDefinitionProperty.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,33 @@
66
import java.lang.annotation.RetentionPolicy;
77
import java.lang.annotation.Target;
88

9+
/**
10+
* This annotation is used to define the property of a complex JSON schema type (such as custom Java
11+
* data classes) for an MCP (Model Context Protocol) server.
12+
*
13+
* <p>By using this annotation, you can define custom JSON schema properties that are not natively
14+
* supported by the MCP protocol. This allows you to use more complex data models in your MCP
15+
* server.
16+
*
17+
* @see McpJsonSchemaDefinition
18+
* @author codeboyzhou
19+
*/
920
@Target(ElementType.FIELD)
1021
@Retention(RetentionPolicy.RUNTIME)
1122
public @interface McpJsonSchemaDefinitionProperty {
23+
24+
/** The name of the JSON schema property. If not specified, the field name will be used. */
1225
String name() default StringHelper.EMPTY;
1326

27+
/**
28+
* The description of the JSON schema property. If not specified, the default value {@code "Not
29+
* specified"} will be used.
30+
*/
1431
String description() default StringHelper.EMPTY;
1532

33+
/**
34+
* Whether the JSON schema property is required. If not specified, the default value {@code false}
35+
* will be used.
36+
*/
1637
boolean required() default false;
1738
}

src/main/java/com/github/codeboyzhou/mcp/declarative/annotation/McpPrompt.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,35 @@
66
import java.lang.annotation.RetentionPolicy;
77
import java.lang.annotation.Target;
88

9+
/**
10+
* This annotation is used to mark a method as an MCP (Model Context Protocol) prompt method.
11+
*
12+
* <p>The prompt's name defaults to the name of the annotated method. Prompt metadata such as title
13+
* and description can be specified via the corresponding attributes. If omitted, these metadata
14+
* fields will default to the literal string "Not specified".
15+
*
16+
* @apiNote Example usage:
17+
* <pre>{@code
18+
* @McpPrompt
19+
* public String getWeather(String city) {
20+
* // Method implementation...
21+
* }
22+
* }</pre>
23+
*
24+
* @see <a
25+
* href="https://modelcontextprotocol.io/docs/learn/server-concepts#core-server-features">MCP
26+
* Protocol Documentation</a>
27+
* @author codeboyzhou
28+
*/
929
@Target(ElementType.METHOD)
1030
@Retention(RetentionPolicy.RUNTIME)
1131
public @interface McpPrompt {
12-
32+
/** The name of the prompt. Defaults to the name of the annotated method. */
1333
String name() default StringHelper.EMPTY;
1434

35+
/** The title of the prompt. Defaults to the literal string "Not specified". */
1536
String title() default StringHelper.EMPTY;
1637

38+
/** The description of the prompt. Defaults to the literal string "Not specified". */
1739
String description() default StringHelper.EMPTY;
1840
}

src/main/java/com/github/codeboyzhou/mcp/declarative/annotation/McpPromptParam.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,39 @@
66
import java.lang.annotation.RetentionPolicy;
77
import java.lang.annotation.Target;
88

9+
/**
10+
* This annotation is used to mark a method parameter as an MCP (Model Context Protocol) prompt
11+
* parameter.
12+
*
13+
* <p>The parameter's name must be specified explicitly. Parameter metadata such as title,
14+
* description, and required can be specified via the corresponding attributes. If omitted, these
15+
* metadata fields will default to the literal string "Not specified" and {@code false}.
16+
*
17+
* @apiNote Example usage:
18+
* <pre>{@code
19+
* @McpPrompt
20+
* public String getWeather(@McpPromptParam(name = "city") String city) {
21+
* // Method implementation...
22+
* }
23+
* }</pre>
24+
*
25+
* @see <a
26+
* href="https://modelcontextprotocol.io/docs/learn/server-concepts#core-server-features">MCP
27+
* Protocol Documentation</a>
28+
* @author codeboyzhou
29+
*/
930
@Target(ElementType.PARAMETER)
1031
@Retention(RetentionPolicy.RUNTIME)
1132
public @interface McpPromptParam {
12-
33+
/** The name of the prompt parameter. */
1334
String name();
1435

36+
/** The title of the prompt parameter. Defaults to the literal string "Not specified". */
1537
String title() default StringHelper.EMPTY;
1638

39+
/** The description of the prompt parameter. Defaults to the literal string "Not specified". */
1740
String description() default StringHelper.EMPTY;
1841

42+
/** Whether the prompt parameter is required. Defaults to {@code false}. */
1943
boolean required() default false;
2044
}

src/main/java/com/github/codeboyzhou/mcp/declarative/annotation/McpResource.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,50 @@
77
import java.lang.annotation.RetentionPolicy;
88
import java.lang.annotation.Target;
99

10+
/**
11+
* This annotation is used to mark a method as an MCP (Model Context Protocol) resource method.
12+
*
13+
* <p>The resource's URI must be specified explicitly. Resource metadata such as name, title,
14+
* description, and MIME type can be specified via the corresponding attributes. If omitted, these
15+
* metadata fields will default to the literal string "Not specified" and "text/plain".
16+
*
17+
* @apiNote Example usage:
18+
* <pre>{@code
19+
* @McpResource(uri = "weather://forecast/{city}/{date}")
20+
* public String getWeather() {
21+
* // Method implementation...
22+
* }
23+
* }</pre>
24+
*
25+
* @see <a
26+
* href="https://modelcontextprotocol.io/docs/learn/server-concepts#core-server-features">MCP
27+
* Protocol Documentation</a>
28+
* @author codeboyzhou
29+
*/
1030
@Target(ElementType.METHOD)
1131
@Retention(RetentionPolicy.RUNTIME)
1232
public @interface McpResource {
33+
/** The URI of the resource. */
1334
String uri();
1435

36+
/** The name of the resource. Defaults to the name of the annotated method. */
1537
String name() default StringHelper.EMPTY;
1638

39+
/** The title of the resource. Defaults to the literal string "Not specified". */
1740
String title() default StringHelper.EMPTY;
1841

42+
/** The description of the resource. Defaults to the literal string "Not specified". */
1943
String description() default StringHelper.EMPTY;
2044

45+
/** The MIME type of the resource. Defaults to "text/plain". */
2146
String mimeType() default "text/plain";
2247

48+
/**
49+
* The roles required to access the resource. Defaults to {@link McpSchema.Role#ASSISTANT} and
50+
* {@link McpSchema.Role#USER}.
51+
*/
2352
McpSchema.Role[] roles() default {McpSchema.Role.ASSISTANT, McpSchema.Role.USER};
2453

54+
/** The priority of the resource. Defaults to 1.0. */
2555
double priority() default 1.0;
2656
}

src/main/java/com/github/codeboyzhou/mcp/declarative/annotation/McpServerApplication.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,35 @@
66
import java.lang.annotation.RetentionPolicy;
77
import java.lang.annotation.Target;
88

9+
/**
10+
* This annotation is used to mark a class as an MCP (Model Context Protocol) server application.
11+
*
12+
* <p>The base package for component scanning can be specified via the {@code basePackage}
13+
* attribute. If not specified, the package of the annotated class will be used.
14+
*
15+
* @apiNote Example usage:
16+
* <pre>{@code
17+
* @McpServerApplication(basePackage = "com.example.mcp")
18+
* public class MyMcpServerApplication {
19+
* // Application logic...
20+
* }
21+
* }</pre>
22+
*
23+
* @see <a href="https://modelcontextprotocol.io/docs/learn/server-concepts">MCP Protocol
24+
* Documentation</a>
25+
* @author codeboyzhou
26+
*/
927
@Target(ElementType.TYPE)
1028
@Retention(RetentionPolicy.RUNTIME)
1129
public @interface McpServerApplication {
30+
/** The base package for component scanning. Defaults to the package of the annotated class. */
1231
String basePackage() default StringHelper.EMPTY;
1332

33+
/**
34+
* The base package class for component scanning. Defaults to {@link Object.class}.
35+
*
36+
* <p>Note: This attribute is intended to be used when the base package cannot be determined
37+
* statically. In most cases, {@link #basePackage()} should be used instead.
38+
*/
1439
Class<?> basePackageClass() default Object.class;
1540
}

src/main/java/com/github/codeboyzhou/mcp/declarative/annotation/McpTool.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,35 @@
66
import java.lang.annotation.RetentionPolicy;
77
import java.lang.annotation.Target;
88

9+
/**
10+
* This annotation is used to mark a method as an MCP (Model Context Protocol) tool method.
11+
*
12+
* <p>The tool's name defaults to the name of the annotated method. Tool metadata such as title and
13+
* description can be specified via the corresponding attributes. If omitted, these metadata fields
14+
* will default to the literal string "Not specified".
15+
*
16+
* @apiNote Example usage:
17+
* <pre>{@code
18+
* @McpTool
19+
* public String getWeather(String city) {
20+
* // Method implementation...
21+
* }
22+
* }</pre>
23+
*
24+
* @see <a
25+
* href="https://modelcontextprotocol.io/docs/learn/server-concepts#core-server-features">MCP
26+
* Protocol Documentation</a>
27+
* @author codeboyzhou
28+
*/
929
@Target(ElementType.METHOD)
1030
@Retention(RetentionPolicy.RUNTIME)
1131
public @interface McpTool {
12-
32+
/** The name of the tool. Defaults to the name of the annotated method. */
1333
String name() default StringHelper.EMPTY;
1434

35+
/** The title of the tool. Defaults to the literal string "Not specified". */
1536
String title() default StringHelper.EMPTY;
1637

38+
/** The description of the tool. Defaults to the literal string "Not specified". */
1739
String description() default StringHelper.EMPTY;
1840
}

0 commit comments

Comments
 (0)