Merge pull request #2087 from modelcontextprotocol/v2/fix/1914-surface-post-add-refresh-failure
fix(web): surface a failed post-write server-list reload
This commit is contained in:
commit
8b9839cc93
2 changed files with 683 additions and 59 deletions
|
|
@ -6,6 +6,7 @@ import {
|
|||
} from "./useImportClientConfig";
|
||||
import type { ImportSourceResult } from "@inspector/core/mcp/import/index.js";
|
||||
import type { MCPConfig } from "@inspector/core/mcp/types.js";
|
||||
import { ServerListReloadError } from "@inspector/core/react/useServers.js";
|
||||
|
||||
function config(...ids: string[]): MCPConfig {
|
||||
const mcpServers: MCPConfig["mcpServers"] = {};
|
||||
|
|
@ -207,6 +208,31 @@ describe("useImportClientConfig", () => {
|
|||
expect(outcome.detail).toBe("add failed");
|
||||
});
|
||||
|
||||
it("reports a reload failure as imported-with-a-warning, not failed (#1914)", async () => {
|
||||
// A `ServerListReloadError` rejects *after* the write landed, so the entry
|
||||
// really was added. A red "Failed" badge would contradict the error's own
|
||||
// message and invite a retry that then collides with the row it claims
|
||||
// wasn't created. The reason still shows, as `detail`.
|
||||
const onAddServer = vi.fn(async () => {
|
||||
throw new ServerListReloadError(
|
||||
"The server was added, but the server list could not be reloaded: disk full",
|
||||
);
|
||||
});
|
||||
const { result } = setup({
|
||||
onFetchSource: vi.fn(async () => foundSource(config("alpha"))),
|
||||
onAddServer,
|
||||
});
|
||||
await act(async () => {
|
||||
await result.current.pickSource("claude");
|
||||
});
|
||||
await act(async () => {
|
||||
await result.current.runImport();
|
||||
});
|
||||
const outcome = result.current.outcomes[0];
|
||||
expect(outcome.status).toBe("added");
|
||||
expect(outcome.detail).toMatch(/could not be reloaded: disk full/);
|
||||
});
|
||||
|
||||
it("resolves conflicts by overwrite, skip, and rename", async () => {
|
||||
const onAddServer = vi.fn(async () => {});
|
||||
const onUpdateServer = vi.fn(async () => {});
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
type ImportSourceResult,
|
||||
} from "@inspector/core/mcp/import/index.js";
|
||||
import { validateStoreId } from "@inspector/core/storage/store-id.js";
|
||||
import { ServerListReloadError } from "@inspector/core/react/useServers.js";
|
||||
import type { MCPConfig, MCPServerConfig } from "@inspector/core/mcp/types.js";
|
||||
|
||||
export type ImportPhase = "select" | "loading" | "review" | "summary";
|
||||
|
|
@ -198,11 +199,17 @@ export function useImportClientConfig({
|
|||
await write();
|
||||
return { id, status: outcome };
|
||||
} catch (err) {
|
||||
return {
|
||||
id,
|
||||
status: "failed",
|
||||
detail: err instanceof Error ? err.message : String(err),
|
||||
};
|
||||
const detail = err instanceof Error ? err.message : String(err);
|
||||
// A `ServerListReloadError` means the write landed and only reading the
|
||||
// list back failed, so this entry really was imported. Reporting it as
|
||||
// `failed` would contradict the error's own message and invite a retry
|
||||
// that then collides with the row it says wasn't created (#1914 r3).
|
||||
// The status is the truth about the write; `detail` renders in red
|
||||
// beneath it either way, so the reload failure is still visible.
|
||||
if (err instanceof ServerListReloadError) {
|
||||
return { id, status: outcome, detail };
|
||||
}
|
||||
return { id, status: "failed", detail };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue