docx-editContent
Modify specific content blocks in Word documents by index using JSON schema. Identify blocks with docx-queryObjects and understand structure via docx-getSchema for precise edits.
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 |
|---|---|---|---|
| block | Yes | ||
| id | Yes | ||
| index | Yes |
Implementation Reference
- src/docx-utils.ts:212-219 (handler)Core implementation of docx-editContent: replaces the content block at the specified index in the document's JSON content array, validates the update, rebuilds the docx Document object.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 tool call handler: parses arguments using the tool's inputSchema and delegates to 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 definition for the docx-editContent tool, including parameters id, index, and block (referencing DocxSchema $defs/Block)."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/schema.ts:97-112 (schema)DocxSchema.$defs.Block: the JSON schema for content blocks used in the tool's '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" } ] },
- src/index.ts:101-103 (registration)MCP server registration for listing tools, which exposes docx-editContent via the 'tools' object.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: Object.entries(tools).map(([name, t]) => ({ name, description: t.description, inputSchema: t.inputSchema as any })) }));