Skip to main content
Glama

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

Implementation Reference

  • 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)
  • The registration of the 'get_path' tool in the FastMCP application using the app.tool() decorator.
    app.tool()(tools.get_path)

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