fix: fix mcp output schema is union type frontend crash (#31779)

Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
This commit is contained in:
wangxiaolei 2026-02-04 17:33:41 +08:00 committed by GitHub
parent 5f69470ebf
commit 74b027c41a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 11 deletions

View File

@ -1,6 +1,7 @@
import type { ToolNodeType, ToolVarInputs } from './types'
import type { InputVar } from '@/app/components/workflow/types'
import { useBoolean } from 'ahooks'
import { capitalize } from 'es-toolkit/string'
import { produce } from 'immer'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
@ -25,6 +26,12 @@ import {
} from '@/service/use-tools'
import { canFindTool } from '@/utils'
import { useWorkflowStore } from '../../store'
import { normalizeJsonSchemaType } from './output-schema-utils'
const formatDisplayType = (output: Record<string, unknown>): string => {
const normalizedType = normalizeJsonSchemaType(output) || 'Unknown'
return capitalize(normalizedType)
}
const useConfig = (id: string, payload: ToolNodeType) => {
const workflowStore = useWorkflowStore()
@ -247,20 +254,13 @@ const useConfig = (id: string, payload: ToolNodeType) => {
})
}
else {
const normalizedType = normalizeJsonSchemaType(output)
res.push({
name: outputKey,
type:
output.type === 'array'
? `Array[${output.items?.type
? output.items.type.slice(0, 1).toLocaleUpperCase()
+ output.items.type.slice(1)
: 'Unknown'
}]`
: `${output.type
? output.type.slice(0, 1).toLocaleUpperCase()
+ output.type.slice(1)
: 'Unknown'
}`,
normalizedType === 'array'
? `Array[${output.items ? formatDisplayType(output.items) : 'Unknown'}]`
: formatDisplayType(output),
description: output.description,
})
}