Skip to content

chore(main): Uses property for SDK version #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions mcp-server-chat2mysql/chat2mysql-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,4 @@
<artifactId>chat2mysql-commons</artifactId>
<packaging>jar</packaging>

<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

</project>
28 changes: 20 additions & 8 deletions mcp-server-chat2mysql/chat2mysql-declarative-sdk-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@
<artifactId>chat2mysql-declarative-sdk-example</artifactId>
<packaging>jar</packaging>

<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.github.codeboyzhou</groupId>
<artifactId>chat2mysql-commons</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.mcp.server.chat2mysql;

import com.github.codeboyzhou.mcp.declarative.annotation.McpComponentScan;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class McpStdioServerTest {

@Test
void classIsAnnotatedWithMcpComponentScan() {
Class<McpStdioServer> cls = McpStdioServer.class;
assertTrue(cls.isAnnotationPresent(McpComponentScan.class),
"McpStdioServer should be annotated with @McpComponentScan");

McpComponentScan ann = cls.getAnnotation(McpComponentScan.class);
assertEquals(McpStdioServer.class, ann.basePackageClass(),
"@McpComponentScan.basePackageClass should point to McpStdioServer.class");
}

@Test
void mainHandlesNoArgsWithoutException() {
// ensure main method does not throw when called with empty args
assertDoesNotThrow(() -> McpStdioServer.main(new String[0]),
"Calling main with no arguments should not throw an exception");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.github.mcp.server.chat2mysql;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import com.github.mcp.server.chat2mysql.util.SqlHelper;
import java.util.Set;

class MyMcpPromptsTest {

@Test
void generateSqlOptimizationTips_includesSqlAndPromptHeader() {
String sql = "SELECT * FROM users WHERE id = 1;";
try (MockedStatic<SqlHelper> helper = Mockito.mockStatic(SqlHelper.class)) {
helper.when(() -> SqlHelper.parseTableNames(sql))
.thenReturn(Set.of("users"));
helper.when(() -> SqlHelper.showCreateTable("users"))
.thenReturn("CREATE TABLE users (id INT PRIMARY KEY);");
helper.when(() -> SqlHelper.explainSql(sql))
.thenReturn("id | select_type | table | type | possible_keys | key | rows | Extra\n1 | SIMPLE | users | ALL | NULL | NULL | 1 | ");

String prompt = MyMcpPrompts.generateSqlOptimizationTips(sql);

// verify the prompt is not null or empty
assertNotNull(prompt, "Prompt should not be null");
assertFalse(prompt.isBlank(), "Prompt should not be blank");

// verify it includes the SQL statement
assertTrue(prompt.contains("The SQL statement is: " + sql),
"Prompt should include the SQL statement");

// verify it includes the explain plan section label and content
assertTrue(prompt.contains("The EXPLAIN plan for the SQL statement is:"),
"Prompt should include the EXPLAIN plan section");
assertTrue(prompt.contains("id | select_type"),
"Prompt should include the mocked EXPLAIN plan content");

// verify it includes the mocked table schema
assertTrue(prompt.contains("The table schema for users is: CREATE TABLE users"),
"Prompt should include the mocked table schema content");

// verify it ends with the language-specific message ending
String ending = com.github.mcp.server.chat2mysql.enums.PromptMessageEnding.ofCurrentUserLanguage();
assertTrue(prompt.endsWith(ending),
"Prompt should end with the language-specific message ending");
}
}
}
28 changes: 20 additions & 8 deletions mcp-server-chat2mysql/chat2mysql-native-sdk-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@
<artifactId>chat2mysql-native-sdk-example</artifactId>
<packaging>jar</packaging>

<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.github.codeboyzhou</groupId>
<artifactId>chat2mysql-commons</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.github.mcp.server.chat2mysql;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import io.modelcontextprotocol.server.McpSyncServer;
import io.modelcontextprotocol.server.McpServerFeatures.SyncPromptSpecification;
import io.modelcontextprotocol.spec.McpSchema;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import java.util.List;

class McpPromptsTest {

static {
// Enable Byte Buddy experimental support for Java 21
System.setProperty("net.bytebuddy.experimental", "true");
}

private static SyncPromptSpecification spec;

@BeforeAll
static void setup() {
// obtain the prompt specification
spec = McpPrompts.generateSqlOptimizationTips();
}

@Test
void specHasCorrectNameAndDescription() {
McpSchema.Prompt prompt = spec.prompt();
assertEquals("generate_sql_optimization_tips", prompt.name(),
"Prompt name should match");
assertEquals("Generate SQL optimization tips.", prompt.description(),
"Prompt description should match");
}

@Test
void specHasSqlArgument() {
List<McpSchema.PromptArgument> args = spec.prompt().arguments();
assertEquals(1, args.size(), "There should be exactly one argument");
McpSchema.PromptArgument arg = args.get(0);
assertEquals("sql", arg.name(), "Argument name should be 'sql'");
assertTrue(arg.required(), "SQL argument should be required");
}

@Test
void addAllToRegistersPromptOnServer() {
McpSyncServer server = mock(McpSyncServer.class);
McpPrompts.addAllTo(server);
// verify that addPrompt was called with the correct prompt specification properties
ArgumentCaptor<SyncPromptSpecification> captor = ArgumentCaptor.forClass(SyncPromptSpecification.class);
verify(server).addPrompt(captor.capture());
SyncPromptSpecification actual = captor.getValue();
assertEquals(spec.prompt().name(), actual.prompt().name(), "Prompt name should match");
assertEquals(spec.prompt().description(), actual.prompt().description(), "Prompt description should match");
assertEquals(spec.prompt().arguments().size(),
actual.prompt().arguments().size(), "Argument count should match");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

package com.github.mcp.server.chat2mysql;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.mockito.MockedStatic;

import java.lang.reflect.Method;
import java.lang.reflect.Field;

import io.modelcontextprotocol.server.McpSyncServer;

class McpStdioServerTest {

private McpStdioServer stdioServer;

@BeforeEach
void setUp() {
stdioServer = new McpStdioServer();
}

@Test
void initializeShouldSetServerField() throws Exception {
// call private initialize()
Method init = McpStdioServer.class.getDeclaredMethod("initialize");
init.setAccessible(true);
init.invoke(stdioServer);

// reflectively get 'server' field
Field field = McpStdioServer.class.getDeclaredField("server");
field.setAccessible(true);
Object serverInstance = field.get(stdioServer);

assertNotNull(serverInstance, "server field should be initialized");
assertTrue(serverInstance instanceof McpSyncServer,
"server field should be an instance of McpSyncServer");
}

@Test
void mainShouldCallPromptsAddAllTo() {
// mock McpPrompts static
try (MockedStatic<McpPrompts> prompts = mockStatic(McpPrompts.class)) {
// ensure no exception
assertDoesNotThrow(() -> McpStdioServer.main(new String[0]));

// verify addAllTo was called with any McpSyncServer
prompts.verify(() -> McpPrompts.addAllTo(any(McpSyncServer.class)), times(1));
}
}
}
7 changes: 0 additions & 7 deletions mcp-server-chat2mysql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
</modules>

<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!--==================== maven plugin versions ====================-->
<maven-shade-plugin.version>3.6.0</maven-shade-plugin.version>
<!--==================== dependency versions ====================-->
<mysql-connector-j.version>9.2.0</mysql-connector-j.version>
</properties>
Expand Down
9 changes: 0 additions & 9 deletions mcp-server-filesystem/filesystem-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,4 @@

<artifactId>filesystem-commons</artifactId>
<packaging>jar</packaging>

<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

</project>
28 changes: 20 additions & 8 deletions mcp-server-filesystem/filesystem-declarative-sdk-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@
<artifactId>filesystem-declarative-sdk-example</artifactId>
<packaging>jar</packaging>

<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.github.codeboyzhou</groupId>
<artifactId>filesystem-commons</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class McpStdioServer {

public static void main(String[] args) {
McpServerInfo serverInfo = McpServerInfo.builder().name(SERVER_NAME).version(SERVER_VERSION).build();
McpServers.run(McpSseServer.class, args).startSyncStdioServer(serverInfo);
McpServers.run(McpStdioServer.class, args).startSyncStdioServer(serverInfo);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.mcp.examples.server.filesystem;

import com.github.codeboyzhou.mcp.declarative.McpServers;
import com.github.codeboyzhou.mcp.declarative.server.McpSseServerInfo;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class McpSseServerTest {

static {
// Enable Byte Buddy experimental support for Java 21
System.setProperty("net.bytebuddy.experimental", "true");
}

@Test
void mainInvokesServerRun() {
try (MockedStatic<McpServers> ms = mockStatic(McpServers.class)) {
com.github.codeboyzhou.mcp.declarative.McpServers fake = mock(com.github.codeboyzhou.mcp.declarative.McpServers.class);
ms.when(() -> McpServers.run(McpSseServer.class, new String[0])).thenReturn(fake);
assertDoesNotThrow(() -> McpSseServer.main(new String[0]));
verify(fake).startSyncSseServer(any(McpSseServerInfo.class));
}
}
}
Loading