From 3263d50f4b112168efa5d41d76b604d301ebf268 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Wed, 11 Feb 2026 07:10:22 +0400 Subject: [PATCH] refactor(mcp): Use BlockUIType.MCP_TOOL instead of SpecialBlockID checks Add MCP_TOOL to backend BlockType enum and frontend BlockUIType enum, matching the existing pattern used by AGENT blocks. Replace all SpecialBlockID.MCP_TOOL type-checks with uiType-based checks. --- autogpt_platform/backend/backend/blocks/mcp/block.py | 2 +- autogpt_platform/backend/backend/data/block.py | 1 + .../FlowEditor/nodes/CustomNode/useCustomNode.tsx | 4 +--- .../components/NewControlPanel/NewBlockMenu/Block.tsx | 4 ++-- .../build/components/legacy-builder/BlocksControl.tsx | 8 ++++---- .../components/legacy-builder/CustomNode/CustomNode.tsx | 3 +-- .../build/components/legacy-builder/Flow/Flow.tsx | 2 +- .../frontend/src/app/(platform)/build/components/types.ts | 1 + .../frontend/src/lib/autogpt-server-api/types.ts | 1 + 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/autogpt_platform/backend/backend/blocks/mcp/block.py b/autogpt_platform/backend/backend/blocks/mcp/block.py index 92a57e7477..7554af9b6a 100644 --- a/autogpt_platform/backend/backend/blocks/mcp/block.py +++ b/autogpt_platform/backend/backend/blocks/mcp/block.py @@ -131,7 +131,7 @@ class MCPToolBlock(Block): categories={BlockCategory.DEVELOPER_TOOLS}, input_schema=MCPToolBlock.Input, output_schema=MCPToolBlock.Output, - block_type=BlockType.STANDARD, + block_type=BlockType.MCP_TOOL, test_credentials=TEST_CREDENTIALS, test_input={ "server_url": "https://mcp.example.com/mcp", diff --git a/autogpt_platform/backend/backend/data/block.py b/autogpt_platform/backend/backend/data/block.py index f67134ceb3..445f2c6c6d 100644 --- a/autogpt_platform/backend/backend/data/block.py +++ b/autogpt_platform/backend/backend/data/block.py @@ -74,6 +74,7 @@ class BlockType(Enum): AI = "AI" AYRSHARE = "Ayrshare" HUMAN_IN_THE_LOOP = "Human In The Loop" + MCP_TOOL = "MCP Tool" class BlockCategory(Enum): diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/useCustomNode.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/useCustomNode.tsx index 52b491d68e..050515a02f 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/useCustomNode.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/FlowEditor/nodes/CustomNode/useCustomNode.tsx @@ -3,8 +3,6 @@ import { CustomNodeData } from "./CustomNode"; import { BlockUIType } from "../../../types"; import { useMemo } from "react"; import { mergeSchemaForResolution } from "./helpers"; -import { SpecialBlockID } from "@/lib/autogpt-server-api"; - /** * Build a dynamic input schema for MCP blocks. * @@ -50,7 +48,7 @@ export const useCustomNode = ({ const isAgent = data.uiType === BlockUIType.AGENT; const isMCPWithTool = - data.block_id === SpecialBlockID.MCP_TOOL && + data.uiType === BlockUIType.MCP_TOOL && !!data.hardcodedValues?.tool_input_schema?.properties; const currentInputSchema = isAgent diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/Block.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/Block.tsx index 4c779380ac..2edd5686c6 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/Block.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/NewControlPanel/NewBlockMenu/Block.tsx @@ -9,7 +9,7 @@ import { useControlPanelStore } from "../../../stores/controlPanelStore"; import { blockDragPreviewStyle } from "./style"; import { useReactFlow } from "@xyflow/react"; import { useNodeStore } from "../../../stores/nodeStore"; -import { SpecialBlockID } from "@/lib/autogpt-server-api"; +import { BlockUIType, SpecialBlockID } from "@/lib/autogpt-server-api"; import { MCPToolDialog, type MCPToolDialogResult, @@ -41,7 +41,7 @@ export const Block: BlockComponent = ({ const { addBlock } = useNodeStore(); const [mcpDialogOpen, setMcpDialogOpen] = useState(false); - const isMCPBlock = blockData.id === SpecialBlockID.MCP_TOOL; + const isMCPBlock = blockData.uiType === BlockUIType.MCP_TOOL; const addBlockAndCenter = useCallback( (block: BlockInfo, hardcodedValues?: Record) => { diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/BlocksControl.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/BlocksControl.tsx index d41478b5b2..283a7b2093 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/BlocksControl.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/BlocksControl.tsx @@ -212,7 +212,7 @@ export function BlocksControl({ if (block.notAvailable) return; // For MCP blocks, open the configuration dialog instead of placing directly - if (block.id === SpecialBlockID.MCP_TOOL) { + if (block.uiType === BlockUIType.MCP_TOOL) { setMcpDialogOpen(true); return; } @@ -349,19 +349,19 @@ export function BlocksControl({ className={`m-2 my-4 flex h-20 shadow-none dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100 dark:hover:bg-slate-700 ${ block.notAvailable ? "cursor-not-allowed opacity-50" - : block.id === SpecialBlockID.MCP_TOOL + : block.uiType === BlockUIType.MCP_TOOL ? "cursor-pointer hover:shadow-lg" : "cursor-move hover:shadow-lg" }`} data-id={`block-card-${block.id}`} draggable={ !block.notAvailable && - block.id !== SpecialBlockID.MCP_TOOL + block.uiType !== BlockUIType.MCP_TOOL } onDragStart={(e) => { if ( block.notAvailable || - block.id === SpecialBlockID.MCP_TOOL + block.uiType === BlockUIType.MCP_TOOL ) return; e.dataTransfer.effectAllowed = "copy"; diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/CustomNode/CustomNode.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/CustomNode/CustomNode.tsx index ffa70db26b..7b1abdbfbd 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/CustomNode/CustomNode.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/CustomNode/CustomNode.tsx @@ -21,7 +21,6 @@ import { GraphInputSchema, GraphOutputSchema, NodeExecutionResult, - SpecialBlockID, } from "@/lib/autogpt-server-api"; import { beautifyString, @@ -218,7 +217,7 @@ export const CustomNode = React.memo( // MCP Tool block: display the selected tool's dynamic schema const isMCPWithTool = - data.block_id === SpecialBlockID.MCP_TOOL && + data.uiType === BlockUIType.MCP_TOOL && !!data.hardcodedValues?.tool_input_schema?.properties; if (isMCPWithTool) { diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/Flow/Flow.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/Flow/Flow.tsx index 6cd8721be5..b633c493f3 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/Flow/Flow.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/legacy-builder/Flow/Flow.tsx @@ -753,7 +753,7 @@ const FlowEditor: React.FC<{ isOutputStatic: nodeSchema.staticOutput, uiType: nodeSchema.uiType, // Set customized_name at creation so it persists through save/load - ...(blockID === SpecialBlockID.MCP_TOOL && { + ...(nodeSchema.uiType === BlockUIType.MCP_TOOL && { metadata: { credentials_optional: true, ...(finalHardcodedValues.selected_tool && { diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/types.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/types.ts index 2fde427330..0f5021351d 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/types.ts +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/types.ts @@ -9,4 +9,5 @@ export enum BlockUIType { AGENT = "Agent", AI = "AI", AYRSHARE = "Ayrshare", + MCP_TOOL = "MCP Tool", } diff --git a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts index a08aeec0a9..d26c5ddc64 100644 --- a/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts +++ b/autogpt_platform/frontend/src/lib/autogpt-server-api/types.ts @@ -749,6 +749,7 @@ export enum BlockUIType { AGENT = "Agent", AI = "AI", AYRSHARE = "Ayrshare", + MCP_TOOL = "MCP Tool", } export enum SpecialBlockID {