save_document
Save Microsoft Word documents to disk to preserve edits and formatting changes made during programmatic manipulation.
Instructions
Save the document to disk
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| docId | Yes | Document identifier |
Implementation Reference
- src/tools/tool-handlers.ts:89-98 (handler)MCP tool handler for 'save_document': calls documentManager.saveDocument(args.docId) and returns formatted success response with filepath.case "save_document": const filepath = await documentManager.saveDocument(args.docId); return { content: [ { type: "text", text: `Document saved successfully to: ${filepath}`, }, ], };
- src/tools/document-tools.ts:172-185 (schema)Tool schema definition for 'save_document', including inputSchema requiring 'docId'.{ name: "save_document", description: "Save the document to disk", inputSchema: { type: "object", properties: { docId: { type: "string", description: "Document identifier", }, }, required: ["docId"], }, },
- src/index.ts:24-28 (registration)Registers all tools including 'save_document' via documentTools export for ListToolsRequestHandler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: documentTools, }; });
- Core implementation of document saving logic: recreates Document from in-memory paragraphs, packs to buffer, writes to filepath.async saveDocument(docId: string): Promise<string> { const docInfo = this.getDocument(docId); // Recreate document with all paragraphs const document = new Document({ sections: [ { properties: {}, children: docInfo.paragraphs, }, ], }); const buffer = await Packer.toBuffer(document); await fs.writeFile(docInfo.filepath, buffer); return docInfo.filepath; }
- src/index.ts:31-47 (helper)General tool call handler registration that dispatches to specific handleToolCall based on tool name, including 'save_document'.server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const result = await handleToolCall(request.params.name, request.params.arguments); return result; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error: ${errorMessage}`, }, ], isError: true, }; } });