Skip to content

Commit 1517dcf

Browse files
authored
[app-builder] mcp server compatible (#366)
1 parent 12b264b commit 1517dcf

File tree

1 file changed

+22
-11
lines changed
  • app-builder/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/util

1 file changed

+22
-11
lines changed

app-builder/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/util/McpUtils.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
package modelengine.fit.jober.aipp.util;
88

9-
import modelengine.fitframework.inspection.Validation;
9+
import modelengine.fitframework.util.StringUtils;
10+
11+
import java.net.URI;
12+
import java.net.URISyntaxException;
1013

1114
/**
1215
* 大模型上下文协议相关工具方法。
@@ -15,31 +18,39 @@
1518
* @since 2025-07-11
1619
*/
1720
public class McpUtils {
18-
private static final String SSE_ENDPOINT_SPLIT_DELIMITER = "/";
19-
2021
/**
2122
* 获取 {@code baseUrl} 部分。
2223
*
2324
* @param url 目标地址。
2425
* @return {@code baseUrl} 部分。
25-
* @throws IllegalArgumentException 当目标地址不包含 {@code sseEndpoint} 时
26+
* @throws IllegalArgumentException 当目标地址不合法时
2627
*/
2728
public static String getBaseUrl(String url) {
28-
String[] splits = url.split(SSE_ENDPOINT_SPLIT_DELIMITER);
29-
Validation.greaterThan(splits.length, 3, "The url is wrong. [url={0}]", url);
30-
return url.substring(0, url.length() - splits[splits.length - 1].length() - 1);
29+
try {
30+
URI uri = new URI(url);
31+
String baseUrl = uri.getScheme() + "://" + uri.getHost();
32+
if (uri.getPort() != -1) {
33+
baseUrl += ":" + uri.getPort();
34+
}
35+
return baseUrl;
36+
} catch (URISyntaxException e) {
37+
throw new IllegalArgumentException(StringUtils.format("The url is wrong. [url={0}]", url));
38+
}
3139
}
3240

3341
/**
3442
* 获取 {@code sseEndpoint} 部分。
3543
*
3644
* @param url 目标地址。
3745
* @return {@code sseEndpoint} 部分。
38-
* @throws IllegalArgumentException 当目标地址不包含 {@code sseEndpoint} 时
46+
* @throws IllegalArgumentException 当目标地址不合法时
3947
*/
4048
public static String getSseEndpoint(String url) {
41-
String[] splits = url.split(SSE_ENDPOINT_SPLIT_DELIMITER);
42-
Validation.greaterThan(splits.length, 3, "The url is wrong. [url={0}]", url);
43-
return SSE_ENDPOINT_SPLIT_DELIMITER + splits[splits.length - 1];
49+
try {
50+
URI uri = new URI(url);
51+
return uri.getPath();
52+
} catch (URISyntaxException e) {
53+
throw new IllegalArgumentException(StringUtils.format("The url is wrong. [url={0}]", url));
54+
}
4455
}
4556
}

0 commit comments

Comments
 (0)