Skip to content

Commit b6d3083

Browse files
authored
fix: mcp tool description & tool select ui (#5948)
1 parent 29e9e3f commit b6d3083

File tree

6 files changed

+89
-28
lines changed

6 files changed

+89
-28
lines changed

packages/global/core/app/jsonschema.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,19 @@ const getNodeInputRenderTypeFromSchemaInputType = ({
8484
}
8585
return { renderTypeList: [FlowNodeInputTypeEnum.JSONEditor, FlowNodeInputTypeEnum.reference] };
8686
};
87-
export const jsonSchema2NodeInput = (jsonSchema: JSONSchemaInputType): FlowNodeInputItemType[] => {
87+
export const jsonSchema2NodeInput = ({
88+
jsonSchema,
89+
schemaType
90+
}: {
91+
jsonSchema: JSONSchemaInputType;
92+
schemaType: 'mcp' | 'http';
93+
}): FlowNodeInputItemType[] => {
8894
return Object.entries(jsonSchema?.properties || {}).map(([key, value]) => ({
8995
key,
9096
label: key,
9197
valueType: getNodeInputTypeFromSchemaInputType({ type: value.type, arrayItems: value.items }),
9298
description: value.description,
93-
toolDescription: value['x-tool-description'] ?? value.description ?? key,
99+
toolDescription: schemaType === 'http' ? value['x-tool-description'] : value.description || key,
94100
required: jsonSchema?.required?.includes(key),
95101
...getNodeInputRenderTypeFromSchemaInputType(value)
96102
}));

packages/global/core/app/tool/httpTool/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const getHTTPToolRuntimeNode = ({
6969
toolId: `${AppToolSourceEnum.http}-${parentId}/${tool.name}`
7070
}
7171
},
72-
inputs: jsonSchema2NodeInput(tool.inputSchema),
72+
inputs: jsonSchema2NodeInput({ jsonSchema: tool.inputSchema, schemaType: 'http' }),
7373
outputs: [
7474
...jsonSchema2NodeOutput(tool.outputSchema),
7575
{

packages/global/core/app/tool/mcpTool/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const getMCPToolRuntimeNode = ({
6262
toolId: `${AppToolSourceEnum.mcp}-${parentId}/${tool.name}`
6363
}
6464
},
65-
inputs: jsonSchema2NodeInput(tool.inputSchema),
65+
inputs: jsonSchema2NodeInput({ jsonSchema: tool.inputSchema, schemaType: 'mcp' }),
6666
outputs: [
6767
{
6868
id: NodeOutputKeyEnum.rawResponse,

projects/app/src/pageComponents/app/detail/HTTPTools/EditForm.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,17 @@ const EditForm = ({
154154
>
155155
<Flex alignItems={'center'} py={3} px={3}>
156156
<Box maxW={'full'} pl={2} position="relative" width="calc(100% - 30px)">
157-
<Flex alignItems="center" gap={2} mb={1}>
158-
<Box>{renderHttpMethod(tool.method)}</Box>
157+
<Flex alignItems="center" gap={2} mb={1} w={'full'}>
158+
<Box flex={'0 0 40px'}>{renderHttpMethod(tool.method)}</Box>
159159
<Box
160160
color={'myGray.900'}
161161
fontSize={'14px'}
162162
lineHeight={'20px'}
163163
letterSpacing={'0.25px'}
164+
whiteSpace={'nowrap'}
165+
overflow={'hidden'}
166+
textOverflow={'ellipsis'}
167+
maxW={'200px'}
164168
>
165169
{tool.name}
166170
</Box>
@@ -170,6 +174,10 @@ const EditForm = ({
170174
fontSize={'14px'}
171175
lineHeight={'20px'}
172176
letterSpacing={'0.25px'}
177+
whiteSpace={'nowrap'}
178+
overflow={'hidden'}
179+
textOverflow={'ellipsis'}
180+
maxW={'200px'}
173181
>
174182
{tool.path}
175183
</Box>

projects/app/src/pageComponents/app/detail/SimpleApp/components/ToolSelectModal.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ const RenderList = React.memo(function RenderList({
371371
objectFit={'contain'}
372372
borderRadius={'sm'}
373373
/>
374-
<Box fontWeight={'bold'} ml={3} color={'myGray.900'} flex={'1'}>
374+
<Box fontWeight={'bold'} ml={3} color={'myGray.900'} overflow={'hidden'}>
375375
{t(parseI18nString(template.name, i18n.language))}
376376
</Box>
377377
{isSystemTool && (
@@ -408,16 +408,19 @@ const RenderList = React.memo(function RenderList({
408408
borderRadius={'sm'}
409409
flexShrink={0}
410410
/>
411-
<Box flex={'1 0 0'} ml={3}>
412-
<Box
413-
color={'myGray.900'}
414-
fontWeight={'500'}
415-
fontSize={'sm'}
416-
className="textEllipsis"
417-
>
418-
{t(parseI18nString(template.name, i18n.language))}
419-
</Box>
411+
<Box
412+
px={3}
413+
color={'myGray.900'}
414+
fontWeight={'500'}
415+
fontSize={'sm'}
416+
maxW={'200px'}
417+
whiteSpace={'nowrap'}
418+
overflow={'hidden'}
419+
textOverflow={'ellipsis'}
420+
>
421+
{t(parseI18nString(template.name, i18n.language))}
420422
</Box>
423+
<Box flex={1} />
421424

422425
{selected ? (
423426
<Button

test/cases/global/core/app/jsonschema.test.ts

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { JSONSchemaInputType } from '@fastgpt/global/core/app/jsonschema';
33
import { jsonSchema2NodeInput } from '@fastgpt/global/core/app/jsonschema';
44

55
describe('jsonSchema2NodeInput', () => {
6-
it('should return correct node input', () => {
6+
it('should return correct node input for http schema', () => {
77
const jsonSchema: JSONSchemaInputType = {
88
type: 'object',
99
properties: {
@@ -25,15 +25,15 @@ describe('jsonSchema2NodeInput', () => {
2525
key: 'name',
2626
label: 'name',
2727
valueType: 'string',
28-
toolDescription: 'name',
28+
toolDescription: undefined,
2929
required: true,
3030
renderTypeList: ['input', 'reference']
3131
},
3232
{
3333
key: 'select',
3434
label: 'select',
3535
valueType: 'string',
36-
toolDescription: 'select',
36+
toolDescription: undefined,
3737
required: false,
3838
value: '11',
3939
renderTypeList: ['select'],
@@ -52,7 +52,7 @@ describe('jsonSchema2NodeInput', () => {
5252
key: 'age',
5353
label: 'age',
5454
valueType: 'number',
55-
toolDescription: 'age',
55+
toolDescription: undefined,
5656
required: true,
5757
renderTypeList: ['numberInput', 'reference'],
5858
max: 100,
@@ -62,60 +62,104 @@ describe('jsonSchema2NodeInput', () => {
6262
key: 'boolean',
6363
label: 'boolean',
6464
valueType: 'boolean',
65-
toolDescription: 'boolean',
65+
toolDescription: undefined,
6666
required: false,
6767
renderTypeList: ['switch']
6868
},
6969
{
7070
key: 'object',
7171
label: 'object',
7272
valueType: 'object',
73-
toolDescription: 'object',
73+
toolDescription: undefined,
7474
required: false,
7575
renderTypeList: ['JSONEditor', 'reference']
7676
},
7777
{
7878
key: 'strArr',
7979
label: 'strArr',
8080
valueType: 'arrayString',
81-
toolDescription: 'strArr',
81+
toolDescription: undefined,
8282
required: false,
8383
renderTypeList: ['JSONEditor', 'reference']
8484
},
8585
{
8686
key: 'numArr',
8787
label: 'numArr',
8888
valueType: 'arrayNumber',
89-
toolDescription: 'numArr',
89+
toolDescription: undefined,
9090
required: false,
9191
renderTypeList: ['JSONEditor', 'reference']
9292
},
9393
{
9494
key: 'boolArr',
9595
label: 'boolArr',
9696
valueType: 'arrayBoolean',
97-
toolDescription: 'boolArr',
97+
toolDescription: undefined,
9898
required: false,
9999
renderTypeList: ['JSONEditor', 'reference']
100100
},
101101
{
102102
key: 'objArr',
103103
label: 'objArr',
104104
valueType: 'arrayObject',
105-
toolDescription: 'objArr',
105+
toolDescription: undefined,
106106
required: false,
107107
renderTypeList: ['JSONEditor', 'reference']
108108
},
109109
{
110110
key: 'anyArr',
111111
label: 'anyArr',
112112
valueType: 'arrayAny',
113-
toolDescription: 'anyArr',
113+
toolDescription: undefined,
114114
required: false,
115115
renderTypeList: ['JSONEditor', 'reference']
116116
}
117117
];
118-
const result = jsonSchema2NodeInput(jsonSchema);
118+
const result = jsonSchema2NodeInput({ jsonSchema, schemaType: 'http' });
119+
120+
expect(result).toEqual(expectResponse);
121+
});
122+
123+
it('should return correct node input for mcp schema', () => {
124+
const jsonSchema: JSONSchemaInputType = {
125+
type: 'object',
126+
properties: {
127+
name: { type: 'string', description: 'User name' },
128+
age: { type: 'number', minimum: 0, maximum: 100 },
129+
withoutDesc: { type: 'string' }
130+
},
131+
required: ['name']
132+
};
133+
const expectResponse = [
134+
{
135+
key: 'name',
136+
label: 'name',
137+
valueType: 'string',
138+
description: 'User name',
139+
toolDescription: 'User name',
140+
required: true,
141+
renderTypeList: ['input', 'reference']
142+
},
143+
{
144+
key: 'age',
145+
label: 'age',
146+
valueType: 'number',
147+
toolDescription: 'age',
148+
required: false,
149+
renderTypeList: ['numberInput', 'reference'],
150+
max: 100,
151+
min: 0
152+
},
153+
{
154+
key: 'withoutDesc',
155+
label: 'withoutDesc',
156+
valueType: 'string',
157+
toolDescription: 'withoutDesc',
158+
required: false,
159+
renderTypeList: ['input', 'reference']
160+
}
161+
];
162+
const result = jsonSchema2NodeInput({ jsonSchema, schemaType: 'mcp' });
119163

120164
expect(result).toEqual(expectResponse);
121165
});

0 commit comments

Comments
 (0)