perf: mcp server testing and refreshing

This commit is contained in:
Junyan Qin
2025-11-04 18:14:59 +08:00
parent 1afecf01e4
commit 1046f3c2aa
10 changed files with 101 additions and 156 deletions

View File

@@ -51,7 +51,7 @@ export default function MCPCardComponent({
setTesting(true);
httpClient
.testMCPServer(cardVO.name)
.testMCPServer(cardVO.name, {})
.then((resp) => {
const taskId = resp.task_id;
@@ -62,9 +62,11 @@ export default function MCPCardComponent({
setTesting(false);
if (taskResp.runtime.exception) {
toast.error(t('mcp.testFailed') + taskResp.runtime.exception);
toast.error(
t('mcp.refreshFailed') + taskResp.runtime.exception,
);
} else {
toast.success(t('mcp.testSuccess'));
toast.success(t('mcp.refreshSuccess'));
}
// Refresh to get updated runtime_info
@@ -74,7 +76,7 @@ export default function MCPCardComponent({
}, 1000);
})
.catch((err) => {
toast.error(t('mcp.testFailed') + err.message);
toast.error(t('mcp.refreshFailed') + err.message);
setTesting(false);
});
}

View File

@@ -361,11 +361,22 @@ export default function MCPFormDialog({
}
async function testMcp() {
const serverName = form.getValues('name');
setMcpTesting(true);
try {
const { task_id } = await httpClient.testMCPServer(serverName);
const { task_id } = await httpClient.testMCPServer('_', {
name: form.getValues('name'),
mode: 'sse',
enable: true,
extra_args: {
url: form.getValues('url'),
timeout: form.getValues('timeout'),
ssereadtimeout: form.getValues('ssereadtimeout'),
headers: Object.fromEntries(
extraArgs.map((arg) => [arg.key, arg.value]),
),
},
});
if (!task_id) {
throw new Error(t('mcp.noTaskId'));
}
@@ -388,13 +399,11 @@ export default function MCPFormDialog({
tool_count: 0,
tools: [],
});
} else if (taskResp.runtime.result) {
await loadServerForEdit(serverName);
toast.success(t('mcp.testSuccess'));
} else {
toast.error(
`${t('mcp.testError')}: ${t('mcp.noResultReturned')}`,
);
if (isEditMode) {
await loadServerForEdit(form.getValues('name'));
}
toast.success(t('mcp.testSuccess'));
}
}
} catch (err) {

View File

@@ -524,8 +524,11 @@ export class BackendClient extends BaseHttpClient {
});
}
public testMCPServer(serverName: string): Promise<AsyncTaskCreatedResp> {
return this.post(`/api/v1/mcp/servers/${serverName}/test`);
public testMCPServer(
serverName: string,
serverData: object,
): Promise<AsyncTaskCreatedResp> {
return this.post(`/api/v1/mcp/servers/${serverName}/test`, serverData);
}
public installMCPServerFromGithub(

View File

@@ -312,9 +312,11 @@ const enUS = {
value: 'Value',
testing: 'Testing...',
connecting: 'Connecting...',
testSuccess: 'Connection test successful',
testFailed: 'Connection test failed: ',
testError: 'Connection test error',
testSuccess: 'Test successful',
testFailed: 'Test failed: ',
testError: 'Test error',
refreshSuccess: 'Refresh successful',
refreshFailed: 'Refresh failed: ',
connectionSuccess: 'Connection successful',
connectionFailed: 'Connection failed',
toolsFound: 'tools',

View File

@@ -314,9 +314,11 @@ const jaJP = {
value: '値',
testing: 'テスト中...',
connecting: '接続中...',
testSuccess: '接続テストに成功しました',
testFailed: '接続テストに失敗しました:',
testError: '接続テストエラー',
testSuccess: '刷新に成功しました',
testFailed: '刷新に失敗しました:',
testError: '刷新エラー',
refreshSuccess: '刷新に成功しました',
refreshFailed: '刷新に失敗しました:',
connectionSuccess: '接続に成功しました',
connectionFailed: '接続に失敗しました',
toolsFound: '個のツール',

View File

@@ -300,9 +300,11 @@ const zhHans = {
value: '值',
testing: '测试中...',
connecting: '连接中...',
testSuccess: '连接测试成功',
testFailed: '连接测试失败:',
testError: '连接测试出错',
testSuccess: '测试成功',
testFailed: '测试失败:',
testError: '刷新出错',
refreshSuccess: '刷新成功',
refreshFailed: '刷新失败:',
connectionSuccess: '连接成功',
connectionFailed: '连接失败',
toolsFound: '个工具',

View File

@@ -298,9 +298,11 @@ const zhHant = {
value: '值',
testing: '測試中...',
connecting: '連接中...',
testSuccess: '連接測試成功',
testFailed: '連接測試失敗:',
testError: '連接測試出錯',
testSuccess: '測試成功',
testFailed: '刷新失敗:',
testError: '刷新出錯',
refreshSuccess: '刷新成功',
refreshFailed: '刷新失敗:',
connectionSuccess: '連接成功',
connectionFailed: '連接失敗',
toolsFound: '個工具',