Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

wangxiaolei74b027c41af3
diff --git a/web/app/components/workflow/nodes/tool/use-config.ts b/web/app/components/workflow/nodes/tool/use-config.ts
index 7e4594f4f29..87e91860080 100644
--- a/web/app/components/workflow/nodes/tool/use-config.ts
+++ b/web/app/components/workflow/nodes/tool/use-config.ts
@@ -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,
})
}