fix(ui): clear toolset search on close and only keep non-empty tool lists on failed refetch

Reopening the editor after a search rendered once with the old query,
which fetched every stale server; clear the search whenever the editor
closes. A failed refetch now keeps the previous list only when it has
tools, so a server that loaded none and then fails reports the error.
(LIT-10012)
This commit is contained in:
Mrinal Chanshetty 2026-10-27 09:29:47 -07:00
parent e77cf5b44c
commit 61d61f42b9
4 changed files with 30 additions and 5 deletions

View file

@ -79,6 +79,22 @@ describe("useMCPServerTools", () => {
);
});
it("reports an error when a refetch fails for a server that had loaded no tools", async () => {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const sharedWrapper = ({ children }: { children: React.ReactNode }) =>
React.createElement(QueryClientProvider, { client: queryClient }, children);
vi.mocked(networking.listMCPTools)
.mockResolvedValueOnce({ tools: [], error: null })
.mockResolvedValueOnce({ tools: [], error: "http_502", message: "upstream down" });
const { result } = renderHook(() => useMCPServerTools(["a"], new Set(["a"])), { wrapper: sharedWrapper });
await waitFor(() => expect(result.current.get("a")?.status).toBe("success"));
await act(() => queryClient.refetchQueries({ queryKey: mcpServerToolKeys.detail("a") }));
await waitFor(() => expect(result.current.get("a")).toEqual({ tools: [], status: "error" }));
});
it("keeps showing the loaded tools when a later refetch fails", async () => {
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const sharedWrapper = ({ children }: { children: React.ReactNode }) =>

View file

@ -40,8 +40,7 @@ const toStatus = ({
fetchStatus,
data,
}: Pick<QueryObserverResult<MCPServerToolEntry[]>, "status" | "fetchStatus" | "data">): MCPServerToolsStatus => {
// A failed refetch keeps the tools that already loaded on screen.
if (status === "error" && data !== undefined) return "success";
if (status === "error" && data !== undefined && data.length > 0) return "success";
if (status !== "pending") return status;
return fetchStatus === "idle" ? "idle" : "loading";
};

View file

@ -373,7 +373,11 @@ describe("MCPToolsetsTab tool search and bulk selection", () => {
await act(() => queryClient.invalidateQueries({ queryKey: mcpServerToolKeys.all }));
await new Promise((resolve) => setTimeout(resolve, 50));
expect(networking.listMCPTools).toHaveBeenCalledTimes(callsWhileOpen);
const reopened = await openCreate(user);
expect(reopened.getByRole("textbox", { name: "Search tools or servers" })).toHaveValue("");
await new Promise((resolve) => setTimeout(resolve, 50));
expect(networking.listMCPTools).toHaveBeenCalledTimes(callsWhileOpen);
});

View file

@ -298,11 +298,17 @@ function CreateToolsetModal({ open, onClose, onSave, initialToolset }: CreateToo
});
};
// Clearing the search on close keeps a reopen from fetching every server for one render.
const handleClose = () => {
setSearch("");
onClose();
};
const handleSubmit = async (values: ToolsetFormValues) => {
setSaving(true);
try {
await onSave(values.toolset_name, values.description, selectedTools);
onClose();
handleClose();
} finally {
setSaving(false);
}
@ -316,7 +322,7 @@ function CreateToolsetModal({ open, onClose, onSave, initialToolset }: CreateToo
const matchingState = selectionState(selectedTools, matchingTools);
return (
<Dialog open={open} onOpenChange={(open) => !open && onClose()}>
<Dialog open={open} onOpenChange={(open) => !open && handleClose()}>
<DialogContent className="max-h-[calc(100dvh-2rem)] overflow-y-auto sm:max-w-[960px]">
<DialogHeader>
<DialogTitle>{initialToolset ? "Edit Toolset" : "New Toolset"}</DialogTitle>
@ -463,7 +469,7 @@ function CreateToolsetModal({ open, onClose, onSave, initialToolset }: CreateToo
</div>
<div className="flex justify-end gap-2 mt-4 pt-4 border-t border-border">
<Button variant="outline" onClick={onClose}>
<Button variant="outline" onClick={handleClose}>
Cancel
</Button>
<Button onClick={() => void form.handleSubmit(handleSubmit)()} disabled={saving} aria-busy={saving}>