Skip to main content
Glama

render_node

Extract and format paragraph content from HNPX fiction documents to display narrative text with optional IDs and structural markers.

Instructions

Render text representation of the node (only descendent paragraphs)

Args: file_path (str): Path to the HNPX document node_id (str): ID of the node to render show_ids (bool): Whether to show paragraph IDs in square brackets show_markers (bool): Whether to mark chapter/sequence beginnings

Returns: str: Formatted text representation the node

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
node_idYes
show_idsNo
show_markersNo

Implementation Reference

  • The main handler function for the 'render_node' tool. Parses the HNPX document, finds the specified node, and recursively renders its descendant paragraphs as formatted text, with optional IDs and markers.
    def render_node( file_path: str, node_id: str, show_ids: bool = False, show_markers: bool = True ) -> str: """Render text representation of the node (only descendent paragraphs) Args: file_path (str): Path to the HNPX document node_id (str): ID of the node to render show_ids (bool): Whether to show paragraph IDs in square brackets show_markers (bool): Whether to mark chapter/sequence beginnings Returns: str: Formatted text representation the node """ tree = hnpx.parse_document(file_path) node = hnpx.find_node(tree, node_id) if node is None: raise NodeNotFoundError(node_id) return _render_paragraphs_recursive(node, show_ids, show_markers).strip()
  • Registers the render_node tool with the FastMCP application using app.tool() decorator.
    app.tool()(tools.render_node)
  • Helper function that recursively traverses the node subtree to render paragraphs, adding chapter titles and sequence markers as specified.
    def _render_paragraphs_recursive( node: etree.Element, show_ids: bool, show_markers: bool, is_first_child: bool = False, ) -> str: """Recursively print all paragraphs""" result = "" if node.tag == "paragraph": node_id = node.get("id") rendered_text = (node.text or "").strip() if rendered_text: if show_ids: result += f"[{node_id}] {rendered_text}\n\n" else: result += rendered_text + "\n\n" else: if node.tag == "chapter": result += f"=== {node.get('title')} ===\n\n" elif node.tag == "sequence" and not is_first_child: result += "***\n\n" is_first_child = True for child in node: if child.tag != "summary": result += _render_paragraphs_recursive( child, show_ids, show_markers, is_first_child ) is_first_child = False return result

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