MCPcopy Create free account
hub / github.com/simstudioai/sim / useForceRefreshMcpTools

Function useForceRefreshMcpTools

apps/sim/hooks/queries/mcp.ts:180–214  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

178}
179
180export function useForceRefreshMcpTools() {
181 const queryClient = useQueryClient()
182
183 return useMutation({
184 mutationFn: async (workspaceId: string) => {
185 const allServers =
186 queryClient.getQueryData<McpServer[]>(mcpKeys.serversList(workspaceId)) ?? []
187 const servers = allServers.filter((s) => s.enabled && s.workspaceId === workspaceId)
188 const results = await Promise.allSettled(
189 servers.map(async (server) => {
190 const tools = await fetchMcpTools(workspaceId, true, undefined, server.id)
191 queryClient.setQueryData(mcpKeys.serverToolsList(workspaceId, server.id), tools)
192 return tools
193 })
194 )
195 results.forEach((result, index) => {
196 if (result.status === 'rejected') {
197 const failedServer = servers[index]
198 if (failedServer) {
199 queryClient.invalidateQueries({
200 queryKey: mcpKeys.serverToolsList(workspaceId, failedServer.id),
201 })
202 }
203 }
204 })
205 return results
206 .filter((r): r is PromiseFulfilledResult<McpTool[]> => r.status === 'fulfilled')
207 .flatMap((r) => r.value)
208 },
209 onSettled: (_data, _error, workspaceId) => {
210 queryClient.invalidateQueries({ queryKey: mcpKeys.serversList(workspaceId) })
211 queryClient.invalidateQueries({ queryKey: mcpKeys.storedToolsList(workspaceId) })
212 },
213 })
214}
215
216interface CreateMcpServerParams {
217 workspaceId: string

Callers 2

MCPFunction · 0.90
tool-input.tsxFile · 0.90

Calls 1

fetchMcpToolsFunction · 0.85

Tested by

no test coverage detected