Skip to content

Commit ab38c3f

Browse files
issue13423 (#13759)
* feature: 支持控制台启停mcp server * fix: 补充exportPath
1 parent e53ef7d commit ab38c3f

File tree

5 files changed

+93
-9
lines changed

5 files changed

+93
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ public void updateMcpServer(String namespaceId, boolean isPublish, McpServerBasi
479479
}
480480
}
481481
mcpServerVersionInfo.setVersions(versionDetails);
482+
mcpServerVersionInfo.setEnabled(newSpecification.isEnabled());
482483
}
483484

484485
ConfigFormV3 mcpServerVersionForm = buildMcpServerVersionForm(namespaceId, mcpServerVersionInfo);

console-ui/src/locales/zh-CN.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ const I18N_CONF = {
717717
operation: '操作',
718718
delete: '删除',
719719
details: '详情',
720+
online: '启用',
721+
offline: '禁用',
720722
sampleConfig: '配置示例',
721723
edit: '编辑',
722724
mcpServerType: '类型',

console-ui/src/pages/AI/McpManagement/McpManagement.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,83 @@ class McpManagement extends React.Component {
319319
}
320320
}
321321

322+
updateState = async record => {
323+
this.setState({ loading: true });
324+
const result = await request({
325+
url: 'v3/console/ai/mcp',
326+
method: 'get',
327+
data: {
328+
mcpId: record.id,
329+
mcpName: record.name,
330+
},
331+
error: () => {
332+
this.setState({ loading: false }, this.getData);
333+
},
334+
});
335+
336+
const data = result.data;
337+
console.log(data);
338+
let getEndpointSpecification = '';
339+
if (data && data.protocol && data.protocol !== 'stdio') {
340+
// 使用已有服务
341+
if (
342+
data.remoteServerConfig &&
343+
data.remoteServerConfig.serviceRef &&
344+
data.remoteServerConfig.serviceRef.serviceName
345+
) {
346+
getEndpointSpecification = JSON.stringify({
347+
type: 'REF',
348+
data: {
349+
groupName: data.remoteServerConfig.serviceRef.groupName,
350+
namespaceId: data.remoteServerConfig.serviceRef.namespaceId,
351+
serviceName: data.remoteServerConfig.serviceRef.serviceName,
352+
},
353+
});
354+
}
355+
// 外部直连
356+
else if (data && data.backendEndpoints && data.backendEndpoints.length > 0) {
357+
// 解析address
358+
const protocol = data.backendEndpoints[0].protocol;
359+
const address = data.backendEndpoints[0].address;
360+
const port = data.backendEndpoints[0].port;
361+
const exportPath = data.backendEndpoints[0].path;
362+
getEndpointSpecification = JSON.stringify({
363+
type: 'DIRECT',
364+
data: {
365+
protocol: protocol,
366+
address: address,
367+
port: port,
368+
exportPath: exportPath,
369+
},
370+
});
371+
}
372+
}
373+
374+
let toolSpec = '';
375+
if (data.toolSpec) {
376+
toolSpec = JSON.stringify(data.toolSpec);
377+
}
378+
379+
data.enabled = !data.enabled;
380+
request({
381+
url: `v3/console/ai/mcp`,
382+
type: 'put',
383+
data: {
384+
serverSpecification: JSON.stringify(data),
385+
toolSpecification: toolSpec,
386+
endpointSpecification: getEndpointSpecification,
387+
},
388+
success: res => {
389+
Message.success('Success');
390+
this.setState({ loading: false }, this.getData);
391+
},
392+
error: res => {
393+
Message.error(res.responseText || res.statusText);
394+
this.setState({ loading: false });
395+
},
396+
});
397+
};
398+
322399
removeConfig = record => {
323400
const { locale = {} } = this.props;
324401
const self = this;
@@ -380,6 +457,10 @@ class McpManagement extends React.Component {
380457
<a style={{ marginRight: 5 }} onClick={() => this.removeConfig(record)}>
381458
{locale.delete}
382459
</a>
460+
<span style={{ marginRight: 5 }}>|</span>
461+
<a style={{ marginRight: 5 }} onClick={() => this.updateState(record)}>
462+
{record.enabled ? locale.offline : locale.online}
463+
</a>
383464
</div>
384465
);
385466
}

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?a1d0aa3d6873c4668a1f" rel="stylesheet"></head>
38+
<link href="./css/main.css?ac4c35e44e7329c68e4a" 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?a1d0aa3d6873c4668a1f"></script></body>
59+
<script type="text/javascript" src="./js/main.js?ac4c35e44e7329c68e4a"></script></body>
6060

6161
</html>

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

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

0 commit comments

Comments
 (0)