add_paragraph
Insert formatted text paragraphs into Word documents programmatically with options for bold, italic, underline, font customization, and alignment.
Instructions
Add a paragraph of text to the document
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| docId | Yes | Document identifier | |
| text | Yes | Paragraph text | |
| formatting | No | Optional formatting options |
Implementation Reference
- src/tools/tool-handlers.ts:29-38 (handler)Handles the 'add_paragraph' tool invocation within the main tool handler switch statement by calling the document manager's addParagraph method and returning a success response.case "add_paragraph": documentManager.addParagraph(args.docId, args.text, args.formatting); return { content: [ { type: "text", text: `Paragraph added successfully.`, }, ], };
- src/tools/document-tools.ts:46-79 (schema)Defines the input schema and metadata for the 'add_paragraph' tool, including parameters for docId, text, and optional formatting.{ name: "add_paragraph", description: "Add a paragraph of text to the document", inputSchema: { type: "object", properties: { docId: { type: "string", description: "Document identifier", }, text: { type: "string", description: "Paragraph text", }, formatting: { type: "object", description: "Optional formatting options", properties: { bold: { type: "boolean" }, italic: { type: "boolean" }, underline: { type: "boolean" }, fontSize: { type: "number" }, font: { type: "string" }, color: { type: "string", description: "Hex color (e.g., FF0000 for red)" }, alignment: { type: "string", enum: ["left", "center", "right", "justified"], }, }, }, }, required: ["docId", "text"], }, },
- src/tools/document-tools.ts:46-79 (registration)Registers the 'add_paragraph' tool in the documentTools array, which is likely exported for use in MCP tool server setup.{ name: "add_paragraph", description: "Add a paragraph of text to the document", inputSchema: { type: "object", properties: { docId: { type: "string", description: "Document identifier", }, text: { type: "string", description: "Paragraph text", }, formatting: { type: "object", description: "Optional formatting options", properties: { bold: { type: "boolean" }, italic: { type: "boolean" }, underline: { type: "boolean" }, fontSize: { type: "number" }, font: { type: "string" }, color: { type: "string", description: "Hex color (e.g., FF0000 for red)" }, alignment: { type: "string", enum: ["left", "center", "right", "justified"], }, }, }, }, required: ["docId", "text"], }, },
- Implements the core logic for adding a paragraph with optional formatting to the document using the docx library, called by the tool handler.addParagraph(docId: string, text: string, formatting?: FormattingOptions): void { const docInfo = this.getDocument(docId); const textRunOptions: any = { text }; if (formatting?.bold !== undefined) textRunOptions.bold = formatting.bold; if (formatting?.italic !== undefined) textRunOptions.italics = formatting.italic; if (formatting?.underline) textRunOptions.underline = {}; if (formatting?.fontSize !== undefined) textRunOptions.size = formatting.fontSize * 2; // Half-points if (formatting?.font !== undefined) textRunOptions.font = formatting.font; if (formatting?.color !== undefined) textRunOptions.color = formatting.color; const textRun = new TextRun(textRunOptions); const paragraphOptions: any = { children: [textRun], }; const alignment = this.getAlignment(formatting?.alignment); if (alignment !== undefined) { paragraphOptions.alignment = alignment; } const paragraph = new Paragraph(paragraphOptions); docInfo.paragraphs.push(paragraph); this.updateDocument(docId); }