Skip to main content
Glama

Unreal Engine MCP Bridge

by gingerol
umg_tools.py13.2 kB
#!/usr/bin/env python """ UMG Tools for Unreal Engine MCP Provides tools for creating and manipulating UMG (Unreal Motion Graphics) widgets. """ import logging from typing import Dict, Any, List, Optional, Union logger = logging.getLogger("UnrealMCP.UMGTools") def register_umg_tools(mcp): """Register all UMG tools with the MCP server.""" @mcp.tool() def create_umg_widget_blueprint( widget_name: str, parent_class: str = "UserWidget", path: str = "/Game/UI" ) -> Dict[str, Any]: """Create a new UMG Widget Blueprint. Args: widget_name: The name of the Widget Blueprint to create. parent_class: The parent class for the Widget Blueprint. path: The content browser path where the Widget Blueprint should be created. Returns: A dictionary containing the result of the operation and the Widget Blueprint 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 = { "widget_name": widget_name, "parent_class": parent_class, "path": path } response = conn.send_command("create_umg_widget_blueprint", params) return response @mcp.tool() def add_text_block_to_widget( widget_name: str, text_block_name: str, text: str = "", position: List[float] = [0, 0], size: List[float] = [200, 50], font_size: int = 12, color: List[float] = [1, 1, 1, 1], # RGBA horizontal_alignment: str = "Center", vertical_alignment: str = "Center", wrap_text: bool = True ) -> Dict[str, Any]: """Add a Text Block widget to a UMG Widget Blueprint. Args: widget_name: The name or path of the Widget Blueprint to modify. text_block_name: The name to give the new Text Block widget. text: The initial text to display. position: [X, Y] coordinates for the widget's position. size: [Width, Height] for the widget's size. font_size: The font size to use. color: [R, G, B, A] color values (0.0-1.0) for the text. horizontal_alignment: Horizontal text alignment ("Left", "Center", "Right"). vertical_alignment: Vertical text alignment ("Top", "Center", "Bottom"). wrap_text: Whether the text should wrap when it reaches the edge of the containing box. Returns: A dictionary containing the result of the operation and the widget 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 = { "widget_name": widget_name, "text_block_name": text_block_name, "text": text, "position": position, "size": size, "font_size": font_size, "color": color, "horizontal_alignment": horizontal_alignment, "vertical_alignment": vertical_alignment, "wrap_text": wrap_text } response = conn.send_command("add_text_block_to_widget", params) return response @mcp.tool() def add_button_to_widget( widget_name: str, button_name: str, text: str = "", position: List[float] = [0, 0], size: List[float] = [200, 50], font_size: int = 12, text_color: List[float] = [1, 1, 1, 1], # RGBA background_color: List[float] = [0.1, 0.1, 0.1, 1], # RGBA hover_color: List[float] = [0.2, 0.2, 0.2, 1], # RGBA pressed_color: List[float] = [0.05, 0.05, 0.05, 1] # RGBA ) -> Dict[str, Any]: """Add a Button widget to a UMG Widget Blueprint. Args: widget_name: The name or path of the Widget Blueprint to modify. button_name: The name to give the new Button widget. text: The text to display on the button. position: [X, Y] coordinates for the widget's position. size: [Width, Height] for the widget's size. font_size: The font size to use for the button text. text_color: [R, G, B, A] color values (0.0-1.0) for the button text. background_color: [R, G, B, A] color values for the button's normal state. hover_color: [R, G, B, A] color values for the button's hover state. pressed_color: [R, G, B, A] color values for the button's pressed state. Returns: A dictionary containing the result of the operation and the widget 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 = { "widget_name": widget_name, "button_name": button_name, "text": text, "position": position, "size": size, "font_size": font_size, "text_color": text_color, "background_color": background_color, "hover_color": hover_color, "pressed_color": pressed_color } response = conn.send_command("add_button_to_widget", params) return response @mcp.tool() def add_image_to_widget( widget_name: str, image_name: str, image_path: str = None, position: List[float] = [0, 0], size: List[float] = [200, 200], tint_color: List[float] = [1, 1, 1, 1] # RGBA ) -> Dict[str, Any]: """Add an Image widget to a UMG Widget Blueprint. Args: widget_name: The name or path of the Widget Blueprint to modify. image_name: The name to give the new Image widget. image_path: Optional path to the image asset to use. position: [X, Y] coordinates for the widget's position. size: [Width, Height] for the widget's size. tint_color: [R, G, B, A] color values (0.0-1.0) to tint the image. Returns: A dictionary containing the result of the operation and the widget 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 = { "widget_name": widget_name, "image_name": image_name, "position": position, "size": size, "tint_color": tint_color } if image_path: params["image_path"] = image_path response = conn.send_command("add_image_to_widget", params) return response @mcp.tool() def add_progress_bar_to_widget( widget_name: str, progress_bar_name: str, percent: float = 0.5, position: List[float] = [0, 0], size: List[float] = [200, 20], fill_color: List[float] = [0, 0.5, 1, 1], # RGBA background_color: List[float] = [0.1, 0.1, 0.1, 1] # RGBA ) -> Dict[str, Any]: """Add a Progress Bar widget to a UMG Widget Blueprint. Args: widget_name: The name or path of the Widget Blueprint to modify. progress_bar_name: The name to give the new Progress Bar widget. percent: The initial fill percentage (0.0-1.0). position: [X, Y] coordinates for the widget's position. size: [Width, Height] for the widget's size. fill_color: [R, G, B, A] color values (0.0-1.0) for the fill color. background_color: [R, G, B, A] color values for the background color. Returns: A dictionary containing the result of the operation and the widget 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 = { "widget_name": widget_name, "progress_bar_name": progress_bar_name, "percent": percent, "position": position, "size": size, "fill_color": fill_color, "background_color": background_color } response = conn.send_command("add_progress_bar_to_widget", params) return response @mcp.tool() def bind_widget_event( widget_name: str, widget_component_name: str, event_name: str, function_name: str = "" ) -> Dict[str, Any]: """Bind an event on a widget component to a function. Args: widget_name: The name or path of the Widget Blueprint to modify. widget_component_name: The name of the widget component (e.g., a button). event_name: The name of the event to bind (e.g., "OnClicked", "OnHovered"). function_name: Optional name for the function to create. If empty, a name will be generated. Returns: A dictionary containing the result of the operation and the binding 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 = { "widget_name": widget_name, "widget_component_name": widget_component_name, "event_name": event_name } if function_name: params["function_name"] = function_name response = conn.send_command("bind_widget_event", params) return response @mcp.tool() def add_widget_to_viewport( widget_name: str, z_order: int = 0 ) -> Dict[str, Any]: """Add a widget instance to the game viewport. Args: widget_name: The name or path of the Widget Blueprint to add. z_order: The Z-order for the widget (higher values appear on top). 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 = { "widget_name": widget_name, "z_order": z_order } response = conn.send_command("add_widget_to_viewport", params) return response @mcp.tool() def remove_widget_from_viewport( widget_name: str ) -> Dict[str, Any]: """Remove a widget instance from the game viewport. Args: widget_name: The name or path of the Widget Blueprint to remove. 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 = {"widget_name": widget_name} response = conn.send_command("remove_widget_from_viewport", params) return response @mcp.tool() def set_text_block_binding( widget_name: str, text_block_name: str, binding_property: str, binding_type: str = "Text" ) -> Dict[str, Any]: """Set up a property binding for a Text Block widget. Args: widget_name: The name or path of the Widget Blueprint to modify. text_block_name: The name of the Text Block widget. binding_property: The name of the property to bind to. binding_type: The type of binding ("Text", "Visibility", etc.). Returns: A dictionary containing the result of the operation and the binding 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 = { "widget_name": widget_name, "text_block_name": text_block_name, "binding_property": binding_property, "binding_type": binding_type } response = conn.send_command("set_text_block_binding", params) return response logger.info("Registered UMG 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