Skip to content

Commit c4d9463

Browse files
committed
polish(main): Some minor enhancements
1 parent a8d4788 commit c4d9463

File tree

10 files changed

+53
-23
lines changed

10 files changed

+53
-23
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.codeboyzhou.mcp.declarative.annotation;
22

3+
import com.github.codeboyzhou.mcp.declarative.util.StringHelper;
4+
35
import java.lang.annotation.ElementType;
46
import java.lang.annotation.Retention;
57
import java.lang.annotation.RetentionPolicy;
@@ -8,7 +10,7 @@
810
@Target(ElementType.TYPE)
911
@Retention(RetentionPolicy.RUNTIME)
1012
public @interface McpComponentScan {
11-
String basePackage() default "";
13+
String basePackage() default StringHelper.EMPTY;
1214

1315
Class<?> basePackageClass() default Object.class;
1416
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.codeboyzhou.mcp.declarative.annotation;
22

3+
import com.github.codeboyzhou.mcp.declarative.util.StringHelper;
4+
35
import java.lang.annotation.ElementType;
46
import java.lang.annotation.Retention;
57
import java.lang.annotation.RetentionPolicy;
@@ -9,7 +11,7 @@
911
@Retention(RetentionPolicy.RUNTIME)
1012
public @interface McpPrompt {
1113

12-
String name() default "";
14+
String name() default StringHelper.EMPTY;
1315

1416
String description();
1517
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.codeboyzhou.mcp.declarative.annotation;
22

3+
import com.github.codeboyzhou.mcp.declarative.util.StringHelper;
34
import io.modelcontextprotocol.spec.McpSchema;
45

56
import java.lang.annotation.ElementType;
@@ -12,7 +13,7 @@
1213
public @interface McpResource {
1314
String uri();
1415

15-
String name() default "";
16+
String name() default StringHelper.EMPTY;
1617

1718
String description();
1819

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.codeboyzhou.mcp.declarative.annotation;
22

3+
import com.github.codeboyzhou.mcp.declarative.util.StringHelper;
4+
35
import java.lang.annotation.ElementType;
46
import java.lang.annotation.Retention;
57
import java.lang.annotation.RetentionPolicy;
@@ -9,7 +11,7 @@
911
@Retention(RetentionPolicy.RUNTIME)
1012
public @interface McpTool {
1113

12-
String name() default "";
14+
String name() default StringHelper.EMPTY;
1315

1416
String description();
1517
}

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

Lines changed: 2 additions & 1 deletion
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
import java.util.Map;
67

@@ -37,7 +38,7 @@ public static McpServerConfiguration defaultConfiguration() {
3738
Map.of(),
3839
"/mcp/message",
3940
"/sse",
40-
"",
41+
StringHelper.EMPTY,
4142
8080
4243
);
4344
}

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

Lines changed: 3 additions & 1 deletion
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.util.StringHelper;
4+
35
import java.time.Duration;
46

57
public class McpServerInfo {
@@ -46,7 +48,7 @@ public static class Builder<T extends Builder<T>> {
4648

4749
protected String version = "1.0.0";
4850

49-
protected String instructions = "";
51+
protected String instructions = StringHelper.EMPTY;
5052

5153
protected Duration requestTimeout = Duration.ofSeconds(10);
5254

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

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

3+
import com.github.codeboyzhou.mcp.declarative.annotation.McpPrompts;
4+
import com.github.codeboyzhou.mcp.declarative.annotation.McpResources;
35
import com.github.codeboyzhou.mcp.declarative.annotation.McpTools;
46
import com.github.codeboyzhou.mcp.declarative.exception.McpServerException;
57
import com.github.codeboyzhou.mcp.declarative.server.McpServerInfo;
@@ -8,6 +10,8 @@
810
import com.github.codeboyzhou.mcp.declarative.server.TestMcpComponentScanBasePackageString;
911
import com.github.codeboyzhou.mcp.declarative.server.TestMcpComponentScanDefault;
1012
import com.github.codeboyzhou.mcp.declarative.server.TestMcpComponentScanIsNull;
13+
import com.github.codeboyzhou.mcp.declarative.server.TestMcpPrompts;
14+
import com.github.codeboyzhou.mcp.declarative.server.TestMcpResources;
1115
import com.github.codeboyzhou.mcp.declarative.server.TestMcpTools;
1216
import org.junit.jupiter.api.AfterEach;
1317
import org.junit.jupiter.api.BeforeEach;
@@ -42,10 +46,21 @@ void setUp() {
4246
void tearDown() throws NoSuchFieldException, IllegalAccessException {
4347
reflections = getReflectionsField();
4448
assertNotNull(reflections);
49+
4550
Map<String, Set<String>> scannedClasses = reflections.getStore().get(Scanners.TypesAnnotated.name());
51+
52+
Set<String> scannedPromptClass = scannedClasses.get(McpPrompts.class.getName());
53+
assertEquals(1, scannedPromptClass.size());
54+
assertEquals(scannedPromptClass.iterator().next(), TestMcpPrompts.class.getName());
55+
56+
Set<String> scannedResourceClass = scannedClasses.get(McpResources.class.getName());
57+
assertEquals(1, scannedResourceClass.size());
58+
assertEquals(scannedResourceClass.iterator().next(), TestMcpResources.class.getName());
59+
4660
Set<String> scannedToolClass = scannedClasses.get(McpTools.class.getName());
4761
assertEquals(1, scannedToolClass.size());
4862
assertEquals(scannedToolClass.iterator().next(), TestMcpTools.class.getName());
63+
4964
reflections = null;
5065
}
5166

@@ -81,10 +96,10 @@ void testStartSyncSseServer() {
8196
McpSseServerInfo serverInfo = McpSseServerInfo.builder()
8297
.instructions("test-mcp-sync-sse-server-instructions")
8398
.requestTimeout(Duration.ofSeconds(10))
84-
.baseUrl("http://127.0.0.1:8080")
99+
.baseUrl("http://127.0.0.1:8081")
85100
.messageEndpoint("/message")
86101
.sseEndpoint("/sse")
87-
.port(8080)
102+
.port(8081)
88103
.name("test-mcp-sync-sse-server")
89104
.version("1.0.0")
90105
.build();

src/test/java/com/github/codeboyzhou/mcp/declarative/server/TestMcpPrompts.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
@McpPrompts
88
public class TestMcpPrompts {
99

10+
@SuppressWarnings("unused")
1011
@McpPrompt(name = "prompt1", description = "prompt1")
1112
public static String prompt1(
12-
@McpPromptParam(name = "name", description = "name", required = true) String name,
13-
@McpPromptParam(name = "version", description = "version", required = true) String version
13+
@McpPromptParam(name = "argument1", description = "argument1", required = true) String argument1,
14+
@McpPromptParam(name = "argument2", description = "argument2", required = true) String argument2
1415
) {
15-
return "Hello " + name + ", I am " + version;
16+
return String.format("This is prompt1, required argument1: %s, required argument2: %s", argument1, argument2);
1617
}
1718

19+
@SuppressWarnings("unused")
1820
@McpPrompt(description = "prompt2")
1921
public static String prompt2(
20-
@McpPromptParam(name = "name", description = "name") String name,
21-
@McpPromptParam(name = "version", description = "version") String version
22+
@McpPromptParam(name = "argument1", description = "argument1") String argument1,
23+
@McpPromptParam(name = "argument2", description = "argument2") String argument2
2224
) {
23-
return "Hello " + name + ", I am " + version;
25+
return String.format("This is prompt2, optional argument1: %s, optional argument2: %s", argument1, argument2);
2426
}
2527

2628
}

src/test/java/com/github/codeboyzhou/mcp/declarative/server/TestMcpResources.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
@McpResources
77
public class TestMcpResources {
88

9+
@SuppressWarnings("unused")
910
@McpResource(uri = "test://resource1", name = "resource1", description = "resource1")
1011
public String resource1() {
11-
return System.lineSeparator();
12+
return "This is resource1 content";
1213
}
1314

15+
@SuppressWarnings("unused")
1416
@McpResource(uri = "test://resource2", description = "resource2")
1517
public String resource2() {
16-
return System.lineSeparator();
18+
return "This is resource2 content";
1719
}
1820

1921
}

src/test/java/com/github/codeboyzhou/mcp/declarative/server/TestMcpTools.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ public class TestMcpTools {
1010
@SuppressWarnings("unused")
1111
@McpTool(name = "tool1", description = "tool1")
1212
public static String tool1(
13-
@McpToolParam(name = "name", description = "name", required = true) String name,
14-
@McpToolParam(name = "version", description = "version", required = true) String version
13+
@McpToolParam(name = "argument1", description = "argument1", required = true) String argument1,
14+
@McpToolParam(name = "argument2", description = "argument2", required = true) String argument2
1515
) {
16-
return "Hello " + name + ", I am " + version;
16+
return String.format("This is tool1, required argument1: %s, required argument2: %s", argument1, argument2);
1717
}
1818

1919
@SuppressWarnings("unused")
2020
@McpTool(description = "tool2")
2121
public static String tool2(
22-
@McpToolParam(name = "name", description = "name") String name,
23-
@McpToolParam(name = "version", description = "version") String version
22+
@McpToolParam(name = "argument1", description = "argument1") String argument1,
23+
@McpToolParam(name = "argument2", description = "argument2") String argument2
2424
) {
25-
return "Hello " + name + ", I am " + version;
25+
return String.format("This is tool2, optional argument1: %s, optional argument2: %s", argument1, argument2);
2626
}
2727

2828
@SuppressWarnings("unused")
@@ -31,7 +31,8 @@ public static String tool3(
3131
@McpToolParam(name = "complexJsonSchema", description = "complexJsonSchema")
3232
TestMcpToolComplexJsonSchema complexJsonSchema
3333
) {
34-
return String.format("Hello, my name is %s, I am from %s", complexJsonSchema.name(), complexJsonSchema.country());
34+
return String.format("This is tool3 for testing complex json schema: my name is %s, I am from %s",
35+
complexJsonSchema.name(), complexJsonSchema.country());
3536
}
3637

3738
}

0 commit comments

Comments
 (0)