add_to_group
Add a node to a group in Godot .tscn scene files to organize and manage scene elements for game development workflows.
Instructions
Add a node to a group in a .tscn scene file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scene | Yes | Path to the .tscn file | |
| nodePath | Yes | Node path within the scene | |
| group | Yes | Group name to add | |
| expectedHash | No | Expected content hash for stale-edit prevention |
Implementation Reference
- src/tools/scene-edit-tools.ts:553-597 (handler)The handler implementation for 'add_to_group', which reads the scene, validates the hash, ensures the node exists, checks if the group is already present, and updates the group list for the node.
handler: async (ctx) => { const { scene: scenePath, nodePath, group, 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 }); const node = scene.nodes.get(nodePath); if (!node) { return makeTextResponse({ error: `Node not found: ${nodePath}`, data: null, }); } if (node.groups.includes(group)) { return makeTextResponse({ error: `Node is already in group: ${group}`, data: null, }); } node.groups.push(group); await writeAndEmit(scenePath, scene, eventBus, ctx.signal); return makeTextResponse({ data: { nodePath, group, groups: node.groups, }, metadata: { source: "index" }, }); } catch (err) { return makeTextResponse({ error: `Failed to add to group: ${(err as Error).message}`, data: null, }); } }); }, - The schema definition for 'add_to_group', including the required scene path, node path, and group name, with an optional expected hash.
schema: { scene: z.string().describe("Path to the .tscn file"), nodePath: z.string().describe("Node path within the scene"), group: z.string().describe("Group name to add"), expectedHash: z .string() .optional() .describe("Expected content hash for stale-edit prevention"), }, - src/tools/scene-edit-tools.ts:541-543 (registration)The registration of the 'add_to_group' tool in the tools array.
{ name: "add_to_group", description: "Add a node to a group in a .tscn scene file.",