From fce2f50a014b50c2973eb8c2bac0b4996fc42c0e Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Tue, 8 Jul 2025 17:02:02 +0800 Subject: [PATCH] fix: Apply MCP node acquisition tool (#3510) --- apps/application/serializers/application.py | 4 ++-- apps/application/views/application.py | 9 ++++++--- ui/src/api/application/application.ts | 11 ++++++----- ui/src/workflow/nodes/mcp-node/index.vue | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/application/serializers/application.py b/apps/application/serializers/application.py index 9dada48a4..74ed342df 100644 --- a/apps/application/serializers/application.py +++ b/apps/application/serializers/application.py @@ -572,8 +572,8 @@ class PlayDemoTextRequest(serializers.Serializer): async def get_mcp_tools(servers): - async with MultiServerMCPClient(servers) as client: - return client.get_tools() + client = MultiServerMCPClient(servers) + return await client.get_tools() class McpServersSerializer(serializers.Serializer): diff --git a/apps/application/views/application.py b/apps/application/views/application.py index 8b032bf67..66cf79da7 100644 --- a/apps/application/views/application.py +++ b/apps/application/views/application.py @@ -71,7 +71,8 @@ class ApplicationAPI(APIView): RoleConstants.USER.get_workspace_role(), RoleConstants.WORKSPACE_MANAGE.get_workspace_role()) def get(self, request: Request, workspace_id: str): - return result.success(Query(data={'workspace_id': workspace_id, 'user_id': request.user.id}).list(request.query_params)) + return result.success( + Query(data={'workspace_id': workspace_id, 'user_id': request.user.id}).list(request.query_params)) class Page(APIView): authentication_classes = [TokenAuth] @@ -266,9 +267,11 @@ class McpServers(APIView): [PermissionConstants.APPLICATION.get_workspace_application_permission()], CompareConstants.AND), RoleConstants.WORKSPACE_MANAGE.get_workspace_role()) - def get(self, request: Request, workspace_id, application_id: str): + def post(self, request: Request, workspace_id, application_id: str): return result.success(ApplicationOperateSerializer( - data={'mcp_servers': request.query_params.get('mcp_servers')}).get_mcp_servers()) + data={'mcp_servers': request.query_params.get('mcp_servers'), 'workspace_id': workspace_id, + 'user_id': request.user.id, + 'application_id': application_id}).get_mcp_servers(request.data)) class SpeechToText(APIView): diff --git a/ui/src/api/application/application.ts b/ui/src/api/application/application.ts index bf416cc2b..ca83a1b83 100644 --- a/ui/src/api/application/application.ts +++ b/ui/src/api/application/application.ts @@ -289,11 +289,12 @@ const speechToText: ( /** * mcp 节点 */ -const getMcpTools: (application_id: String, loading?: Ref) => Promise> = ( - application_id, - loading, -) => { - return get(`${prefix.value}/${application_id}/mcp_tools`, undefined, loading) +const getMcpTools: ( + application_id: String, + mcp_servers: any, + loading?: Ref, +) => Promise> = (application_id, mcp_servers, loading) => { + return post(`${prefix.value}/${application_id}/mcp_tools`, { mcp_servers }, {}, loading) } /** diff --git a/ui/src/workflow/nodes/mcp-node/index.vue b/ui/src/workflow/nodes/mcp-node/index.vue index 4922217b8..b0c27b89c 100644 --- a/ui/src/workflow/nodes/mcp-node/index.vue +++ b/ui/src/workflow/nodes/mcp-node/index.vue @@ -260,7 +260,7 @@ function getTools() { MsgError(t('views.applicationWorkflow.nodes.mcpNode.mcpServerTip')) return } - applicationApi.getMcpTools(id, loading).then((res: any) => { + applicationApi.getMcpTools(id, form_data.value.mcp_servers, loading).then((res: any) => { form_data.value.mcp_tools = res.data MsgSuccess(t('views.applicationWorkflow.nodes.mcpNode.getToolsSuccess')) // 修改了json,刷新mcp_server