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

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

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