Skip to content

Commit c1c6c77

Browse files
committed
feat(mcp-server-chat2mysql): Introduce multi-language support for Chat2MySQL prompts
1 parent 2d4154d commit c1c6c77

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ If you are looking for servers implemented with Typescript MCP SDK or Python MCP
2525

2626
These servers aim to demonstrate MCP features and the MCP Java SDK.
2727

28-
- [Chat2MySQL](https://github.com/codeboyzhou/mcp-java-sdk-examples/blob/main/mcp-server-chat2mysql/README.md) - Use AI agent to chat with your MySQL database
28+
- [Chat2MySQL](https://github.com/codeboyzhou/mcp-java-sdk-examples/blob/main/mcp-server-chat2mysql/README.md) - Use AI agent that supports multi-language to chat with your MySQL database
2929
- [Filesystem](https://github.com/codeboyzhou/mcp-java-sdk-examples/blob/main/mcp-server-filesystem/README.md) - Secure file operations with configurable access controls

mcp-server-chat2mysql/src/main/java/com/github/mcp/examples/server/chat2mysql/McpPrompts.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.mcp.examples.server.chat2mysql;
22

3+
import com.github.mcp.examples.server.chat2mysql.enums.PromptMessageEnding;
34
import com.github.mcp.examples.server.chat2mysql.util.SqlHelper;
45
import io.modelcontextprotocol.server.McpServerFeatures;
56
import io.modelcontextprotocol.server.McpSyncServer;
@@ -56,6 +57,7 @@ public static McpServerFeatures.SyncPromptSpecification generateSqlOptimizationT
5657

5758
promptTemplate.append("The EXPLAIN plan for the SQL statement is: ").append(SqlHelper.explainSql(sqlStr));
5859
promptTemplate.append("\n\nPlease provide optimization recommendations for the SQL statement.");
60+
promptTemplate.append("\n\n").append(PromptMessageEnding.ofCurrentUserLanguage());
5961

6062
McpSchema.TextContent content = new McpSchema.TextContent(promptTemplate.toString());
6163
McpSchema.PromptMessage message = new McpSchema.PromptMessage(McpSchema.Role.USER, content);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.mcp.examples.server.chat2mysql.enums;
2+
3+
public enum PromptMessageEnding {
4+
5+
en_US("en_US", "Please answer in English"),
6+
7+
zh_CN("zh_CN", "请使用中文回答"),
8+
9+
;
10+
11+
private final String code;
12+
13+
private final String prompt;
14+
15+
PromptMessageEnding(String code, String prompt) {
16+
this.code = code;
17+
this.prompt = prompt;
18+
}
19+
20+
public static String ofCurrentUserLanguage() {
21+
PromptMessageEnding[] values = values();
22+
for (PromptMessageEnding value : values) {
23+
final String language = System.getProperty("user.language");
24+
final String country = System.getProperty("user.country");
25+
final String locale = String.format("%s_%s", language, country);
26+
if (value.code.equals(locale)) {
27+
return value.prompt;
28+
}
29+
}
30+
return en_US.prompt;
31+
}
32+
33+
}

0 commit comments

Comments
 (0)