Skip to main content
Glama

add_heading

Add structured headings to Word documents at specified levels (1-5) to organize content and improve document navigation.

Instructions

Add a heading to the document at specified level (1-5)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
docIdYesDocument identifier
textYesHeading text
levelYesHeading level (1=Heading1, 2=Heading2, etc.)

Implementation Reference

  • Handler for the 'add_heading' tool call. Dispatches to documentManager.addHeading and returns a formatted success response.
    case "add_heading":
      documentManager.addHeading(args.docId, args.text, args.level);
      return {
        content: [
          {
            type: "text",
            text: `Heading level ${args.level} added: "${args.text}"`,
          },
        ],
      };
  • Input schema definition for the 'add_heading' tool, specifying parameters docId, text, and level with validation.
    {
      name: "add_heading",
      description: "Add a heading to the document at specified level (1-5)",
      inputSchema: {
        type: "object",
        properties: {
          docId: {
            type: "string",
            description: "Document identifier",
          },
          text: {
            type: "string",
            description: "Heading text",
          },
          level: {
            type: "number",
            description: "Heading level (1=Heading1, 2=Heading2, etc.)",
            minimum: 1,
            maximum: 5,
          },
        },
        required: ["docId", "text", "level"],
      },
    },
  • DocumentManager.addHeading method: core logic that maps level to docx HeadingLevel, creates Paragraph, and appends to document paragraphs.
    addHeading(docId: string, text: string, level: number): void {
      const docInfo = this.getDocument(docId);
      
      const headingLevels: { [key: number]: typeof HeadingLevel[keyof typeof HeadingLevel] } = {
        1: HeadingLevel.HEADING_1,
        2: HeadingLevel.HEADING_2,
        3: HeadingLevel.HEADING_3,
        4: HeadingLevel.HEADING_4,
        5: HeadingLevel.HEADING_5,
      };
    
      const heading = new Paragraph({
        text,
        heading: headingLevels[level] || HeadingLevel.HEADING_1,
      });
    
      docInfo.paragraphs.push(heading);
      this.updateDocument(docId);
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies a write operation ('Add') but doesn't disclose permissions needed, whether changes are immediate or require 'save_document', what happens on invalid input (e.g., duplicate headings), or error behavior. The level range constraint is already in the schema, so this adds little beyond basic intent.

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 a single, efficient sentence that front-loads the core action and key constraint (level range). There's zero wasted verbiage, and every word earns its place by specifying the tool's essential function.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't address what the tool returns (e.g., success confirmation, heading ID), error conditions, dependencies on other tools (like 'save_document'), or how it integrates with the document structure. Given the complexity of document editing and sibling tools, more context is needed for effective use.

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

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all three parameters (docId, text, level) with clear descriptions and constraints. The description adds no additional parameter semantics beyond what's in the schema, but doesn't need to compensate for gaps, meeting the baseline for high coverage.

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 ('Add a heading') and resource ('to the document') with specific scope ('at specified level (1-5)'), making the purpose immediately understandable. However, it doesn't explicitly distinguish this from sibling tools like 'add_paragraph' or 'apply_text_formatting' in terms of heading-specific functionality.

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 'add_paragraph' for regular text or 'get_document_structure' for viewing headings. There's no mention of prerequisites (e.g., document must exist), sequencing (e.g., use after 'create_document'), or contextual constraints.

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/bibash44/word-documet-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server