docx-save
Save DOCX files to a specified disk path using their unique ID. Enables document management by persisting changes and ensuring files are stored efficiently.
Instructions
Persist the docx to disk path by id.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| path | Yes |
Implementation Reference
- src/index.ts:202-208 (handler)Main execution logic for the 'docx-save' tool: parses input arguments, retrieves the DOCX buffer from the registry, ensures the output directory exists, writes the file, and returns success info.case "docx-save": { const { id, path: outPath } = parseArgs<{ id: string; path: string }>(args, tools["docx-save"].inputSchema); const buf = await registry.packToBuffer(id); const dir = path.dirname(outPath); await mkdir(dir, { recursive: true }); await writeFile(outPath, buf); return ok({ id, path: outPath, bytes: buf.byteLength });
- src/index.ts:73-75 (schema)Input schema definition for the 'docx-save' tool, specifying required 'id' and 'path' parameters."docx-save": { description: "Persist the docx to disk path by id.", inputSchema: { type: "object", required: ["id", "path"], properties: { id: { type: "string" }, path: { type: "string" } } }
- src/docx-utils.ts:180-182 (helper)Helper method in DocRegistry that converts the in-memory Document object to a Uint8Array buffer using docx Packer, used by the docx-save handler.} async packToBuffer(id: DocId): Promise<Uint8Array> { const cur = this.require(id); return await Packer.toBuffer(cur.doc);
- src/index.ts:24-29 (helper)Utility function to validate and parse tool arguments against the schema, used in all tool handlers including docx-save.function parseArgs<T>(args: unknown, schema: any): T { const validate = ajv.compile(schema); if (!validate(args)) { throw new McpError(ErrorCode.InvalidParams, ajv.errorsText(validate.errors)); } return args as T;