get_node
Retrieve XML representation of a specific node from HNPX documents for hierarchical fiction writing, extracting individual narrative elements with attributes and summary data.
Instructions
Retrieve XML representation of a specific node (without descendants)
Args: file_path (str): Path to the HNPX document node_id (str): ID of the node to retrieve
Returns: str: XML representation of the node with its attributes and summary child only
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| node_id | Yes |
Implementation Reference
- src/hnpx_sdk/tools.py:84-103 (handler)The main handler function for the 'get_node' tool. It parses the HNPX XML document, locates the node by ID, removes all children except the summary, and returns the node's XML string.def get_node(file_path: str, node_id: str) -> str: """Retrieve XML representation of a specific node (without descendants) Args: file_path (str): Path to the HNPX document node_id (str): ID of the node to retrieve Returns: str: XML representation of the node with its attributes and summary child only """ tree = hnpx.parse_document(file_path) node = hnpx.find_node(tree, node_id) if node is None: raise NodeNotFoundError(node_id) _remove_children(node) # Return node with all attributes and summary child return etree.tostring(node, encoding="unicode", method="html")
- src/hnpx_sdk/server.py:11-11 (registration)Registers the get_node function as an MCP tool using FastMCP's app.tool() decorator.app.tool()(tools.get_node)
- src/hnpx_sdk/tools.py:78-82 (helper)Helper function used by get_node to strip all child elements except the 'summary' from the retrieved node.def _remove_children(node: Any) -> None: for child in node: if child.tag != "summary": node.remove(child)