fix(mcp): surface per-app failures when importing MCP servers from apps

import_mcp_from_apps swallowed every importer error with unwrap_or(0),
so a corrupt config.toml surfaced as "imported 0 servers" with no hint
that anything went wrong.

Move the aggregation into McpService::import_from_all_apps: each app
imports best-effort (one bad file doesn't block the rest), and failures
are collected into a single error naming the failing apps alongside the
count that did import. The frontend now refreshes the server list on
settle rather than success, since a partial failure still means new
servers were persisted.
This commit is contained in:
Jason
2026-07-08 22:21:37 +08:00
parent 11c173c730
commit 94fc1cc064
4 changed files with 91 additions and 8 deletions
+3 -1
View File
@@ -67,7 +67,9 @@ export function useImportMcpFromApps() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: () => mcpApi.importFromApps(),
onSuccess: () => {
// 后端是 best-effort 导入:部分应用失败会返回错误,但其余应用的
// 服务器已经入库,失败时也要刷新列表。
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["mcp", "all"] });
},
});