Skip to content

Commit fda94bc

Browse files
committed
fix(mcp): key draft reset off both schema sources, not the resolved toolSchema
toolSchema resolves to cachedSchema || selectedToolConfig?.inputSchema, so a live-only schema refresh (the discovered tool's inputSchema changes but the cached _toolSchema snapshot doesn't) left the reset key unchanged and could keep a stale invalid draft on screen. Track a signature of each schema source independently so a change in either one clears drafts, regardless of which source toolSchema resolves to.
1 parent 0f7b3a5 commit fda94bc

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/mcp-dynamic-args

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/mcp-dynamic-args/mcp-dynamic-args.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ function requiresJsonValue(paramSchema: any): boolean {
4242
)
4343
}
4444

45+
/**
46+
* Stable signature of a tool schema's properties, for detecting whether the
47+
* effective param shape has changed (independent of object identity).
48+
*/
49+
function schemaSignature(schema: unknown): string {
50+
const properties = (schema as { properties?: unknown } | undefined)?.properties
51+
return properties ? JSON.stringify(properties) : ''
52+
}
53+
4554
interface McpDynamicArgsProps {
4655
blockId: string
4756
subBlockId: string
@@ -101,12 +110,13 @@ export function McpDynamicArgs({
101110
* Draft text for JSON-value params (object/array/non-primitive-enum) whose current
102111
* edit isn't valid JSON yet. Keeping this out of toolArgs means the stored argument
103112
* is always either the last valid parsed value or untouched — never malformed text
104-
* that could reach tool execution. Drafts reset whenever the selected tool or its
105-
* effective schema changes, so a stale draft can't outlive the param shape it was
106-
* typed against.
113+
* that could reach tool execution. Drafts reset whenever the selected tool or either
114+
* schema source changes — `toolSchema` prefers the cached `_toolSchema` snapshot over
115+
* the live discovered schema, so the reset key tracks both independently rather than
116+
* the resolved `toolSchema`, which wouldn't change on a live-only refresh.
107117
*/
108118
const [invalidJsonDrafts, setInvalidJsonDrafts] = useState<Record<string, string>>({})
109-
const draftResetKey = `${selectedTool ?? ''}|${toolSchema?.properties ? JSON.stringify(toolSchema.properties) : ''}`
119+
const draftResetKey = `${selectedTool ?? ''}|${schemaSignature(cachedSchema)}|${schemaSignature(selectedToolConfig?.inputSchema)}`
110120
const [prevDraftResetKey, setPrevDraftResetKey] = useState(draftResetKey)
111121
if (prevDraftResetKey !== draftResetKey) {
112122
setPrevDraftResetKey(draftResetKey)

0 commit comments

Comments
 (0)