Skip to content

Commit 6417e7a

Browse files
waleedlatif1claude
andcommitted
chore(mcp): align with React Query and design-token best practices
- useForceRefreshMcpTools: onSuccess → onSettled so cache reconciles on error - useMcpServerTest: replace `instanceof Error` ternaries with `toError().message` - mcp.tsx: use `--text-error` token (not the unused `--error`) and drop redundant dark variant Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent b879189 commit 6417e7a

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

  • apps/sim
    • app/workspace/[workspaceId]/settings/components/mcp
    • hooks/queries

apps/sim/app/workspace/[workspaceId]/settings/components/mcp/mcp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ export function MCP({ initialServerId }: MCPProps) {
716716
<div className='min-h-0 flex-1 overflow-y-auto'>
717717
{error ? (
718718
<div className='flex h-full flex-col items-center justify-center gap-2'>
719-
<p className='text-[var(--error)] text-xs leading-tight dark:text-[var(--error)]'>
719+
<p className='text-[var(--text-error)] text-xs leading-tight'>
720720
{error instanceof Error ? error.message : 'Failed to load MCP servers'}
721721
</p>
722722
</div>

apps/sim/hooks/queries/mcp.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect } from 'react'
22
import { createLogger } from '@sim/logger'
3+
import { toError } from '@sim/utils/errors'
34
import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
45
import { ApiClientError } from '@/lib/api/client/errors'
56
import { requestJson } from '@/lib/api/client/request'
@@ -115,8 +116,9 @@ export function useForceRefreshMcpTools() {
115116

116117
return useMutation({
117118
mutationFn: (workspaceId: string) => fetchMcpTools(workspaceId, true),
118-
onSuccess: (tools, workspaceId) => {
119-
queryClient.setQueryData(mcpKeys.toolsList(workspaceId), tools)
119+
onSettled: (tools, _error, workspaceId) => {
120+
if (tools) queryClient.setQueryData(mcpKeys.toolsList(workspaceId), tools)
121+
queryClient.invalidateQueries({ queryKey: mcpKeys.toolsList(workspaceId) })
120122
},
121123
})
122124
}
@@ -455,7 +457,7 @@ export function useMcpServerTest() {
455457
logger.info(`MCP server test ${result.success ? 'passed' : 'failed'}:`, variables.name)
456458
},
457459
onError: (error) => {
458-
logger.error('MCP server test failed:', error instanceof Error ? error.message : error)
460+
logger.error('MCP server test failed:', toError(error).message)
459461
},
460462
})
461463

@@ -466,8 +468,7 @@ export function useMcpServerTest() {
466468
? ({
467469
success: false,
468470
message: 'Connection failed',
469-
error:
470-
mutation.error instanceof Error ? mutation.error.message : 'Unknown error occurred',
471+
error: toError(mutation.error).message,
471472
} as McpServerTestResult)
472473
: null),
473474
isTestingConnection: mutation.isPending,

0 commit comments

Comments
 (0)