Skip to content

Commit ed1b970

Browse files
committed
fix(mcp): third-round bugbot review
- discoverTools failure path now drops the per-server positive cache alongside writing the negative-cache marker, matching discoverServerTools' behavior so a workspace-aggregate failure doesn't leave stale tools cached. - useForceRefreshMcpTools filters disabled and out-of-workspace rows before fan-out so disabled servers don't 404 → negative-cache themselves. - Remove unused useMcpServerTools export — the aggregate goes through useQueries directly, no external consumer exists.
1 parent 3fd031c commit ed1b970

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

apps/sim/hooks/queries/mcp.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ async function fetchMcpTools(
122122
}
123123
}
124124

125-
export function useMcpServerTools(workspaceId: string, serverId?: string) {
126-
return useQuery({
127-
queryKey: mcpKeys.serverToolsList(workspaceId, serverId),
128-
queryFn: ({ signal }) => fetchMcpTools(workspaceId, false, signal, serverId),
129-
enabled: !!workspaceId && !!serverId,
130-
retry: false,
131-
staleTime: 30 * 1000,
132-
refetchOnWindowFocus: false,
133-
})
134-
}
135-
136125
/**
137126
* Workspace aggregate derived from N parallel per-server queries via
138127
* `useQueries`. One slow server cannot block the others.
@@ -195,7 +184,9 @@ export function useForceRefreshMcpTools() {
195184

196185
return useMutation({
197186
mutationFn: async (workspaceId: string) => {
198-
const servers = queryClient.getQueryData<McpServer[]>(mcpKeys.serversList(workspaceId)) ?? []
187+
const allServers =
188+
queryClient.getQueryData<McpServer[]>(mcpKeys.serversList(workspaceId)) ?? []
189+
const servers = allServers.filter((s) => s.enabled && s.workspaceId === workspaceId)
199190
const results = await Promise.allSettled(
200191
servers.map(async (server) => {
201192
const tools = await fetchMcpTools(workspaceId, true, undefined, server.id)

apps/sim/lib/mcp/service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,12 @@ class McpService {
590590
)
591591
deferredSideEffects.push(
592592
this.updateServerStatus(server.id, workspaceId, false, outcome.message),
593-
this.markServerUnhealthy(workspaceId, server.id, outcome.originalError)
593+
this.markServerUnhealthy(workspaceId, server.id, outcome.originalError),
594+
this.cacheAdapter
595+
.delete(serverCacheKey(workspaceId, server.id))
596+
.catch((err) =>
597+
logger.warn(`[${requestId}] Cache delete failed for ${server.name}:`, err)
598+
)
594599
)
595600
})
596601

0 commit comments

Comments
 (0)