Skip to main content
Glama

add_node

Add a new node as a child to an existing node in Godot .tscn scene files to expand scene trees and organize game elements.

Instructions

Add a new node as a child of an existing node in a .tscn scene file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sceneYesPath to the .tscn file
parentYesParent node path (use root node name for root, or node path like "Path/To/Parent")
typeYesGodot node type (e.g. Sprite2D, Camera2D)
nameYesName for the new node
propertiesNoOptional properties as key-value pairs
expectedHashNoExpected content hash for stale-edit prevention

Implementation Reference

  • The handler function for the add_node tool, which validates the parent node, checks for duplicates, and updates the scene hierarchy.
    handler: async (ctx) => {
      const { scene: scenePath, parent, type, name, properties, expectedHash } = ctx.args;
      validatePath(scenePath);
    
      return withFileLock(scenePath, async () => {
        try {
          const { source, scene } = await readAndParse(scenePath);
          const hashErr = hashCheck(source, expectedHash);
          if (hashErr) return makeTextResponse({ error: hashErr, data: null });
    
          // Validate parent exists
          const parentNode = scene.nodes.get(parent);
          if (!parentNode) {
            return makeTextResponse({
              error: `Parent node not found: ${parent}`,
              data: null,
            });
          }
    
          // Compute parent attr for TSCN format
          const parentAttr = parentNode.parent === null ? "." : parentNode.nodePath;
          const newNodePath =
            parentNode.parent === null ? name : parentNode.nodePath + "/" + name;
    
          // Check for duplicate
          if (scene.nodes.has(newNodePath)) {
            return makeTextResponse({
              error: `Node already exists: ${newNodePath}`,
              data: null,
            });
          }
    
          // Build properties
          const nodeProps: Record<string, unknown> = {};
          if (properties) {
            for (const [key, value] of Object.entries(properties)) {
              nodeProps[key] = convertJsonToTscnValue(value);
            }
          }
    
          // Create NodeInfo
          const newNode: NodeInfo = {
            name,
            type,
            scenePath: scenePath,
            nodePath: newNodePath,
            parent: parentAttr,
            children: [],
            script: null,
            groups: [],
            properties: nodeProps,
            isInstanceOf: null,
            rawSpan: null,
          };
    
          scene.nodes.set(newNodePath, newNode);
          parentNode.children.push(name);
    
          await writeAndEmit(scenePath, scene, eventBus, ctx.signal);
    
          return makeTextResponse({
            data: {
              added: newNodePath,
              parent: parentAttr,
              type,
            },
            metadata: { source: "index" },
          });
  • Schema definition for the add_node tool inputs including scene path, parent node, node type, name, properties, and optional expectedHash.
    schema: {
      scene: z.string().describe("Path to the .tscn file"),
      parent: z
        .string()
        .describe(
          'Parent node path (use root node name for root, or node path like "Path/To/Parent")',
        ),
      type: z.string().describe("Godot node type (e.g. Sprite2D, Camera2D)"),
      name: z.string().describe("Name for the new node"),
      properties: z
        .record(z.unknown())
        .optional()
        .describe("Optional properties as key-value pairs"),
      expectedHash: z
        .string()
        .optional()
        .describe("Expected content hash for stale-edit prevention"),
    },
  • Registration of the add_node tool within the tool list.
    {
      name: "add_node",
      description: {
        base: "Add a new node as a child of an existing node in a .tscn scene file.",
        slots: {
          editing:
            "Provide contentHash from your last read to prevent conflicts with concurrent edits.",
          planning:
            "Consider the scene hierarchy carefully before adding nodes. Use get_scene_tree first.",
        },
      },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states the basic action without disclosing critical behavioral traits. It doesn't mention whether this modifies files destructively, requires specific permissions, handles errors, or provides feedback on success/failure. The description is minimal and lacks operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It front-loads the core purpose ('Add a new node') and specifies the context ('.tscn scene file', 'child of an existing node') concisely.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 6 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what happens after addition (e.g., returns success, modifies file in-place), error conditions, or interaction with other tools like 'get_scene_tree'. The complexity warrants more guidance on behavior and outcomes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are fully documented in the schema. The description adds no additional meaning beyond implying a parent-child relationship, which is already covered in the 'parent' parameter description. Baseline score of 3 applies as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Add a new node'), the target resource ('.tscn scene file'), and the relationship ('as a child of an existing node'). It distinguishes from sibling tools like 'remove_node' and 'modify_node_property' by focusing on creation with parent-child hierarchy.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when adding nodes to scene files but provides no explicit guidance on when to use this versus alternatives like 'create_scene' (for new scenes) or 'modify_node_property' (for existing nodes). It mentions the parent-child relationship contextually but lacks when-not scenarios or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/woohq/godette-mcp'

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