Skip to main content
Glama

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
NameRequiredDescriptionDefault
file_pathYes
node_idsYes

Implementation Reference

  • 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"
  • Registration of the remove_nodes tool in the FastMCP application.
    app.tool()(tools.remove_nodes)

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/mozhaa/hnpx-sdk'

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