delete_node
Remove a node from Dynalist documents. Choose to delete only the node while moving its children up, or delete the node along with all its descendants.
Instructions
Delete a node from a Dynalist document. By default, only the node is deleted and its children move up to the parent. Use include_children=true to delete the node AND all its descendants.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | Dynalist URL with node deep link | |
| file_id | No | Document ID (alternative to URL) | |
| node_id | Yes | Node ID to delete | |
| include_children | No | If true, delete the node AND all its children/descendants. If false (default), only delete the node (children move up to parent). |
Implementation Reference
- src/tools/index.ts:754-807 (handler)Main handler function that parses input, resolves document ID, deletes the specified node or recursively all descendants if include_children=true using client.editDocument, and returns success message with count.async ({ url, file_id, node_id, include_children }) => { let documentId = file_id; if (url) { const parsed = parseDynalistUrl(url); documentId = parsed.documentId; } if (!documentId) { return { content: [{ type: "text", text: "Error: Either 'url' or 'file_id' must be provided" }], isError: true, }; } let deletedCount = 1; if (include_children) { // Read document to find all descendants const doc = await client.readDocument(documentId); const nodeMap = buildNodeMap(doc.nodes); // Collect all descendant IDs recursively const nodesToDelete: string[] = []; function collectDescendants(id: string) { nodesToDelete.push(id); const node = nodeMap.get(id); if (node?.children) { for (const childId of node.children) { collectDescendants(childId); } } } collectDescendants(node_id); // Delete all nodes (children first, then parents - reverse order) const changes = nodesToDelete.reverse().map(id => ({ action: "delete" as const, node_id: id })); await client.editDocument(documentId, changes); deletedCount = nodesToDelete.length; } else { // Delete only the node itself await client.editDocument(documentId, [ { action: "delete", node_id } ]); } return { content: [ { type: "text", text: `Deleted ${deletedCount} node(s) successfully!\nDocument: ${documentId}${include_children ? " (including all children)" : " (children moved to parent)"}`, }, ], };
- src/tools/index.ts:748-753 (schema)Zod input schema defining parameters for the delete_node tool.{ url: z.string().optional().describe("Dynalist URL with node deep link"), file_id: z.string().optional().describe("Document ID (alternative to URL)"), node_id: z.string().describe("Node ID to delete"), include_children: z.boolean().optional().default(false).describe("If true, delete the node AND all its children/descendants. If false (default), only delete the node (children move up to parent)."), },
- src/tools/index.ts:745-809 (registration)Registration of the delete_node tool using server.tool with name, description, schema, and handler function.server.tool( "delete_node", "Delete a node from a Dynalist document. By default, only the node is deleted and its children move up to the parent. Use include_children=true to delete the node AND all its descendants.", { url: z.string().optional().describe("Dynalist URL with node deep link"), file_id: z.string().optional().describe("Document ID (alternative to URL)"), node_id: z.string().describe("Node ID to delete"), include_children: z.boolean().optional().default(false).describe("If true, delete the node AND all its children/descendants. If false (default), only delete the node (children move up to parent)."), }, async ({ url, file_id, node_id, include_children }) => { let documentId = file_id; if (url) { const parsed = parseDynalistUrl(url); documentId = parsed.documentId; } if (!documentId) { return { content: [{ type: "text", text: "Error: Either 'url' or 'file_id' must be provided" }], isError: true, }; } let deletedCount = 1; if (include_children) { // Read document to find all descendants const doc = await client.readDocument(documentId); const nodeMap = buildNodeMap(doc.nodes); // Collect all descendant IDs recursively const nodesToDelete: string[] = []; function collectDescendants(id: string) { nodesToDelete.push(id); const node = nodeMap.get(id); if (node?.children) { for (const childId of node.children) { collectDescendants(childId); } } } collectDescendants(node_id); // Delete all nodes (children first, then parents - reverse order) const changes = nodesToDelete.reverse().map(id => ({ action: "delete" as const, node_id: id })); await client.editDocument(documentId, changes); deletedCount = nodesToDelete.length; } else { // Delete only the node itself await client.editDocument(documentId, [ { action: "delete", node_id } ]); } return { content: [ { type: "text", text: `Deleted ${deletedCount} node(s) successfully!\nDocument: ${documentId}${include_children ? " (including all children)" : " (children moved to parent)"}`, }, ], }; } );