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(