:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mcp-store): report a tool listing that never produced tools (#103110)
posthog[bot]856d6a2fee85
diff --git a/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useGatewayServers.ts b/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useGatewayServers.tsindex 4df962502f5d..0a808aa4a439 100644--- a/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useGatewayServers.ts+++ b/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useGatewayServers.ts@@ -26,6 +26,9 @@ import { useQueryClient } from "@tanstack/react-query";import { useSubscription } from "@trpc/tanstack-react-query";import { useCallback, useMemo } from "react";+const DISCOVERY_FAILED =+ "Connected, but listing the server's tools failed. Open the server to try again.";+/*** The team's gateway server registry plus every server-level mutation:* connect/disconnect the caller's own credential, the member self-switch, and@@ -75,15 +78,24 @@ export function useGatewayServers() {(client, match: GatewayServerMatch) => discoverGatewayTools(client, match),{onSuccess: (result) => {+ // Losing the registry row leaves the same empty server as a failed+ // listing, so it reports the same way. "no-connection" does not: the+ // credential is mid-OAuth or needs reauth, which the server's own tag+ // already says.+ if (result.skipped === "no-server") {+ toast.warning(DISCOVERY_FAILED);+ return;+ }if (!result.discovered || !result.serverId) return;queryClient.invalidateQueries({queryKey: gatewayKeys.serverTools(result.serverId),});queryClient.invalidateQueries({ queryKey: gatewayKeys.servers });},- // A failed listing must not read as a failed connect. The detail page- // still shows its empty state and retries on mount.- onError: () => {},+ // A failed listing must not read as a failed connect, but it must not+ // pass silently either: the server then sits at "Connected" with no+ // tools and nothing says why.+ onError: () => toast.warning(DISCOVERY_FAILED),},);const discoverTools = discoverToolsMutation.mutate;diff --git a/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useRegisterGatewayServer.test.tsx b/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useRegisterGatewayServer.test.tsxindex d42a4e6eda36..108800407898 100644--- a/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useRegisterGatewayServer.test.tsx+++ b/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useRegisterGatewayServer.test.tsx@@ -14,6 +14,7 @@ const mocks = vi.hoisted(() => ({refreshTools: vi.fn(),getCallbackUrl: vi.fn(),openAndWait: vi.fn(),+ toastWarning: vi.fn(),}));vi.mock("@posthog/ui/features/auth/authClient", () => ({@@ -34,7 +35,7 @@ vi.mock("@posthog/host-router/react", () => ({}));vi.mock("@posthog/ui/primitives/toast", () => ({- toast: { error: vi.fn(), success: vi.fn() },+ toast: { error: vi.fn(), success: vi.fn(), warning: mocks.toastWarning },}));import { useRegisterGatewayServer } from "./useRegisterGatewayServer";@@ -133,7 +134,7 @@ describe("useRegisterGatewayServer", () => {expect(queryClient.getQueryState(toolsKey)?.isInvalidated).toBe(true);});- it("still registers the server when the tool listing fails", async () => {+ it("still registers the server when the tool listing fails, and says so", async () => {mocks.getServers.mockResolvedValue([gatewayServer()]);mocks.refreshTools.mockRejectedValue(new Error("upstream down"));@@ -141,6 +142,23 @@ describe("useRegisterGatewayServer", () => {expect(outcome.created?.id).toBe("srv-1");expect(outcome.discoveredTools).toBe(false);+ // The upstream reason can carry a fragment of the server's response body,+ // so the toast stays a fixed recovery message.+ expect(mocks.toastWarning).toHaveBeenCalledWith(+ "Added, but listing the server's tools failed. Open the server to try again.",+ );+ });++ it("reports a server that vanished from the registry before the listing", async () => {+ mocks.getServers.mockResolvedValue([]);++ const outcome = await register();++ expect(mocks.refreshTools).not.toHaveBeenCalled();+ expect(outcome.created).toBeNull();+ expect(mocks.toastWarning).toHaveBeenCalledWith(+ "Added, but listing the server's tools failed. Open the server to try again.",+ );});it("skips the listing when the credential is still mid-OAuth", async () => {diff --git a/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useRegisterGatewayServer.ts b/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useRegisterGatewayServer.tsindex 808c581f05e3..d4eb5646cb83 100644--- a/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useRegisterGatewayServer.ts+++ b/products/desktop/packages/ui/src/features/mcp-gateway/hooks/useRegisterGatewayServer.ts@@ -25,6 +25,9 @@ interface RegisterGatewayServerResult {error: string | null;}+const DISCOVERY_FAILED =+ "Added, but listing the server's tools failed. Open the server to try again.";+/*** Registers a custom server with the gateway (Add-server form submit) and* resolves the resulting registry entry so the caller can navigate to it.@@ -57,12 +60,22 @@ export function useRegisterGatewayServer() {// Registering stores the credential but discovers no tools, and this// flow lands the user straight on the server's detail page — list them// now so that page isn't empty. A failure here is not a failed install;- // the detail page retries on mount.+ // the detail page retries on mount. It is still reported, because a+ // server that lists no tools is unusable and the row alone never says so.const discovery = await discoverGatewayTools(client,{ serverId: created?.id, url: vars.request.url },{ servers },- ).catch(() => null);+ ).catch(() => {+ toast.warning(DISCOVERY_FAILED);+ return null;+ });+ // Losing the registry row leaves the same empty server as a failed+ // listing. "no-connection" does not: the credential is mid-OAuth, which+ // the server's own tag already says.+ if (discovery?.skipped === "no-server") {+ toast.warning(DISCOVERY_FAILED);+ }return { created, discoveredTools: !!discovery?.discovered, error: null };},{