create_document
Create new Microsoft Word documents with custom titles and save them to specified file paths for document management and content creation.
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/document-tools.ts:4-21 (schema)Tool schema definition including inputSchema for create_document with 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/tools/tool-handlers.ts:7-16 (handler)Handler case in handleToolCall function that invokes documentManager.createDocument and returns success message with docId.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/services/document-manager.ts:25-57 (handler)Core implementation of createDocument in DocumentManager class: generates docId, creates empty docx Document with optional title heading, stores in memory map.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; }
- src/index.ts:24-28 (registration)MCP server registration of tools list handler returning the documentTools array containing create_document.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: documentTools, }; });
- src/index.ts:31-47 (registration)MCP server registration of tool call handler dispatching to handleToolCall based on tool name.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, }; } });