Skip to main content
Glama

godot_add_node

Add a new node to a Godot scene by specifying its type, name, and parent path. This tool helps developers build scene hierarchies and configure node properties directly within the Godot editor.

Instructions

Adds a new node of the specified type as a child of the given parent node.

Args:

  • parent_path (string): Node path of the parent e.g. "/root/Main"

  • node_type (string): Godot class name e.g. "Sprite2D", "CharacterBody2D", "Label", "AudioStreamPlayer"

  • node_name (string): Name for the new node

  • scene_path (string, optional): Scene to modify. Defaults to active scene.

  • properties (object, optional): Initial property values to set on the new node.

Returns: { name, type, path } of the created node.

Examples:

  • Use when: "Add a Sprite2D called PlayerSprite under /root/Main"

  • Use when: "Add a Label node to the HUD with text 'Score: 0'"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
parent_pathYesNode path of the parent node
node_typeYesGodot class name for the new node
node_nameYesName for the new node
scene_pathNoScene to modify. Omit for active scene.
propertiesNoInitial property key/value pairs

Implementation Reference

  • The handler function that executes the godot_add_node tool. It extracts parameters, makes a POST request to the Godot client at '/scene/node', and returns the created node information.
    async ({ parent_path, node_type, node_name, scene_path, properties }) => {
      const result = await godotRequest<GodotNodeInfo>("POST", "/scene/node", {
        parent_path, node_type, node_name, scene_path, properties
      });
      return {
        content: [{ type: "text", text: `Node created: ${JSON.stringify(result, null, 2)}` }]
      };
    }
  • The input validation schema using Zod for godot_add_node. Defines required fields (parent_path, node_type, node_name) and optional fields (scene_path, properties).
    inputSchema: z.object({
      parent_path: z.string().describe("Node path of the parent node"),
      node_type: z.string().describe("Godot class name for the new node"),
      node_name: z.string().describe("Name for the new node"),
      scene_path: z.string().optional().describe("Scene to modify. Omit for active scene."),
      properties: z.record(z.unknown()).optional().describe("Initial property key/value pairs")
    }).strict(),
  • The complete registration of the godot_add_node tool with MCP server, including title, description, input schema, annotations, and the handler function.
      server.registerTool(
        "godot_add_node",
        {
          title: "Add Node to Scene",
          description: `Adds a new node of the specified type as a child of the given parent node.
    
    Args:
      - parent_path (string): Node path of the parent e.g. "/root/Main"
      - node_type (string): Godot class name e.g. "Sprite2D", "CharacterBody2D", "Label", "AudioStreamPlayer"
      - node_name (string): Name for the new node
      - scene_path (string, optional): Scene to modify. Defaults to active scene.
      - properties (object, optional): Initial property values to set on the new node.
    
    Returns:
      { name, type, path } of the created node.
    
    Examples:
      - Use when: "Add a Sprite2D called PlayerSprite under /root/Main"
      - Use when: "Add a Label node to the HUD with text 'Score: 0'"`,
          inputSchema: z.object({
            parent_path: z.string().describe("Node path of the parent node"),
            node_type: z.string().describe("Godot class name for the new node"),
            node_name: z.string().describe("Name for the new node"),
            scene_path: z.string().optional().describe("Scene to modify. Omit for active scene."),
            properties: z.record(z.unknown()).optional().describe("Initial property key/value pairs")
          }).strict(),
          annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
        },
        async ({ parent_path, node_type, node_name, scene_path, properties }) => {
          const result = await godotRequest<GodotNodeInfo>("POST", "/scene/node", {
            parent_path, node_type, node_name, scene_path, properties
          });
          return {
            content: [{ type: "text", text: `Node created: ${JSON.stringify(result, null, 2)}` }]
          };
        }
      );
  • The godotRequest helper function used by the handler to make HTTP requests to the Godot MCP Bridge. Handles errors, connection issues, and response parsing.
    export async function godotRequest<T>(
      method: "GET" | "POST" | "PUT" | "DELETE",
      path: string,
      body?: unknown
    ): Promise<T> {
      try {
        const response = await client.request<ApiResponse<T>>({
          method,
          url: path,
          data: body
        });
    
        const payload = response.data;
        if (!payload.success) {
          throw new Error(payload.error ?? "Godot returned an unsuccessful response.");
        }
        return payload.data as T;
      } catch (err) {
        if (axios.isAxiosError(err)) {
          const axErr = err as AxiosError<ApiResponse<unknown>>;
          if (axErr.code === "ECONNREFUSED") {
            throw new Error(
              `Cannot connect to Godot at ${GODOT_BASE_URL}. ` +
              `Make sure the MCP Bridge plugin is enabled and the project is running ` +
              `(Project > Tools > MCP Bridge > Start Server).`
            );
          }
          const serverMsg = axErr.response?.data?.error;
          throw new Error(serverMsg ?? axErr.message);
        }
        throw err;
      }
    }

Latest Blog Posts

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/ricky-yosh/godot-mcp-server'

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