save_document
Save Microsoft Word documents to disk for persistent storage and future access. This tool stores documents with their formatting, tables, and content intact.
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)The handler function for the 'save_document' tool. It calls documentManager.saveDocument with the provided docId and returns a success message with the saved 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)Input schema definition for the 'save_document' tool, specifying that it requires a 'docId' string parameter.{ 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 the list of available tools (from documentTools array, which includes 'save_document') with the MCP server for the ListToolsRequest.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: documentTools, }; });
- Core implementation of saving the document: reconstructs the DOCX from in-memory paragraphs using docx library, writes buffer to file, returns 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; }