Skip to main content
Glama

move_nodes

Relocate multiple nodes to a new parent within HNPX documents to restructure hierarchical fiction writing content.

Instructions

Move multiple nodes between parents

Args: file_path (str): Path to the HNPX document node_ids (list): List of node IDs to move new_parent_id (str): ID of the new parent node

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
node_idsYes
new_parent_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function that implements the logic for moving multiple nodes to a new parent in the HNPX document tree, including hierarchy validation, error checking, and XML manipulation using lxml.
    def move_nodes(file_path: str, node_ids: list, new_parent_id: str) -> str:
        """Move multiple nodes between parents
    
        Args:
            file_path (str): Path to the HNPX document
            node_ids (list): List of node IDs to move
            new_parent_id (str): ID of the new parent node
        """
        tree = hnpx.parse_document(file_path)
        new_parent = hnpx.find_node(tree, new_parent_id)
    
        if new_parent is None:
            raise NodeNotFoundError(new_parent_id)
    
        # Check hierarchy validity for new parent
        valid_hierarchy = {
            "book": ["chapter"],
            "chapter": ["sequence"],
            "sequence": ["beat"],
            "beat": ["paragraph"],
            "paragraph": [],
        }
    
        nodes_moved = 0
        for node_id in node_ids:
            node = hnpx.find_node(tree, node_id)
            if node is None:
                raise NodeNotFoundError(node_id)
    
            # Check if trying to move root
            if node.tag == "book":
                raise InvalidOperationError("move_nodes", "Cannot move book element")
    
            # Check hierarchy validity
            if node.tag not in valid_hierarchy[new_parent.tag]:
                raise InvalidHierarchyError(new_parent.tag, node.tag)
    
            old_parent = node.getparent()
            old_parent.remove(node)
            new_parent.append(node)
            nodes_moved += 1
    
        hnpx.save_document(tree, file_path)
    
        return f"Moved {nodes_moved} nodes to parent {new_parent_id}"
  • Registers the move_nodes handler as an MCP tool using FastMCP's app.tool() decorator.
    app.tool()(tools.move_nodes)
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. While 'move' implies mutation, it doesn't disclose critical behavioral traits: whether this operation requires specific permissions, what happens to node positions in the new parent, whether the move is atomic or can fail partially, or how it affects references to moved nodes. The description is minimal and lacks necessary context for safe use.

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

Conciseness3/5

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

The description is brief and front-loaded with the core purpose, but the parameter explanations are minimal and don't add significant value. While not verbose, the under-specification means it could be more informative without losing conciseness. The structure is clear but could be improved with more substantive content.

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

Completeness2/5

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

Given the complexity of a mutation tool with 3 parameters, 0% schema description coverage, no annotations, and sibling tools that suggest a rich node-manipulation context, the description is incomplete. It doesn't address prerequisites, error conditions, or the impact of the operation. The presence of an output schema helps, but the description should provide more context for safe and effective use.

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

Parameters2/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 lists the three parameters with brief explanations, but these add minimal semantic value beyond the schema's names. For example, it doesn't explain what format 'node_ids' expects (e.g., strings, integers), what 'new_parent_id' represents, or how 'file_path' relates to the HNPX document structure. The description fails to adequately compensate for the lack of schema descriptions.

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 action ('move multiple nodes') and the resource ('between parents'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'reorder_children' or 'remove_nodes', which might involve similar node manipulation operations.

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?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'reorder_children' (which might change order within a parent) and 'remove_nodes' (which might delete nodes), there's no indication of when moving nodes between parents is the appropriate choice versus other operations.

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