Skip to content

Commit ca5d1a0

Browse files
authored
Develop fix mcp api problem (#13429)
* Add mcpForm validate for mcpId and mcpName. * Fix old caller not support problem.
1 parent cf0551f commit ca5d1a0

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

ai/src/main/java/com/alibaba/nacos/ai/form/mcp/admin/McpDetailForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class McpDetailForm extends McpForm {
4141

4242
@Override
4343
public void validate() throws NacosApiException {
44-
super.validate();
44+
fillDefaultValue();
4545
if (StringUtils.isEmpty(serverSpecification)) {
4646
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,
4747
"Required parameter 'serverSpecification' type McpServerBasicInfo is not present");

ai/src/main/java/com/alibaba/nacos/ai/form/mcp/admin/McpForm.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package com.alibaba.nacos.ai.form.mcp.admin;
1818

1919
import com.alibaba.nacos.api.ai.constant.AiConstants;
20+
import com.alibaba.nacos.api.exception.NacosException;
2021
import com.alibaba.nacos.api.exception.api.NacosApiException;
2122
import com.alibaba.nacos.api.model.NacosForm;
23+
import com.alibaba.nacos.api.model.v2.ErrorCode;
2224
import com.alibaba.nacos.common.utils.StringUtils;
2325

2426
import java.io.Serial;
@@ -44,6 +46,10 @@ public class McpForm implements NacosForm {
4446
@Override
4547
public void validate() throws NacosApiException {
4648
fillDefaultValue();
49+
if (StringUtils.isEmpty(mcpId) && StringUtils.isEmpty(mcpName)) {
50+
throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,
51+
"Required parameter 'mcpId' or 'mcpName' type String at lease one is not present");
52+
}
4753
}
4854

4955
protected void fillDefaultValue() {

ai/src/main/java/com/alibaba/nacos/ai/service/McpServerOperationService.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ public String createMcpServer(String namespaceId, McpServerBasicInfo serverSpeci
292292
}
293293

294294
ServerVersionDetail versionDetail = serverSpecification.getVersionDetail();
295+
if (null == versionDetail && StringUtils.isNotBlank(serverSpecification.getVersion())) {
296+
versionDetail = new ServerVersionDetail();
297+
versionDetail.setVersion(serverSpecification.getVersion());
298+
serverSpecification.setVersionDetail(versionDetail);
299+
}
295300
if (Objects.isNull(versionDetail) || StringUtils.isEmpty(versionDetail.getVersion())) {
296301
throw new NacosApiException(NacosApiException.INVALID_PARAM, ErrorCode.PARAMETER_VALIDATE_ERROR,
297302
"Version must be specified in parameter `serverSpecification`");
@@ -309,7 +314,7 @@ public String createMcpServer(String namespaceId, McpServerBasicInfo serverSpeci
309314
injectToolAndEndpoint(namespaceId, serverSpecification.getId(), newSpecification,
310315
toolSpecification, endpointSpecification);
311316

312-
McpServerVersionInfo versionInfo = buildServerVersionInfo(serverSpecification, id, versionDetail);
317+
McpServerVersionInfo versionInfo = buildServerVersionInfo(newSpecification, id, versionDetail);
313318

314319
ConfigRequestInfo configRequestInfo = new ConfigRequestInfo();
315320
configRequestInfo.setUpdateForExist(Boolean.FALSE);
@@ -355,9 +360,17 @@ public void updateMcpServer(String namespaceId, boolean isPublish, McpServerBasi
355360

356361
String mcpServerId = serverSpecification.getId();
357362
mcpServerId = resolveMcpServerId(namespaceId, serverSpecification.getName(), mcpServerId);
363+
if (StringUtils.isEmpty(serverSpecification.getId())) {
364+
serverSpecification.setId(mcpServerId);
365+
}
358366
checkMcpServerIndex(mcpServerId);
359367

360368
ServerVersionDetail versionDetail = serverSpecification.getVersionDetail();
369+
if (null == versionDetail && StringUtils.isNotBlank(serverSpecification.getVersion())) {
370+
versionDetail = new ServerVersionDetail();
371+
versionDetail.setVersion(serverSpecification.getVersion());
372+
serverSpecification.setVersionDetail(versionDetail);
373+
}
361374
if (Objects.isNull(versionDetail) || StringUtils.isEmpty(versionDetail.getVersion())) {
362375
throw new NacosApiException(NacosApiException.INVALID_PARAM, ErrorCode.PARAMETER_VALIDATE_ERROR,
363376
"Version must be specified in parameter `serverSpecification`");

console/src/main/resources/static/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<link rel="stylesheet" type="text/css" href="console-ui/public/css/icon.css">
3636
<link rel="stylesheet" type="text/css" href="console-ui/public/css/font-awesome.css">
3737
<!-- 第三方css结束 -->
38-
<link href="./css/main.css?935076a0c49bdf2df6b1" rel="stylesheet"></head>
38+
<link href="./css/main.css?f608fa08915931f90aba" rel="stylesheet"></head>
3939

4040
<body>
4141
<div id="root" style="overflow:hidden"></div>
@@ -56,6 +56,6 @@
5656
<script src="console-ui/public/js/merge.js"></script>
5757
<script src="console-ui/public/js/loader.js"></script>
5858
<!-- 第三方js结束 -->
59-
<script type="text/javascript" src="./js/main.js?935076a0c49bdf2df6b1"></script></body>
59+
<script type="text/javascript" src="./js/main.js?f608fa08915931f90aba"></script></body>
6060

6161
</html>

console/src/main/resources/static/js/main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)