create_document
Create a new Microsoft Word document with optional title and save it to a specified file path. This tool enables AI assistants to generate Word documents programmatically.
Instructions
Create a new Word document with optional title
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | Full path where document will be saved (e.g., /path/to/document.docx) | |
| title | No | Optional title for the document |
Implementation Reference
- src/tools/tool-handlers.ts:7-16 (handler)The MCP tool handler case for 'create_document': invokes DocumentManager.createDocument with filepath and title, returns the generated document ID in the response content.case "create_document": const docId = documentManager.createDocument(args.filepath, args.title); return { content: [ { type: "text", text: `Document created successfully with ID: ${docId}. Use this ID for all future operations on this document.`, }, ], };
- src/tools/document-tools.ts:5-21 (schema)Input schema definition for the 'create_document' tool, specifying filepath (required) and optional title.name: "create_document", description: "Create a new Word document with optional title", inputSchema: { type: "object", properties: { filepath: { type: "string", description: "Full path where document will be saved (e.g., /path/to/document.docx)", }, title: { type: "string", description: "Optional title for the document", }, }, required: ["filepath"], }, },
- src/index.ts:24-28 (registration)MCP server registration of tools list via ListToolsRequestHandler, which includes the 'create_document' tool schema from documentTools.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: documentTools, }; });
- Core helper function in DocumentManager class that creates an in-memory docx Document object, optionally adds title heading, stores it with generated ID, and returns the ID.createDocument(filepath: string, title?: string): string { const docId = `doc_${++this.idCounter}_${Date.now()}`; const sections: any[] = []; const paragraphs: Paragraph[] = []; if (title) { const titlePara = new Paragraph({ text: title, heading: HeadingLevel.TITLE, }); paragraphs.push(titlePara); } const document = new Document({ sections: [ { properties: {}, children: paragraphs, }, ], }); this.documents.set(docId, { id: docId, filepath, document, paragraphs, created: new Date(), }); return docId; }