get_path
Retrieve the hierarchical path from document root to a specified node in HNPX XML documents for structured fiction writing.
Instructions
Return hierarchical path from document root to specified node
Args: file_path (str): Path to the HNPX document node_id (str): ID of the target node
Returns: str: Concatenated XML representation of all nodes in the path from root to target
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| node_id | Yes |
Implementation Reference
- src/hnpx_sdk/tools.py:196-224 (handler)The main handler function for the 'get_path' tool. It parses the HNPX XML document, locates the specified node by ID, traverses up to the root collecting all ancestors, and returns their concatenated HTML-formatted XML representations separated by newlines.def get_path(file_path: str, node_id: str) -> str: """Return hierarchical path from document root to specified node Args: file_path (str): Path to the HNPX document node_id (str): ID of the target node Returns: str: Concatenated XML representation of all nodes in the path from root to target """ tree = hnpx.parse_document(file_path) node = hnpx.find_node(tree, node_id) if node is None: raise NodeNotFoundError(node_id) # Collect ancestors ancestors = [] current = node while current is not None: ancestors.insert(0, current) current = current.getparent() # Return concatenated XML of all ancestors path_xml = [] for ancestor in ancestors: path_xml.append(etree.tostring(ancestor, encoding="unicode", method="html")) return "\n".join(path_xml)
- src/hnpx_sdk/server.py:15-15 (registration)The registration of the 'get_path' tool in the FastMCP application using the app.tool() decorator.app.tool()(tools.get_path)