Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function FormattedInput({
onChange={onChange}
onScroll={handleScroll}
onInput={handleScroll}
inputClassName='text-transparent caret-[var(--text-primary)]'
inputClassName='font-medium font-sans text-transparent caret-[var(--text-primary)]'
/>
<div className='pointer-events-none absolute inset-0 flex items-center overflow-hidden px-2 py-1.5 font-medium font-sans text-sm'>
<div className='whitespace-nowrap' style={{ transform: `translateX(-${scrollLeft}px)` }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ import { formatParameterLabel } from '@/tools/params'

const logger = createLogger('McpDynamicArgs')

/**
* The dropdown UI renders each enum member as a string label/value, so it can only
* represent JSON Schema enums whose members are primitives — a non-primitive member
* (object/array) would collapse to "[object Object]" and lose its identity. Callers
* route a non-primitive enum to the JSON editor (`long-input`) instead.
*/
function isPrimitiveEnum(
enumValues: unknown
): enumValues is Array<string | number | boolean | null> {
return (
Array.isArray(enumValues) &&
enumValues.every((value) => value === null || typeof value !== 'object')
)
}

/**
* True when the schema's actual value must be a JSON object/array (a plain
* object/array type, or a non-primitive enum member) rather than a string.
*/
function requiresJsonValue(paramSchema: any): boolean {
return (
paramSchema.type === 'object' ||
paramSchema.type === 'array' ||
(Array.isArray(paramSchema.enum) && !isPrimitiveEnum(paramSchema.enum))
)
}

interface McpDynamicArgsProps {
blockId: string
subBlockId: string
Expand Down Expand Up @@ -116,7 +143,9 @@ export function McpDynamicArgs({
)
Comment thread
waleedlatif1 marked this conversation as resolved.

const getInputType = (paramSchema: any) => {
if (paramSchema.enum) return 'dropdown'
if (Array.isArray(paramSchema.enum)) {
return isPrimitiveEnum(paramSchema.enum) ? 'dropdown' : 'long-input'
}
Comment thread
waleedlatif1 marked this conversation as resolved.
if (paramSchema.type === 'boolean') return 'switch'
if (paramSchema.type === 'number' || paramSchema.type === 'integer') {
if (paramSchema.minimum !== undefined && paramSchema.maximum !== undefined) {
Expand Down Expand Up @@ -241,6 +270,8 @@ export function McpDynamicArgs({

case 'long-input': {
const config = createParamConfig(paramName, paramSchema, 'long-input')
const displayValue =
typeof value === 'string' || value == null ? value || '' : JSON.stringify(value)
return (
<LongInput
key={`${paramName}-long`}
Expand All @@ -249,8 +280,18 @@ export function McpDynamicArgs({
config={config}
placeholder={config.placeholder}
rows={4}
value={value || ''}
onChange={(newValue) => updateParameter(paramName, newValue)}
value={displayValue}
onChange={(newValue) => {
if (!requiresJsonValue(paramSchema)) {
updateParameter(paramName, newValue)
return
}
try {
updateParameter(paramName, JSON.parse(newValue))
} catch {
updateParameter(paramName, newValue)
}
}}
isPreview={isPreview}
disabled={disabled}
workflowSearchValuePath={[paramName]}
Expand Down
6 changes: 4 additions & 2 deletions apps/sim/lib/api/contracts/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ export const mcpToolSchemaPropertySchema: z.ZodType<McpToolSchemaProperty> = z.l
.object({
type: z.union([z.string(), z.array(z.string())]).optional(),
description: z.string().optional(),
items: mcpToolSchemaPropertySchema.optional(),
items: z
.union([mcpToolSchemaPropertySchema, z.array(mcpToolSchemaPropertySchema)])
.optional(),
properties: z.record(z.string(), mcpToolSchemaPropertySchema).optional(),
required: z.array(z.string()).optional(),
enum: z.array(z.union([z.string(), z.number(), z.boolean(), z.null()])).optional(),
enum: z.array(z.unknown()).optional(),
Comment thread
waleedlatif1 marked this conversation as resolved.
default: z.unknown().optional(),
})
.passthrough()
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/lib/mcp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export interface McpSecurityPolicy {
export interface McpToolSchemaProperty {
type?: string | string[]
description?: string
items?: McpToolSchemaProperty
items?: McpToolSchemaProperty | McpToolSchemaProperty[]
properties?: Record<string, McpToolSchemaProperty>
required?: string[]
enum?: Array<string | number | boolean | null>
enum?: unknown[]
default?: unknown
[key: string]: unknown
}
Expand Down
Loading