Skip to main content
Glama

create_paragraph

Add paragraph elements to HNPX fiction documents with configurable narrative modes including narration, dialogue, and internal monologue.

Instructions

Create a new paragraph element

Args: file_path (str): Path to the HNPX document parent_id (str): ID of the parent beat element text (str): Paragraph text content mode (str): Narrative mode - one of: "narration" (default), "dialogue", "internal" char (Optional[str]): Character identifier (required when mode="dialogue")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
parent_idYes
textYes
modeNonarration
charNo

Implementation Reference

  • The handler function that implements the create_paragraph tool. It parses the HNPX document, validates the parent is a beat, generates a unique ID, creates a paragraph element with mode and optional char attributes, sets the text content, saves the document, and returns a confirmation message.
    def create_paragraph(
        file_path: str,
        parent_id: str,
        text: str,
        mode: str = "narration",
        char: Optional[str] = None,
    ) -> str:
        """Create a new paragraph element
    
        Args:
            file_path (str): Path to the HNPX document
            parent_id (str): ID of the parent beat element
            text (str): Paragraph text content
            mode (str): Narrative mode - one of: "narration" (default), "dialogue", "internal"
            char (Optional[str]): Character identifier (required when mode="dialogue")
        """
        tree = hnpx.parse_document(file_path)
    
        attributes = {"mode": mode}
        if char:
            attributes["char"] = char
        elif mode == "dialogue":
            raise MissingAttributeError("char")
    
        # Create the paragraph with text content
        parent = hnpx.find_node(tree, parent_id)
        if parent is None:
            raise NodeNotFoundError(parent_id)
    
        if parent.tag != "beat":
            raise InvalidParentError(parent.tag, "beat")
    
        existing_ids = hnpx.get_all_ids(tree)
        new_id = hnpx.generate_unique_id(existing_ids)
        attributes["id"] = new_id
    
        paragraph = etree.SubElement(parent, "paragraph", **attributes)
        paragraph.text = text
    
        hnpx.save_document(tree, file_path)
    
        return f"Created paragraph with id {new_id}"
  • Registers the create_paragraph function as an MCP tool using the fastmcp app.tool() decorator.
    app.tool()(tools.create_paragraph)
  • Imports the tools module containing the create_paragraph function.
    from . import 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