Skip to main content
Glama

Unreal Engine MCP Bridge

by gingerol
node_tools.py12.8 kB
#!/usr/bin/env python """ Blueprint Node Tools for Unreal Engine MCP Provides tools for creating and manipulating Blueprint graph nodes and connections. """ import logging from typing import Dict, Any, List, Optional, Union logger = logging.getLogger("UnrealMCP.NodeTools") def register_blueprint_node_tools(mcp): """Register all Blueprint node tools with the MCP server.""" @mcp.tool() def add_blueprint_event_node( blueprint_name: str, event_type: str, custom_name: str = None ) -> Dict[str, Any]: """Add an event node to a Blueprint graph. Args: blueprint_name: The name or path of the Blueprint to modify. event_type: The type of event to add (e.g., BeginPlay, Tick, ActorBeginOverlap). custom_name: Optional custom name for the node (for custom events). Returns: A dictionary containing the result of the operation and the node details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "event_type": event_type } if custom_name: params["custom_name"] = custom_name response = conn.send_command("add_blueprint_event_node", params) return response @mcp.tool() def add_blueprint_input_action_node( blueprint_name: str, action_name: str, key: str = None ) -> Dict[str, Any]: """Add an input action event node to a Blueprint graph. Args: blueprint_name: The name or path of the Blueprint to modify. action_name: The name of the input action to bind to. key: Optional key to bind to the action if it doesn't exist yet. Returns: A dictionary containing the result of the operation and the node details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "action_name": action_name } if key: params["key"] = key response = conn.send_command("add_blueprint_input_action_node", params) return response @mcp.tool() def add_blueprint_function_node( blueprint_name: str, function_name: str, target: str = "self", category: str = None, inputs: Dict[str, Any] = None ) -> Dict[str, Any]: """Add a function call node to a Blueprint graph. Args: blueprint_name: The name or path of the Blueprint to modify. function_name: The name of the function to call. target: The target object for the function call (e.g., "self", a component name, or a class path). category: Optional category for the function (helps with disambiguation). inputs: Optional dictionary of input pin values to set. Returns: A dictionary containing the result of the operation and the node details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "function_name": function_name, "target": target } if category: params["category"] = category if inputs: params["inputs"] = inputs response = conn.send_command("add_blueprint_function_node", params) return response @mcp.tool() def connect_blueprint_nodes( blueprint_name: str, source_node_id: str, source_pin: str, target_node_id: str, target_pin: str ) -> Dict[str, Any]: """Connect two nodes in a Blueprint graph. Args: blueprint_name: The name or path of the Blueprint to modify. source_node_id: The ID of the source node. source_pin: The name of the output pin on the source node. target_node_id: The ID of the target node. target_pin: The name of the input pin on the target node. Returns: A dictionary containing the result of the operation. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "source_node_id": source_node_id, "source_pin": source_pin, "target_node_id": target_node_id, "target_pin": target_pin } response = conn.send_command("connect_blueprint_nodes", params) return response @mcp.tool() def add_blueprint_variable( blueprint_name: str, variable_name: str, variable_type: str, default_value: Any = None, is_exposed: bool = False, category: str = None, tooltip: str = None ) -> Dict[str, Any]: """Add a variable to a Blueprint class. Args: blueprint_name: The name or path of the Blueprint to modify. variable_name: The name of the variable to add. variable_type: The type of the variable (e.g., Boolean, Float, Vector). default_value: Optional default value for the variable. is_exposed: Whether the variable should be exposed to the editor. category: Optional category for organizing variables in the editor. tooltip: Optional tooltip text for the variable. Returns: A dictionary containing the result of the operation and the variable details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "variable_name": variable_name, "variable_type": variable_type, "is_exposed": is_exposed } if default_value is not None: params["default_value"] = default_value if category: params["category"] = category if tooltip: params["tooltip"] = tooltip response = conn.send_command("add_blueprint_variable", params) return response @mcp.tool() def add_blueprint_get_variable_node( blueprint_name: str, variable_name: str ) -> Dict[str, Any]: """Add a 'Get Variable' node to a Blueprint graph. Args: blueprint_name: The name or path of the Blueprint to modify. variable_name: The name of the variable to get. Returns: A dictionary containing the result of the operation and the node details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "variable_name": variable_name } response = conn.send_command("add_blueprint_get_variable_node", params) return response @mcp.tool() def add_blueprint_set_variable_node( blueprint_name: str, variable_name: str ) -> Dict[str, Any]: """Add a 'Set Variable' node to a Blueprint graph. Args: blueprint_name: The name or path of the Blueprint to modify. variable_name: The name of the variable to set. Returns: A dictionary containing the result of the operation and the node details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "variable_name": variable_name } response = conn.send_command("add_blueprint_set_variable_node", params) return response @mcp.tool() def add_blueprint_get_self_component_reference( blueprint_name: str, component_name: str ) -> Dict[str, Any]: """Add a 'Get Component Reference' node for a component in the Blueprint. Args: blueprint_name: The name or path of the Blueprint to modify. component_name: The name of the component to reference. Returns: A dictionary containing the result of the operation and the node details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "component_name": component_name } response = conn.send_command("add_blueprint_get_self_component_reference", params) return response @mcp.tool() def add_blueprint_self_reference( blueprint_name: str ) -> Dict[str, Any]: """Add a 'Self' reference node to a Blueprint graph. Args: blueprint_name: The name or path of the Blueprint to modify. Returns: A dictionary containing the result of the operation and the node details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = {"blueprint_name": blueprint_name} response = conn.send_command("add_blueprint_self_reference", params) return response @mcp.tool() def find_blueprint_nodes( blueprint_name: str, node_type: str = None, event_type: str = None ) -> Dict[str, Any]: """Find nodes in a Blueprint graph by type or event type. Args: blueprint_name: The name or path of the Blueprint to search. node_type: Optional type of node to find (e.g., K2Node_Event, K2Node_CallFunction). event_type: Optional event type to find (e.g., BeginPlay, Tick). Returns: A dictionary containing the list of matching nodes with their details. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = {"blueprint_name": blueprint_name} if node_type: params["node_type"] = node_type if event_type: params["event_type"] = event_type response = conn.send_command("find_blueprint_nodes", params) return response @mcp.tool() def delete_blueprint_node( blueprint_name: str, node_id: str ) -> Dict[str, Any]: """Delete a node from a Blueprint graph. Args: blueprint_name: The name or path of the Blueprint to modify. node_id: The ID of the node to delete. Returns: A dictionary containing the result of the operation. """ from unreal_mcp_server import get_unreal_connection conn = get_unreal_connection() if not conn: return {"status": "error", "error": "Not connected to Unreal Engine"} params = { "blueprint_name": blueprint_name, "node_id": node_id } response = conn.send_command("delete_blueprint_node", params) return response logger.info("Registered blueprint node tools")

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gingerol/UnrealEngine-ai-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server