Skip to main content
Glama

edit_node_attributes

Modify attributes of existing nodes in HNPX documents to update narrative elements during collaborative fiction writing.

Instructions

Modify attributes of an existing node

Args: file_path (str): Path to the HNPX document node_id (str): ID of the node to modify attributes (dict): Dictionary of attribute names and values to update

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
node_idYes
attributesYes

Implementation Reference

  • The main handler function implementing the logic to edit attributes of a specified node in the HNPX XML document, excluding the 'id' attribute.
    def edit_node_attributes(file_path: str, node_id: str, attributes: dict) -> str:
        """Modify attributes of an existing node
    
        Args:
            file_path (str): Path to the HNPX document
            node_id (str): ID of the node to modify
            attributes (dict): Dictionary of attribute names and values to update
        """
        tree = hnpx.parse_document(file_path)
        node = hnpx.find_node(tree, node_id)
    
        if node is None:
            raise NodeNotFoundError(node_id)
    
        # Update attributes
        for key, value in attributes.items():
            if key == "id":
                raise InvalidOperationError(
                    "edit_node_attributes", "Cannot modify id attribute"
                )
    
            if value is None or value == "":
                if key in node.attrib:
                    del node.attrib[key]
            else:
                node.set(key, value)
    
        hnpx.save_document(tree, file_path)
    
        return f"Updated attributes for node {node_id}"
  • Registers the edit_node_attributes tool with the FastMCP application.
    app.tool()(tools.edit_node_attributes)

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