Skip to content

Commit 829f52e

Browse files
committed
refactor(annotation): Introduce McpServerApplication annotation
- Add McpServerApplication annotation to replace McpComponentScan - Update GuiceInjectorModule to use McpServerApplication for base package determination - Modify test classes to use the new McpServerApplication annotation - Deprecate McpComponentScan annotation
1 parent 7dd12bb commit 829f52e

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.lang.annotation.RetentionPolicy;
88
import java.lang.annotation.Target;
99

10+
@Deprecated
1011
@Target(ElementType.TYPE)
1112
@Retention(RetentionPolicy.RUNTIME)
1213
public @interface McpComponentScan {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.codeboyzhou.mcp.declarative.annotation;
2+
3+
import com.github.codeboyzhou.mcp.declarative.util.StringHelper;
4+
5+
import java.lang.annotation.ElementType;
6+
import java.lang.annotation.Retention;
7+
import java.lang.annotation.RetentionPolicy;
8+
import java.lang.annotation.Target;
9+
10+
@Target(ElementType.TYPE)
11+
@Retention(RetentionPolicy.RUNTIME)
12+
public @interface McpServerApplication {
13+
String basePackage() default StringHelper.EMPTY;
14+
15+
Class<?> basePackageClass() default Object.class;
16+
}

src/main/java/com/github/codeboyzhou/mcp/declarative/common/GuiceInjectorModule.java

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

3-
import com.github.codeboyzhou.mcp.declarative.annotation.McpComponentScan;
43
import com.github.codeboyzhou.mcp.declarative.annotation.McpI18nEnabled;
54
import com.github.codeboyzhou.mcp.declarative.annotation.McpPrompts;
65
import com.github.codeboyzhou.mcp.declarative.annotation.McpResources;
6+
import com.github.codeboyzhou.mcp.declarative.annotation.McpServerApplication;
77
import com.github.codeboyzhou.mcp.declarative.annotation.McpTools;
88
import com.github.codeboyzhou.mcp.declarative.server.factory.McpServerPromptFactory;
99
import com.github.codeboyzhou.mcp.declarative.server.factory.McpServerResourceFactory;
@@ -33,8 +33,8 @@ public GuiceInjectorModule(Class<?> applicationMainClass) {
3333
@Singleton
3434
@SuppressWarnings("unused")
3535
public Reflections provideReflections() {
36-
McpComponentScan scan = applicationMainClass.getAnnotation(McpComponentScan.class);
37-
final String basePackage = determineBasePackage(scan, applicationMainClass);
36+
McpServerApplication application = applicationMainClass.getAnnotation(McpServerApplication.class);
37+
final String basePackage = determineBasePackage(application, applicationMainClass);
3838
return new Reflections(basePackage, TypesAnnotated, MethodsAnnotated, FieldsAnnotated);
3939
}
4040

@@ -56,13 +56,13 @@ protected void configure() {
5656
bind(Boolean.class).annotatedWith(Names.named(VARIABLE_NAME_I18N_ENABLED)).toInstance(i18nEnabled);
5757
}
5858

59-
private String determineBasePackage(McpComponentScan scan, Class<?> applicationMainClass) {
60-
if (scan != null) {
61-
if (!scan.basePackage().trim().isBlank()) {
62-
return scan.basePackage();
59+
private String determineBasePackage(McpServerApplication application, Class<?> applicationMainClass) {
60+
if (application != null) {
61+
if (!application.basePackage().trim().isBlank()) {
62+
return application.basePackage();
6363
}
64-
if (scan.basePackageClass() != Object.class) {
65-
return scan.basePackageClass().getPackageName();
64+
if (application.basePackageClass() != Object.class) {
65+
return application.basePackageClass().getPackageName();
6666
}
6767
}
6868
return applicationMainClass.getPackageName();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.codeboyzhou.mcp.declarative.server;
22

3-
import com.github.codeboyzhou.mcp.declarative.annotation.McpComponentScan;
3+
import com.github.codeboyzhou.mcp.declarative.annotation.McpServerApplication;
44

5-
@McpComponentScan(basePackageClass = TestMcpComponentScanBasePackageClass.class)
5+
@McpServerApplication(basePackageClass = TestMcpComponentScanBasePackageClass.class)
66
public class TestMcpComponentScanBasePackageClass {
77
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.codeboyzhou.mcp.declarative.server;
22

3-
import com.github.codeboyzhou.mcp.declarative.annotation.McpComponentScan;
3+
import com.github.codeboyzhou.mcp.declarative.annotation.McpServerApplication;
44

5-
@McpComponentScan(basePackage = "com.github.codeboyzhou.mcp.declarative.server")
5+
@McpServerApplication(basePackage = "com.github.codeboyzhou.mcp.declarative.server")
66
public class TestMcpComponentScanBasePackageString {
77
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.codeboyzhou.mcp.declarative.server;
22

3-
import com.github.codeboyzhou.mcp.declarative.annotation.McpComponentScan;
3+
import com.github.codeboyzhou.mcp.declarative.annotation.McpServerApplication;
44

5-
@McpComponentScan
5+
@McpServerApplication
66
public class TestMcpComponentScanDefault {
77
}

0 commit comments

Comments
 (0)