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);
    }

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