Skip to main content
Glama

create_chapter

Adds a chapter element to HNPX documents for structured fiction writing, specifying title, summary, and point-of-view character to organize narrative content.

Instructions

Create a new chapter element

Args: file_path (str): Path to the HNPX document parent_id (str): ID of the parent book element title (str): Chapter title summary (str): Chapter summary text pov (Optional[str]): Point-of-view character identifier

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
parent_idYes
titleYes
summaryYes
povNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function implementing the create_chapter tool. It parses the HNPX document, creates a new chapter element under the specified parent using helper, saves the document, and returns the new chapter ID.
    def create_chapter(
        file_path: str, parent_id: str, title: str, summary: str, pov: Optional[str] = None
    ) -> str:
        """Create a new chapter element
    
        Args:
            file_path (str): Path to the HNPX document
            parent_id (str): ID of the parent book element
            title (str): Chapter title
            summary (str): Chapter summary text
            pov (Optional[str]): Point-of-view character identifier
        """
        tree = hnpx.parse_document(file_path)
    
        attributes = {"title": title}
        if pov:
            attributes["pov"] = pov
    
        new_id = _create_element(tree, parent_id, "chapter", attributes, summary)
    
        hnpx.save_document(tree, file_path)
    
        return f"Created chapter with id {new_id}"
  • Registers the create_chapter handler as a tool in the FastMCP application.
    app.tool()(tools.create_chapter)
  • Shared helper function for creating new elements with hierarchy validation, unique ID generation, and summary subelement. Used by create_chapter and similar tools.
    def _create_element(
        tree: etree.ElementTree,
        parent_id: str,
        element_tag: str,
        attributes: dict,
        summary_text: str,
    ) -> str:
        """Generic element creation helper"""
        parent = hnpx.find_node(tree, parent_id)
        if parent is None:
            raise NodeNotFoundError(parent_id)
    
        # Check hierarchy
        valid_hierarchy = {
            "book": ["chapter"],
            "chapter": ["sequence"],
            "sequence": ["beat"],
            "beat": ["paragraph"],
        }
    
        if (
            parent.tag not in valid_hierarchy
            or element_tag not in valid_hierarchy[parent.tag]
        ):
            raise InvalidHierarchyError(parent.tag, element_tag)
    
        # Generate unique ID
        existing_ids = hnpx.get_all_ids(tree)
        new_id = hnpx.generate_unique_id(existing_ids)
        attributes["id"] = new_id
    
        # Create element
        element = etree.SubElement(parent, element_tag, **attributes)
        summary = etree.SubElement(element, "summary")
        summary.text = summary_text
    
        return new_id
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states 'Create' which implies a write/mutation operation, but doesn't address permissions, side effects, error handling, or what the output looks like. This is a significant gap for a mutation tool with zero annotation coverage.

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 well-structured and front-loaded with the core purpose, followed by a concise parameter list. Every sentence earns its place, with no redundant or verbose language, making it efficient and easy to parse.

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 that this is a mutation tool with no annotations, 5 parameters (4 required), and an output schema exists, the description is moderately complete. It covers parameter semantics well but lacks behavioral context and usage guidelines. The output schema mitigates the need to describe return values, but overall gaps remain.

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 provides clear semantics for all 5 parameters (e.g., 'Path to the HNPX document' for file_path, 'ID of the parent book element' for parent_id), adding meaningful context beyond the bare schema. However, it doesn't specify format constraints or examples, keeping it from a perfect score.

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 ('Create a new chapter element') and resource ('chapter'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'create_paragraph' or 'create_sequence' beyond the chapter focus, so it doesn't reach the highest level of sibling differentiation.

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 like 'create_paragraph' or 'create_sequence', nor does it mention prerequisites or context. It simply states what the tool does without indicating appropriate scenarios or exclusions.

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