Skip to main content
Glama

reorder_children

Reorganize child elements in HNPX documents by specifying a new order for child IDs under a parent node to restructure narrative hierarchies.

Instructions

Reorganize the order of child elements

Args: file_path (str): Path to the HNPX document parent_id (str): ID of the parent node child_ids (list): List of child IDs in the desired order

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
parent_idYes
child_idsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'reorder_children' tool. It parses the HNPX XML document, locates the specified parent node, validates that the provided child_ids match all current non-summary children, reorders them by removing and re-appending in the new sequence, saves the updated document, and returns a confirmation message.
    def reorder_children(file_path: str, parent_id: str, child_ids: list) -> str:
        """Reorganize the order of child elements
    
        Args:
            file_path (str): Path to the HNPX document
            parent_id (str): ID of the parent node
            child_ids (list): List of child IDs in the desired order
        """
        tree = hnpx.parse_document(file_path)
        parent = hnpx.find_node(tree, parent_id)
    
        if parent is None:
            raise NodeNotFoundError(parent_id)
    
        # Get current children (excluding summary)
        current_children = [child for child in parent if child.tag != "summary"]
        current_ids = [child.get("id") for child in current_children]
    
        # Validate input
        if set(child_ids) != set(current_ids):
            raise InvalidOperationError(
                "reorder_children", "child_ids must contain all existing child IDs"
            )
    
        # Create mapping and reorder
        child_map = {child.get("id"): child for child in current_children}
    
        # Remove all children (except summary)
        for child in current_children:
            parent.remove(child)
    
        # Add back in new order
        for child_id in child_ids:
            parent.append(child_map[child_id])
    
        hnpx.save_document(tree, file_path)
    
        return f"Reordered children of node {parent_id}"
  • Registers the reorder_children function as an MCP tool using the FastMCP app.tool() decorator.
    app.tool()(tools.reorder_children)
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 implies a mutation ('reorganize') but doesn't disclose behavioral traits like whether changes are permanent, if it requires specific permissions, error conditions (e.g., invalid IDs), or side effects. The description lacks context on what 'reorganize' entails operationally beyond the basic action.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded with the core purpose in the first sentence. The 'Args' section is structured but could be more integrated; overall, it's efficient with minimal waste, though slightly fragmented between the summary and parameter list.

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 3 parameters with 0% schema coverage, no annotations, but an output schema exists, the description is moderately complete. It covers the basic action and parameters but lacks behavioral context, usage guidelines, and detailed parameter semantics. The output schema mitigates the need to explain return values, but gaps remain in mutation handling and tool selection.

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

Parameters3/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 adds meaning by explaining each parameter's purpose (e.g., 'parent_id' identifies the parent node, 'child_ids' is the desired order list), which clarifies beyond the bare schema types. However, it doesn't provide format details (e.g., ID formats, path syntax) or constraints, leaving gaps in parameter understanding.

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 ('reorganize') and resource ('child elements'), specifying it's about ordering. It distinguishes from siblings like 'move_nodes' (which likely moves nodes between parents) and 'remove_node_children' (which removes children). However, it doesn't explicitly mention the HNPX document context or contrast with all siblings like 'edit_node_attributes'.

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. It doesn't mention prerequisites (e.g., needing existing parent/children), exclusions (e.g., not for reordering across parents), or comparisons to siblings like 'move_nodes' for different reordering scenarios. The description only states what it does, not when to choose it.

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