Skip to content

Commit 09cae9a

Browse files
j15zclaude
andcommitted
fix(workflow): resolve MCP tool names from live server data in canvas summaries
resolveToolsLabel preferred the stored title for mcp entries, so canvas and preview summaries could show a state-edited name while the config panel showed the live MCP tool name. Accept an optional mcpTools list (matched by toolId, same as the panel) and pass the already-fetched MCP tool data from workflow-block; the stored title remains the fallback while server data is unavailable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent d39ce99 commit 09cae9a

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,13 @@ const SubBlockRow = memo(function SubBlockRow({
331331

332332
/** Hydrates tool references to display names. */
333333
const { data: customTools = [] } = useCustomTools(workspaceId || '')
334+
const mcpToolSummaries = useMemo(
335+
() => mcpToolsData.map((t) => ({ id: createMcpToolId(t.serverId, t.name), name: t.name })),
336+
[mcpToolsData]
337+
)
334338
const toolsDisplayValue = useMemo(
335-
() => resolveToolsLabel(subBlock, rawValue, customTools),
336-
[subBlock, rawValue, customTools]
339+
() => resolveToolsLabel(subBlock, rawValue, customTools, mcpToolSummaries),
340+
[subBlock, rawValue, customTools, mcpToolSummaries]
337341
)
338342

339343
const filterDisplayValue = useMemo(

apps/sim/lib/workflows/subblocks/display.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ describe('resolveToolsLabel', () => {
135135
expect(resolveToolsLabel(toolInput, [{ type: 'workflow_input' }], [])).toBe('Workflow')
136136
})
137137

138+
it('prefers the live MCP tool name over the stored title', () => {
139+
expect(
140+
resolveToolsLabel(
141+
toolInput,
142+
[{ type: 'mcp', toolId: 'mcp-1', title: 'Renamed By Copilot' }],
143+
[],
144+
[{ id: 'mcp-1', name: 'Live MCP Name' }]
145+
)
146+
).toBe('Live MCP Name')
147+
expect(
148+
resolveToolsLabel(toolInput, [{ type: 'mcp', toolId: 'mcp-1', title: 'Snapshot' }], [], [])
149+
).toBe('Snapshot')
150+
})
151+
138152
it('prefers the custom tool record over the stored title', () => {
139153
expect(
140154
resolveToolsLabel(

apps/sim/lib/workflows/subblocks/display.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,17 @@ export function resolveVariablesLabel(
428428

429429
/**
430430
* Resolves a tool-input value to a tool-name summary. Names come from static
431-
* sources first (block registry, custom-tool records) so that edits to the
432-
* stored entry's `title` cannot change what the UI shows; the stored title
433-
* and inline schema names are only fallbacks for shapes with no canonical
434-
* source (MCP snapshots, legacy entries).
431+
* sources first (block registry, custom-tool records, live MCP tools) so that
432+
* edits to the stored entry's `title` cannot change what the UI shows; the
433+
* stored title and inline schema names are only fallbacks for shapes with no
434+
* canonical source (MCP entries while server data is unavailable, legacy
435+
* entries).
435436
*/
436437
export function resolveToolsLabel(
437438
subBlock: SubBlockConfig | undefined,
438439
rawValue: unknown,
439-
customTools: Array<{ id: string; title?: string; schema?: { function?: { name?: string } } }>
440+
customTools: Array<{ id: string; title?: string; schema?: { function?: { name?: string } } }>,
441+
mcpTools: Array<{ id: string; name: string }> = []
440442
): string | null {
441443
if (subBlock?.type !== 'tool-input') return null
442444
if (!Array.isArray(rawValue) || rawValue.length === 0) return null
@@ -466,6 +468,11 @@ export function resolveToolsLabel(
466468
if (customTool?.schema?.function?.name) return customTool.schema.function.name
467469
}
468470

471+
if (t.type === 'mcp' && typeof t.toolId === 'string') {
472+
const mcpTool = mcpTools.find((candidate) => candidate.id === t.toolId)
473+
if (mcpTool?.name) return mcpTool.name
474+
}
475+
469476
if (typeof t.title === 'string' && t.title) return t.title
470477

471478
const schema = t.schema as { function?: { name?: string } } | undefined

0 commit comments

Comments
 (0)