Skip to content

Commit 3f344a3

Browse files
GOODBOY008ilayaperumalg
authored andcommitted
fix: Fix validate prefix and toolName logic in prefixedToolName method
Signed-off-by: gongzhongqiang <gongzhongqiang@apache.org>
1 parent 77ee57c commit 3f344a3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mcp/common/src/main/java/org/springframework/ai/mcp/McpToolUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.List;
1919

20+
import io.micrometer.common.util.StringUtils;
2021
import io.modelcontextprotocol.client.McpAsyncClient;
2122
import io.modelcontextprotocol.client.McpSyncClient;
2223
import io.modelcontextprotocol.server.McpServerFeatures;
@@ -58,12 +59,12 @@ private McpToolUtils() {
5859

5960
public static String prefixedToolName(String prefix, String toolName) {
6061

61-
String input = prefix + "-" + toolName;
62-
63-
if (input == null || input.isEmpty()) {
64-
throw new IllegalArgumentException("Input string cannot be null or empty");
62+
if (StringUtils.isEmpty(prefix) || StringUtils.isEmpty(toolName)) {
63+
throw new IllegalArgumentException("Prefix or toolName cannot be null or empty");
6564
}
6665

66+
String input = prefix + "-" + toolName;
67+
6768
// Replace any character that isn't alphanumeric, underscore, or hyphen with
6869
// concatenation
6970
String formatted = input.replaceAll("[^a-zA-Z0-9_-]", "");

0 commit comments

Comments
 (0)