Skip to content

Commit 8c5201b

Browse files
committed
feat: enhance MCP tool selection and display in application forms
1 parent 80f53ec commit 8c5201b

File tree

2 files changed

+76
-37
lines changed

2 files changed

+76
-37
lines changed

ui/src/views/application/component/McpServersDialog.vue

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@submit.prevent
1818
>
1919
<el-form-item>
20-
<el-radio-group v-model="form.mcp_source">
20+
<el-radio-group v-model="form.mcp_source" @change="mcpSourceChange">
2121
<el-radio value="referencing">
2222
{{ $t('views.applicationWorkflow.nodes.mcpNode.reference') }}
2323
</el-radio>
@@ -100,17 +100,8 @@ import { computed, inject, onMounted, ref, watch } from 'vue'
100100
import { loadSharedApi } from '@/utils/dynamics-api/shared-api.ts'
101101
import { useRoute } from 'vue-router'
102102
103-
const getApplicationDetail = inject('getApplicationDetail') as any
104-
const applicationDetail = getApplicationDetail()
105103
const emit = defineEmits(['refresh'])
106-
const route = useRoute()
107-
const apiType = computed(() => {
108-
if (route.path.includes('resource-management')) {
109-
return 'systemManage'
110-
} else {
111-
return 'workspace'
112-
}
113-
})
104+
114105
const paramFormRef = ref()
115106
116107
const mcpServerJson = `{
@@ -143,32 +134,20 @@ watch(dialogVisible, (bool) => {
143134
}
144135
})
145136
146-
function getMcpToolSelectOptions() {
147-
const obj =
148-
apiType.value === 'systemManage'
149-
? {
150-
scope: 'WORKSPACE',
151-
tool_type: 'MCP',
152-
workspace_id: applicationDetail.value?.workspace_id,
153-
}
154-
: {
155-
scope: 'WORKSPACE',
156-
tool_type: 'MCP',
157-
}
158-
159-
loadSharedApi({ type: 'tool', systemType: apiType.value })
160-
.getAllToolList(obj, loading)
161-
.then((res: any) => {
162-
mcpToolSelectOptions.value = [...res.data.shared_tools, ...res.data.tools].filter(
163-
(item: any) => item.is_active,
164-
)
165-
})
137+
function mcpSourceChange() {
138+
if (form.value.mcp_source === 'referencing') {
139+
form.value.mcp_servers = ''
140+
} else {
141+
form.value.mcp_tool_id = ''
142+
}
166143
}
167144
168-
const open = (data: any) => {
145+
146+
const open = (data: any, selectOptions: any) => {
169147
form.value = { ...form.value, ...data }
170148
form.value.mcp_source = data.mcp_source || 'referencing'
171149
dialogVisible.value = true
150+
mcpToolSelectOptions.value = selectOptions || []
172151
}
173152
174153
const submit = () => {
@@ -180,10 +159,6 @@ const submit = () => {
180159
})
181160
}
182161
183-
onMounted(() => {
184-
getMcpToolSelectOptions()
185-
})
186-
187162
defineExpose({ open })
188163
</script>
189164
<style lang="scss" scoped></style>

ui/src/workflow/nodes/ai-chat-node/index.vue

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
/>
115115
</el-form-item>
116116

117+
<!-- MCP-->
117118
<div class="flex-between mb-16">
118119
<div class="lighter">MCP</div>
119120
<div>
@@ -129,6 +130,24 @@
129130
<el-switch size="small" v-model="chat_data.mcp_enable" />
130131
</div>
131132
</div>
133+
<div class="w-full" v-if="
134+
(chat_data.mcp_tool_id) ||
135+
(chat_data.mcp_servers && chat_data.mcp_servers.length > 0)"
136+
>
137+
<div class="flex-between border border-r-6 white-bg mb-4" style="padding: 5px 8px">
138+
<div class="flex align-center" style="line-height: 20px">
139+
<ToolIcon type="MCP" class="mr-8" :size="20" />
140+
141+
<div class="ellipsis" :title="relatedObject(toolSelectOptions, chat_data.mcp_tool_id, 'id')?.name">
142+
{{ relatedObject(mcpToolSelectOptions, chat_data.mcp_tool_id, 'id')?.name || $t('common.custom') + ' MCP' }}
143+
</div>
144+
</div>
145+
<el-button text @click="chat_data.mcp_tool_id = ''">
146+
<el-icon><Close /></el-icon>
147+
</el-button>
148+
</div>
149+
</div>
150+
<!-- 工具 -->
132151
<div class="flex-between mb-16">
133152
<div class="lighter">{{ $t('views.applicationWorkflow.nodes.mcpNode.tool') }}</div>
134153
<div>
@@ -144,6 +163,22 @@
144163
<el-switch size="small" v-model="chat_data.tool_enable" />
145164
</div>
146165
</div>
166+
<div class="w-full" v-if="chat_data.tool_ids?.length > 0">
167+
<template v-for="(item, index) in chat_data.tool_ids" :key="index">
168+
<div class="flex-between border border-r-6 white-bg mb-4" style="padding: 5px 8px">
169+
<div class="flex align-center" style="line-height: 20px">
170+
<ToolIcon type="CUSTOM" class="mr-8" :size="20" />
171+
172+
<div class="ellipsis" :title="relatedObject(toolSelectOptions, item, 'id')?.name">
173+
{{ relatedObject(toolSelectOptions, item, 'id')?.name }}
174+
</div>
175+
</div>
176+
<el-button text @click="removeTool(item)">
177+
<el-icon><Close /></el-icon>
178+
</el-button>
179+
</div>
180+
</template>
181+
</div>
147182

148183
<el-form-item @click.prevent>
149184
<template #label>
@@ -206,6 +241,7 @@ import McpServersDialog from '@/views/application/component/McpServersDialog.vue
206241
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
207242
import { useRoute } from 'vue-router'
208243
import ToolDialog from '@/views/application/component/ToolDialog.vue'
244+
import {relatedObject} from "@/utils/array.ts";
209245
const getApplicationDetail = inject('getApplicationDetail') as any
210246
const route = useRoute()
211247
@@ -352,7 +388,7 @@ function openMcpServersDialog() {
352388
mcp_tool_id: chat_data.value.mcp_tool_id,
353389
mcp_source: chat_data.value.mcp_source,
354390
}
355-
mcpServersDialogRef.value.open(config)
391+
mcpServersDialogRef.value.open(config, mcpToolSelectOptions.value)
356392
}
357393
358394
function submitMcpServersDialog(config: any) {
@@ -368,6 +404,10 @@ function openToolDialog() {
368404
function submitToolDialog(config: any) {
369405
set(props.nodeModel.properties.node_data, 'tool_ids', config.tool_ids)
370406
}
407+
function removeTool(id: any) {
408+
const list = props.nodeModel.properties.node_data.tool_ids.filter((v: any) => v !== id)
409+
set(props.nodeModel.properties.node_data, 'tool_ids', list)
410+
}
371411
372412
const toolSelectOptions = ref<any[]>([])
373413
function getToolSelectOptions() {
@@ -392,6 +432,29 @@ function getToolSelectOptions() {
392432
})
393433
}
394434
435+
const mcpToolSelectOptions = ref<any[]>([])
436+
function getMcpToolSelectOptions() {
437+
const obj =
438+
apiType.value === 'systemManage'
439+
? {
440+
scope: 'WORKSPACE',
441+
tool_type: 'MCP',
442+
workspace_id: application.value?.workspace_id,
443+
}
444+
: {
445+
scope: 'WORKSPACE',
446+
tool_type: 'MCP',
447+
}
448+
449+
loadSharedApi({ type: 'tool', systemType: apiType.value })
450+
.getAllToolList(obj)
451+
.then((res: any) => {
452+
mcpToolSelectOptions.value = [...res.data.shared_tools, ...res.data.tools].filter(
453+
(item: any) => item.is_active,
454+
)
455+
})
456+
}
457+
395458
onMounted(() => {
396459
getSelectModel()
397460
if (typeof props.nodeModel.properties.node_data?.is_result === 'undefined') {
@@ -405,6 +468,7 @@ onMounted(() => {
405468
}
406469
407470
getToolSelectOptions()
471+
getMcpToolSelectOptions()
408472
})
409473
</script>
410474
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)