remove_nodes
Permanently delete multiple nodes and all their descendants from HNPX hierarchical fiction documents to manage narrative structure.
Instructions
Permanently remove multiple nodes and all their descendants
Args: file_path (str): Path to the HNPX document node_ids (list): List of node IDs to remove
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| node_ids | Yes |
Implementation Reference
- src/hnpx_sdk/tools.py:417-444 (handler)The main handler function that implements the remove_nodes tool. It parses the HNPX document, finds and removes the specified nodes (preventing root removal), saves the changes, and returns a confirmation message.def remove_nodes(file_path: str, node_ids: list) -> str: """Permanently remove multiple nodes and all their descendants Args: file_path (str): Path to the HNPX document node_ids (list): List of node IDs to remove """ tree = hnpx.parse_document(file_path) nodes_removed = 0 for node_id in node_ids: node = hnpx.find_node(tree, node_id) if node is None: raise NodeNotFoundError(node_id) # Check if trying to remove root if node.tag == "book": raise InvalidOperationError("remove_nodes", "Cannot remove book element") # Remove node parent = node.getparent() parent.remove(node) nodes_removed += 1 hnpx.save_document(tree, file_path) return f"Removed {nodes_removed} nodes and their descendants"
- src/hnpx_sdk/server.py:31-31 (registration)Registration of the remove_nodes tool in the FastMCP application.app.tool()(tools.remove_nodes)