From 75deddd10251923ed3351075341d12fffcceaa86 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com> Date: Mon, 5 May 2025 18:20:19 -0300 Subject: [PATCH] fix: re-add name and description editing on tool mode except for Composio, fix MCP server code (#7901) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Changed backend to contain readonly props for tools * Show name editing for not readonly tools * Fixed edit-tools test * Updated command to use "uvx" instead of "npx" for stability * Fixed mcp code for authentication on auto_login=false * removed args from component desc * [autofix.ci] apply automated fixes * making tool mode inputs the priority. * fix: Clean up comments and whitespace in component_tool.py * Fix column name * update the dispaly name in composio * fix format * ✨ (get-started-progress.tsx): add data-testid attribute to improve testability and accessibility 🔧 (user-progress-track.spec.ts): update test assertions to use the new data-testid attribute for get started progress title --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Edwin Jose Co-authored-by: Gabriel Luiz Freitas Almeida Co-authored-by: cristhianzl --- .../langflow/base/composio/composio_base.py | 8 +- .../langflow/base/tools/component_tool.py | 22 ++--- .../custom/custom_component/component.py | 2 + .../components/get-started-progress.tsx | 5 +- .../components/toolsTable/index.tsx | 32 +++---- .../homePage/components/McpServerTab.tsx | 15 ++-- .../core/features/user-progress-track.spec.ts | 14 +-- .../extended/features/edit-tools.spec.ts | 90 ++++++++++++++++--- 8 files changed, 128 insertions(+), 60 deletions(-) diff --git a/src/backend/base/langflow/base/composio/composio_base.py b/src/backend/base/langflow/base/composio/composio_base.py index c344b8d83..40f555460 100644 --- a/src/backend/base/langflow/base/composio/composio_base.py +++ b/src/backend/base/langflow/base/composio/composio_base.py @@ -186,7 +186,7 @@ class ComposioBaseComponent(Component): build_config["action"]["options"] = [ { "name": self.sanitize_action_name(action), - "metaData": action, + "metadata": action, } for action in self._actions_data ] @@ -282,10 +282,12 @@ class ComposioBaseComponent(Component): configured_tools = [] for tool in tools: # Set the sanitized name - display_name = self._sanitized_names.get(tool.name, self._name_sanitizer.sub("-", tool.name)) + display_name = self._actions_data.get(tool.name, {}).get( + "display_name", self._sanitized_names.get(tool.name, self._name_sanitizer.sub("-", tool.name)) + ) # Set the tags tool.tags = [tool.name] - tool.metadata = {"display_name": display_name, "display_description": tool.description} + tool.metadata = {"display_name": display_name, "display_description": tool.description, "readonly": True} configured_tools.append(tool) return configured_tools diff --git a/src/backend/base/langflow/base/tools/component_tool.py b/src/backend/base/langflow/base/tools/component_tool.py index 29be7a309..9bc6cf930 100644 --- a/src/backend/base/langflow/base/tools/component_tool.py +++ b/src/backend/base/langflow/base/tools/component_tool.py @@ -7,7 +7,6 @@ from typing import TYPE_CHECKING, Literal import pandas as pd from langchain_core.tools import BaseTool, ToolException from langchain_core.tools.structured import StructuredTool -from loguru import logger from pydantic import BaseModel from langflow.base.tools.constants import TOOL_OUTPUT_NAME @@ -40,21 +39,8 @@ def _get_input_type(input_: InputTypes): def build_description(component: Component, output: Output) -> str: - if not output.required_inputs: - logger.warning(f"Output {output.name} does not have required inputs defined") name = component.name or component.__class__.__name__ - if output.required_inputs: - args = ", ".join( - sorted( - [ - f"{name}. {input_name}: {_get_input_type(component._inputs[input_name])}" - for input_name in output.required_inputs - ] - ) - ) - else: - args = "" - return f"{name}. {output.method}({args}) - {component.description}" + return f"{name}. {output.method} - {component.description}" async def send_message_noop( @@ -211,6 +197,8 @@ class ComponentToolkit: inputs=flow_mode_inputs, param_key="flow_tweak_data", ) + elif tool_mode_inputs: + args_schema = create_input_schema(tool_mode_inputs) elif output.required_inputs: inputs = [ self.component._inputs[input_name] @@ -220,6 +208,7 @@ class ComponentToolkit: # If any of the required inputs are not in tool mode, this means # that when the tool is called it will raise an error. # so we should raise an error here. + # TODO: This logic might need to be improved, example if the required is an api key. if not all(getattr(_input, "tool_mode", False) for _input in inputs): non_tool_mode_inputs = [ input_.name @@ -234,8 +223,7 @@ class ComponentToolkit: ) raise ValueError(msg) args_schema = create_input_schema(inputs) - elif tool_mode_inputs: - args_schema = create_input_schema(tool_mode_inputs) + else: args_schema = create_input_schema(self.component.inputs) diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index faa274a1b..7aa618796 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -1166,6 +1166,7 @@ class Component(CustomComponent): async def _build_tools_metadata_input(self): tools = await self._get_tools() # Always use the latest tool data + tool_data = [ { "name": tool.name, @@ -1174,6 +1175,7 @@ class Component(CustomComponent): "status": True, # Initialize all tools with status True "display_name": tool.metadata.get("display_name", tool.name), "display_description": tool.metadata.get("display_description", tool.description), + "readonly": tool.metadata.get("readonly", False), "args": tool.args, # "args_schema": tool.args_schema, } diff --git a/src/frontend/src/components/core/folderSidebarComponent/components/sideBarFolderButtons/components/get-started-progress.tsx b/src/frontend/src/components/core/folderSidebarComponent/components/sideBarFolderButtons/components/get-started-progress.tsx index ffe27d708..84ade0284 100644 --- a/src/frontend/src/components/core/folderSidebarComponent/components/sideBarFolderButtons/components/get-started-progress.tsx +++ b/src/frontend/src/components/core/folderSidebarComponent/components/sideBarFolderButtons/components/get-started-progress.tsx @@ -84,7 +84,10 @@ export const GetStartedProgress: FC<{ return (
- + {percentageGetStarted >= 100 ? ( <> All Set 🎉 diff --git a/src/frontend/src/modals/toolsModal/components/toolsTable/index.tsx b/src/frontend/src/modals/toolsModal/components/toolsTable/index.tsx index d85ac2c0c..449b3f0fb 100644 --- a/src/frontend/src/modals/toolsModal/components/toolsTable/index.tsx +++ b/src/frontend/src/modals/toolsModal/components/toolsTable/index.tsx @@ -147,27 +147,27 @@ export default function ToolsTable({ cellClass: "text-muted-foreground", }, { - field: isAction ? "name" : "tags", + field: "name", headerName: isAction ? "Action" : "Slug", flex: 1, resizable: false, valueGetter: (params) => - isAction - ? params.data.name !== "" - ? parseString(params.data.name, [ - "snake_case", - "no_blank", - "uppercase", - ]) - : parseString(params.data.display_name, [ - "snake_case", - "no_blank", - "uppercase", - ]) - : parseString(params.data.tags.join(", "), [ + params.data.name !== "" + ? parseString(params.data.name, [ "snake_case", + "no_blank", "uppercase", - ]), + ]) + : isAction + ? parseString(params.data.display_name, [ + "snake_case", + "no_blank", + "uppercase", + ]) + : parseString(params.data.tags.join(", "), [ + "snake_case", + "uppercase", + ]), cellClass: "text-muted-foreground", }, { @@ -281,7 +281,7 @@ export default function ToolsTable({ > {focusedRow && - (isAction ? ( + (isAction || !focusedRow.readonly ? (