@@ -9,13 +9,19 @@ Declarative [MCP Java SDK](https://github.com/modelcontextprotocol/java-sdk) Dev
99
1010## Advantages
1111
12- - No Spring Framework Required.
13- - Instant MCP Java server in 1 LOC.
14- - No need to write more SDK low-level codes.
15- - Get rid of complex and lengthy JSON schema definitions.
16- - Just focus on your core logic (resources/prompts/tools).
17- - Configuration file compatible with the Spring AI framework.
18- - Built-in multi-languages support for MCP server (resources/prompts/tools).
12+ 🚫 No Spring Framework Required.
13+
14+ ⚡ Instant MCP Java server in 1 LOC.
15+
16+ 🎉 No need to write more SDK low-level code.
17+
18+ 👏 Get rid of complex and lengthy JSON schema definitions.
19+
20+ 🎯 Just focus on your core logic (resources/prompts/tools).
21+
22+ 🔌 Configuration file compatible with the Spring AI Framework.
23+
24+ 🌍 Built-in multi-languages support for MCP server (resources/prompts/tools).
1925
2026## Showcase
2127
@@ -25,22 +31,29 @@ Just put this one line code in your `main` method:
2531// You can use this annotation to specify the base package
2632// to scan for MCP resources, prompts, tools, but it's optional.
2733// If not specified, it will scan the package where the main method is located.
28- @McpComponentScan (basePackage = " com.github.codeboyzhou.mcp.server.examples" )
34+ @McpServerApplication (basePackage = " com.github.codeboyzhou.mcp.server.examples" )
2935// Use this annotation to enable multi-languages support for MCP server components.
3036@McpI18nEnabled
3137public class MyMcpServer {
3238
33- public static void main (String [] args ) {
34- McpServers servers = McpServers . run(MyMcpServer . class, args);
35- // Start a STDIO MCP server
36- servers. startStdioServer(McpServerInfo . builder(). name(" mcp-server" ). version(" 1.0.0" ). build());
37- // or a HTTP SSE MCP server
38- servers. startSseServer(McpSseServerInfo . builder(). name(" mcp-server" ). version(" 1.0.0" ). port(8080 ). build());
39- // or start with yaml config file (compatible with the Spring AI framework)
40- servers. startServer();
41- // or start with a custom config file (compatible with the Spring AI framework)
42- servers. startServer(" my-mcp-server.yml" );
43- }
39+ public static void main (String [] args ) {
40+ McpServers servers = McpServers . run(MyMcpServer . class, args);
41+
42+ // Start a STDIO MCP server
43+ servers. startStdioServer(McpServerInfo . builder(). name(" mcp-server" ). version(" 1.0.0" ). build());
44+
45+ // or a HTTP SSE MCP server
46+ servers. startSseServer(McpSseServerInfo . builder(). name(" mcp-server" ). version(" 1.0.0" ). port(8080 ). build());
47+
48+ // or a Streamable HTTP MCP server
49+ servers. startStreamableServer(McpStreamableServerInfo . builder(). name(" mcp-server" ). version(" 1.0.0" ). port(8080 ). build());
50+
51+ // or start with yaml config file (compatible with Spring AI)
52+ servers. startServer();
53+
54+ // or start with a custom config file (compatible with Spring AI)
55+ servers. startServer(" my-mcp-server.yml" );
56+ }
4457
4558}
4659```
@@ -75,28 +88,27 @@ No need to care about the low-level details of native MCP Java SDK and how to cr
7588@McpResources
7689public class MyMcpResources {
7790
78- // This method defines a MCP resource to expose the OS env variables
79- @McpResource(uri = "env://variables", description = "OS env variables")
80- public String getSystemEnv() {
81- // Just put your logic code here, forget about the MCP SDK details.
82- return System.getenv().toString();
83- }
91+ // This method defines a MCP resource to expose the OS env variables
92+ @McpResource(uri = "env://variables", description = "OS env variables")
93+ public String getSystemEnv() {
94+ // Just put your logic code here, forget about the MCP SDK details.
95+ return System.getenv().toString();
96+ }
8497
85- // Your other MCP resources here...
98+ // Your other MCP resources here...
8699}
87100```
88101
89102``` java
90103@McpPrompts
91104public class MyMcpPrompts {
92105
93- // This method defines a MCP prompt to read a file
94- @McpPrompt (description = " A simple prompt to read a file" )
95- public String readFile (
96- @McpPromptParam (name = " path" , description = " filepath" , required = true ) String path ) {
97- // Just put your logic code here, forget about the MCP SDK details.
98- return String . format(" What is the complete contents of the file: %s" , path);
99- }
106+ // This method defines a MCP prompt to read a file
107+ @McpPrompt (description = " A simple prompt to read a file" )
108+ public String readFile (@McpPromptParam (name = " path" , description = " filepath" , required = true ) String path ) {
109+ // Just put your logic code here, forget about the MCP SDK details.
110+ return String . format(" What is the complete contents of the file: %s" , path);
111+ }
100112
101113}
102114```
@@ -105,15 +117,14 @@ public class MyMcpPrompts {
105117@McpTools
106118public class MyMcpTools {
107119
108- // This method defines a MCP tool to read a file
109- @McpTool (description = " Read complete file contents with UTF-8 encoding" )
110- public String readFile (
111- @McpToolParam (name = " path" , description = " filepath" , required = true ) String path ) {
112- // Just put your logic code here, forget about the MCP SDK details.
113- return Files . readString(Path . of(path));
114- }
120+ // This method defines a MCP tool to read a file
121+ @McpTool (description = " Read complete file contents with UTF-8 encoding" )
122+ public String readFile (@McpToolParam (name = " path" , description = " filepath" , required = true ) String path ) {
123+ // Just put your logic code here, forget about the MCP SDK details.
124+ return Files . readString(Path . of(path));
125+ }
115126
116- // Your other MCP tools here...
127+ // Your other MCP tools here...
117128}
118129```
119130
0 commit comments