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
| 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)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}"`, }, ], };
- src/tools/document-tools.ts:23-44 (schema)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); }