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
| Name | Required | Description | Default |
|---|---|---|---|
| docId | Yes | Document identifier | |
| text | Yes | Heading text | |
| level | Yes | Heading level (1=Heading1, 2=Heading2, etc.) |
Implementation Reference
- src/tools/tool-handlers.ts:18-27 (handler)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}"`, }, ], };
- src/tools/document-tools.ts:22-45 (schema)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); }