Skip to content

Commit fe7484b

Browse files
committed
refactor(tool-validation): extract getMcpServerIssue, remove fake tool hack
1 parent b70bdb4 commit fe7484b

File tree

2 files changed

+32
-23
lines changed
  • apps/sim

2 files changed

+32
-23
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import { cn } from '@/lib/core/utils/cn'
2020
import {
2121
getIssueBadgeLabel,
2222
getIssueBadgeVariant,
23-
isToolUnavailable,
23+
getMcpServerIssue as validateMcpServer,
2424
getMcpToolIssue as validateMcpTool,
25+
isToolUnavailable,
2526
} from '@/lib/mcp/tool-validation'
2627
import type { McpToolSchema } from '@/lib/mcp/types'
2728
import { getProviderIdFromServiceId, type OAuthProvider, type OAuthService } from '@/lib/oauth'
@@ -550,28 +551,21 @@ export const ToolInput = memo(function ToolInput({
550551
connectionStatus: s.connectionStatus,
551552
lastError: s.lastError ?? undefined,
552553
}))
553-
const discoveredTools = mcpTools.map((t) => ({
554-
serverId: t.serverId,
555-
name: t.name,
556-
inputSchema: t.inputSchema,
557-
}))
558554

559555
if (tool.type === 'mcp-server') {
560-
// Server-level validation: only check server connectivity
561-
return validateMcpTool(
562-
{
563-
serverId,
564-
serverUrl: tool.params?.serverUrl as string | undefined,
565-
toolName: '__server_check__',
566-
schema: undefined,
567-
},
568-
serverStates,
569-
// Pass a fake discovered tool so tool_not_found doesn't trigger
570-
[...discoveredTools, { serverId, name: '__server_check__', inputSchema: undefined }]
556+
return validateMcpServer(
557+
serverId,
558+
tool.params?.serverUrl as string | undefined,
559+
serverStates
571560
)
572561
}
573562

574563
const toolName = tool.params?.toolName as string
564+
const discoveredTools = mcpTools.map((t) => ({
565+
serverId: t.serverId,
566+
name: t.name,
567+
inputSchema: t.inputSchema,
568+
}))
575569

576570
// Try to get fresh schema from DB (enables real-time updates after MCP refresh)
577571
const storedTool =

apps/sim/lib/mcp/tool-validation.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ export function hasSchemaChanged(
3939
return !isEqual(storedWithoutDesc, serverWithoutDesc)
4040
}
4141

42-
export function getMcpToolIssue(
43-
storedTool: StoredMcpToolReference,
44-
servers: ServerState[],
45-
discoveredTools: DiscoveredTool[]
42+
/**
43+
* Validates server-level connectivity for an MCP server.
44+
* Checks: server existence, connection status, URL changes.
45+
*/
46+
export function getMcpServerIssue(
47+
serverId: string,
48+
serverUrl: string | undefined,
49+
servers: ServerState[]
4650
): McpToolIssue | null {
47-
const { serverId, serverUrl, toolName, schema } = storedTool
48-
4951
const server = servers.find((s) => s.id === serverId)
5052
if (!server) {
5153
return { type: 'server_not_found', message: 'Server not found' }
@@ -62,6 +64,19 @@ export function getMcpToolIssue(
6264
return { type: 'url_changed', message: 'Server URL changed' }
6365
}
6466

67+
return null
68+
}
69+
70+
export function getMcpToolIssue(
71+
storedTool: StoredMcpToolReference,
72+
servers: ServerState[],
73+
discoveredTools: DiscoveredTool[]
74+
): McpToolIssue | null {
75+
const { serverId, serverUrl, toolName, schema } = storedTool
76+
77+
const serverIssue = getMcpServerIssue(serverId, serverUrl, servers)
78+
if (serverIssue) return serverIssue
79+
6580
const serverTool = discoveredTools.find((t) => t.serverId === serverId && t.name === toolName)
6681
if (!serverTool) {
6782
return { type: 'tool_not_found', message: 'Tool not found on server' }

0 commit comments

Comments
 (0)