diff --git a/packages/tui/src/context/data.tsx b/packages/tui/src/context/data.tsx index aa619bb3b5..8eff463299 100644 --- a/packages/tui/src/context/data.tsx +++ b/packages/tui/src/context/data.tsx @@ -115,8 +115,6 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({ let connectionGeneration = 0 let statusChanges: Set | undefined let bootstrapping: Promise | undefined - const pendingMcpResourceRefresh = new Map() - const mcpResourceRefreshes = new Map>() function setSessionStatus(sessionID: string, status: DataSessionStatus) { statusChanges?.add(sessionID) @@ -767,15 +765,10 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({ if (bootstrapping) break void result.location.mcp.refresh(event.location) break - case "mcp.resources.changed": { - const location = event.location ?? defaultLocation() - if (bootstrapping || mcpResourceRefreshes.has(locationKey(location))) { - pendingMcpResourceRefresh.set(locationKey(location), location) - break - } - void result.location.mcp.resource.refresh(location) + case "mcp.resources.changed": + if (bootstrapping) break + void result.location.mcp.resource.refresh(event.location) break - } } } @@ -965,26 +958,12 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({ catalog(location?: LocationRef) { return store.location[locationKey(location ?? defaultLocation())]?.mcpResource }, - refresh(ref?: LocationRef) { - const location = ref ?? defaultLocation() - const key = locationKey(location) - const active = mcpResourceRefreshes.get(key) - if (active) return active - const refresh = sdk.api["server.mcp"] - .catalog({ location: locationQuery(location) }) - .then((result) => { - const key = locationKey(result.location) - setStore("location", key, { ...store.location[key], mcpResource: mutable(result.data) }) - }) - .finally(() => { - mcpResourceRefreshes.delete(key) - const pending = pendingMcpResourceRefresh.get(key) - if (!pending || bootstrapping) return - pendingMcpResourceRefresh.delete(key) - void result.location.mcp.resource.refresh(pending) - }) - mcpResourceRefreshes.set(key, refresh) - return refresh + async refresh(ref?: LocationRef) { + const result = await sdk.api["server.mcp"].catalog({ + location: locationQuery(ref ?? defaultLocation()), + }) + const key = locationKey(result.location) + setStore("location", key, { ...store.location[key], mcpResource: mutable(result.data) }) }, }, }, @@ -1069,11 +1048,6 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({ }) .finally(() => { bootstrapping = undefined - for (const [key, location] of pendingMcpResourceRefresh) { - if (mcpResourceRefreshes.has(key)) continue - pendingMcpResourceRefresh.delete(key) - void result.location.mcp.resource.refresh(location) - } }) return bootstrapping } diff --git a/packages/tui/test/cli/tui/data.test.tsx b/packages/tui/test/cli/tui/data.test.tsx index 73078370a5..8ee5030168 100644 --- a/packages/tui/test/cli/tui/data.test.tsx +++ b/packages/tui/test/cli/tui/data.test.tsx @@ -112,19 +112,12 @@ test("refreshes MCP resource catalogs after change events", async () => { const events = createEventStream() let resources = [{ server: "docs", name: "Readme", uri: "docs://readme" }] let requests = 0 - let release: (() => void) | undefined const calls = createFetch((url) => { if (url.pathname !== "/api/mcp/resource") return requests++ - const data = { resources, templates: [] } - if (requests === 3) - return new Promise((resolve) => { - release = () => - resolve(json({ location: { directory, project: { id: "proj_test", directory } }, data })) - }) return json({ location: { directory, project: { id: "proj_test", directory } }, - data, + data: { resources, templates: [] }, }) }, events) let data!: ReturnType @@ -158,19 +151,6 @@ test("refreshes MCP resource catalogs after change events", async () => { data: { server: "docs" }, }) await wait(() => requests === 2 && data.location.mcp.resource.catalog()?.resources[0]?.name === "Guide") - - const refresh = data.location.mcp.resource.refresh() - await wait(() => requests === 3) - resources = [{ server: "docs", name: "Reference", uri: "docs://reference" }] - emitEvent(events, { - id: "evt_mcp_resources_during_refresh", - created: 2, - type: "mcp.resources.changed", - data: { server: "docs" }, - }) - release?.() - await refresh - await wait(() => requests === 4 && data.location.mcp.resource.catalog()?.resources[0]?.name === "Reference") } finally { app.renderer.destroy() }