Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ export function MCP() {
const {
data: mcpToolsData = [],
error: toolsError,
isLoading: toolsLoading,
isFetching: toolsFetching,
toolsStateByServer,
} = useMcpToolsQuery(workspaceId)
const { data: storedTools = [], refetch: refetchStoredTools } = useStoredMcpTools(workspaceId)
const forceRefreshToolsMutation = useForceRefreshMcpTools()
Expand Down Expand Up @@ -623,7 +622,10 @@ export function MCP() {
{filteredServers.map((server) => {
if (!server?.id) return null
const tools = toolsByServer[server.id] || []
const isLoadingTools = toolsLoading || toolsFetching
const serverToolsState = toolsStateByServer.get(server.id)
const isLoadingTools = serverToolsState
? serverToolsState.isLoading || serverToolsState.isFetching
: false

return (
<ServerListItem
Expand Down
22 changes: 18 additions & 4 deletions apps/sim/hooks/queries/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,38 @@ export function useMcpToolsQuery(workspaceId: string) {
let hasData = false
let anyServerLoading = false
let firstError: Error | null = null
for (const result of results) {
const toolsStateByServer = new Map<
string,
{ isLoading: boolean; isFetching: boolean; error: Error | null }
>()
for (let index = 0; index < results.length; index++) {
const result = results[index]
// Drop stale data from servers whose latest refetch errored.
if (result.data && !result.isError) {
tools.push(...result.data)
hasData = true
}
if (result.isLoading) anyServerLoading = true
if (!firstError && result.error instanceof Error) firstError = result.error

const serverId = serverIds[index]
if (serverId) {
toolsStateByServer.set(serverId, {
isLoading: result.isLoading,
isFetching: result.isFetching,
error: result.error instanceof Error ? result.error : null,
})
}
}
return {
data: tools,
isLoading: (serversLoading || anyServerLoading) && !hasData,
isFetching: serversLoading || results.some((r) => r.isFetching),
// Suppress when any healthy server rendered; per-server errors live in `perServer`.
// Suppress when any healthy server rendered; per-server errors live in `toolsStateByServer`.
error: hasData ? null : firstError,
perServer: results,
toolsStateByServer,
}
}, [results, serversLoading])
}, [results, serversLoading, serverIds])
}

export function useForceRefreshMcpTools() {
Expand Down
Loading