remove_node_children
Remove all child elements from a specified parent node in HNPX XML documents to restructure narrative hierarchies during fiction writing.
Instructions
Remove all children of a node
Args: file_path (str): Path to the HNPX document node_id (str): ID of the parent node
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| node_id | Yes |
Implementation Reference
- src/hnpx_sdk/tools.py:595-618 (handler)The handler function that parses the HNPX document, finds the node by ID, removes all its non-summary children, saves the document, and returns a confirmation message.def remove_node_children(file_path: str, node_id: str) -> str: """Remove all children of a node Args: file_path (str): Path to the HNPX document node_id (str): ID of the parent node """ tree = hnpx.parse_document(file_path) node = hnpx.find_node(tree, node_id) if node is None: raise NodeNotFoundError(node_id) children_count = 0 # Remove all children except summary for child in list(node): if child.tag != "summary": node.remove(child) children_count += 1 hnpx.save_document(tree, file_path) return f"Removed {children_count} children from node {node_id}"
- src/hnpx_sdk/server.py:32-32 (registration)Registers the remove_node_children tool with the MCP server using the app.tool() decorator.app.tool()(tools.remove_node_children)