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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions the tool renders 'only descendent paragraphs' and describes output formatting options, but lacks critical behavioral details: whether it requires file access permissions, if it modifies the document, error handling, or performance characteristics. For a tool with 4 parameters and no annotations, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured: a clear purpose statement, followed by labeled sections for Args and Returns. Every sentence adds value—no redundancy or fluff. The formatting makes it easy to scan and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 4 parameters with 0% schema coverage and no annotations, the description does well on parameters but lacks behavioral context. The output schema exists (returns 'str'), so describing return values isn't needed. However, for a tool interacting with document files and nodes, more on permissions, side effects, or error cases would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains all 4 parameters: 'file_path' and 'node_id' as required inputs, and clarifies 'show_ids' and 'show_markers' as boolean flags controlling output formatting. This adds meaningful context beyond the bare schema types, though it doesn't detail path formats or ID structures.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Render') and resource ('text representation of the node'), specifying it only includes 'descendent paragraphs'. It distinguishes from siblings like 'get_node' or 'get_subtree' by focusing on formatted text output rather than raw data. However, it doesn't explicitly contrast with all similar siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like 'get_subtree' or 'get_node' is provided. The description implies it's for formatted text output but doesn't specify scenarios where this is preferable over other retrieval tools. No prerequisites or exclusions are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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