docx-insertContent
Insert content blocks into Word documents at specific positions to modify structure and add formatted text, tables, images, or lists.
Instructions
Insert a block at index. Use docx-queryObjects first to see current structure, and docx-getSchema to understand block structure.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| index | Yes | ||
| block | Yes |
Implementation Reference
- src/docx-utils.ts:221-227 (handler)Core handler function in DocRegistry that inserts a new block into the document's content array at the specified index by updating the JSON model and triggering a document rebuild.insertContent(id: DocId, index: number, newBlock: any) { return this.updateJson(id, (json) => { const arr = [...json.content]; if (index < 0 || index > arr.length) throw new Error("index out of range"); arr.splice(index, 0, newBlock); return { ...json, content: arr } as DocxJSON; });
- src/index.ts:192-195 (handler)MCP server handler that parses arguments using the tool schema and delegates to DocRegistry.insertContent.case "docx-insertContent": { const { id, index, block } = parseArgs<{ id: string; index: number; block: any }>(args, tools["docx-insertContent"].inputSchema); const res = registry.insertContent(id, index, block); return ok({ id: res.id, updatedAt: res.updatedAt });
- src/index.ts:65-67 (registration)Tool registration entry defining the name, description, and input schema for listTools response."docx-insertContent": { description: "Insert a block at index. Use docx-queryObjects first to see current structure, and docx-getSchema to understand block structure.", inputSchema: { type: "object", required: ["id", "index", "block"], properties: { id: { type: "string" }, index: { type: "integer", minimum: 0 }, block: { $ref: "docx:/$defs/Block" } } }
- src/schema.ts:97-112 (schema)JSON Schema definition for Block type, referenced by the tool's inputSchema for the 'block' parameter.Block: { type: "object", oneOf: [ { $ref: "#/$defs/Paragraph" }, { $ref: "#/$defs/Table" }, { $ref: "#/$defs/Image" }, { $ref: "#/$defs/Heading" }, { $ref: "#/$defs/CodeBlock" }, { $ref: "#/$defs/List" }, { $ref: "#/$defs/PageBreak" }, { $ref: "#/$defs/HorizontalRule" }, { $ref: "#/$defs/Blockquote" }, { $ref: "#/$defs/InfoBox" }, { $ref: "#/$defs/TextBox" } ] },