docx-removeContent
Remove specific content blocks from DOCX files by index using JSON schema. Simplify document editing and management with structured, programmatic content removal.
Instructions
Remove a block at index.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| index | Yes |
Implementation Reference
- src/index.ts:69-72 (registration)Tool registration including description and input schema"docx-removeContent": { description: "Remove a block at index.", inputSchema: { type: "object", required: ["id", "index"], properties: { id: { type: "string" }, index: { type: "integer", minimum: 0 } } } },
- src/index.ts:197-200 (handler)MCP tool call handler that validates input and delegates to DocRegistry.removeContentcase "docx-removeContent": { const { id, index } = parseArgs<{ id: string; index: number }>(args, tools["docx-removeContent"].inputSchema); const res = registry.removeContent(id, index); return ok({ id: res.id, updatedAt: res.updatedAt });
- src/docx-utils.ts:230-237 (handler)Core logic: removes the content block at the specified index from the document JSON and triggers document rebuild via updateJsonremoveContent(id: DocId, index: number) { 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, 1); return { ...json, content: arr } as DocxJSON; }); }
- src/docx-utils.ts:132-141 (helper)Helper method called by removeContent to apply JSON updates, validate, rebuild the docx Document object, and update timestampsupdateJson(id: DocId, updater: (json: DocxJSON) => DocxJSON): ManagedDoc { const cur = this.require(id); const next = updater(this.clone(cur.json)); this.assertValid(next); cur.json = next; // Note: doc rebuild will be async if images with paths are present this.rebuildDoc(cur); cur.updatedAt = new Date().toISOString(); return cur; }