docx-editContent
Replace content blocks in Word documents by specifying index and new content. Use with query and schema tools to identify blocks and understand structure.
Instructions
Replace a block at index. Use docx-queryObjects first to see available blocks, 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:212-219 (handler)Core implementation of docx-editContent tool: replaces the block at the given index in the document's content array and updates the JSON model, triggering document rebuild.editContent(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[index] = newBlock; return { ...json, content: arr } as DocxJSON; }); }
- src/index.ts:187-191 (handler)MCP server tool dispatch handler for 'docx-editContent': validates input using the tool schema and calls DocRegistry.editContent.case "docx-editContent": { const { id, index, block } = parseArgs<{ id: string; index: number; block: any }>(args, tools["docx-editContent"].inputSchema); const res = registry.editContent(id, index, block); return ok({ id: res.id, updatedAt: res.updatedAt }); }
- src/index.ts:61-64 (schema)Input schema for the docx-editContent tool, defining parameters id, index, and block (referencing Docx Block schema). Used for validation and tool listing."docx-editContent": { description: "Replace a block at index. Use docx-queryObjects first to see available blocks, 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/index.ts:101-103 (registration)Tool registration via ListToolsRequestHandler, which exposes all tools in the 'tools' object including docx-editContent.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: Object.entries(tools).map(([name, t]) => ({ name, description: t.description, inputSchema: t.inputSchema as any })) }));
- src/schema.ts:97-112 (schema)Definition of the Block schema ($defs.Block) 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" } ] },