fix: Fix validate prefix and toolName logic in prefixedToolName method
Signed-off-by: gongzhongqiang <gongzhongqiang@apache.org>
This commit is contained in:
committed by
Ilayaperumal Gopinathan
parent
77ee57cec0
commit
3f344a311d
@@ -17,6 +17,7 @@ package org.springframework.ai.mcp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.micrometer.common.util.StringUtils;
|
||||
import io.modelcontextprotocol.client.McpAsyncClient;
|
||||
import io.modelcontextprotocol.client.McpSyncClient;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures;
|
||||
@@ -58,12 +59,12 @@ public final class McpToolUtils {
|
||||
|
||||
public static String prefixedToolName(String prefix, String toolName) {
|
||||
|
||||
String input = prefix + "-" + toolName;
|
||||
|
||||
if (input == null || input.isEmpty()) {
|
||||
throw new IllegalArgumentException("Input string cannot be null or empty");
|
||||
if (StringUtils.isEmpty(prefix) || StringUtils.isEmpty(toolName)) {
|
||||
throw new IllegalArgumentException("Prefix or toolName cannot be null or empty");
|
||||
}
|
||||
|
||||
String input = prefix + "-" + toolName;
|
||||
|
||||
// Replace any character that isn't alphanumeric, underscore, or hyphen with
|
||||
// concatenation
|
||||
String formatted = input.replaceAll("[^a-zA-Z0-9_-]", "");
|
||||
|
||||
Reference in New Issue
Block a user