Skip to main content
Glama

add_heading

Add structured headings to Word documents by specifying text and hierarchical level (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

  • Switch case in handleToolCall that executes the add_heading tool by calling documentManager.addHeading and returning a confirmation message.
    case "add_heading": documentManager.addHeading(args.docId, args.text, args.level); return { content: [ { type: "text", text: `Heading level ${args.level} added: "${args.text}"`, }, ], };
  • Tool definition including name, description, and input schema for validating arguments to add_heading.
    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"], },
  • src/index.ts:24-28 (registration)
    Registration of the documentTools array (which includes add_heading) for the MCP server's ListToolsRequestHandler.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: documentTools, }; });
  • Core implementation in DocumentManager that adds a heading paragraph to the document using docx library.
    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