Skip to main content
Glama

add_paragraph

Insert formatted text paragraphs into Microsoft Word documents programmatically, supporting bold, italic, underline, font customization, color, and alignment options.

Instructions

Add a paragraph of text to the document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
docIdYesDocument identifier
textYesParagraph text
formattingNoOptional formatting options

Implementation Reference

  • Switch case handler for the 'add_paragraph' tool. Extracts arguments and calls documentManager.addParagraph(), then returns a success message.
    case "add_paragraph": documentManager.addParagraph(args.docId, args.text, args.formatting); return { content: [ { type: "text", text: `Paragraph added successfully.`, }, ], };
  • Input schema defining the parameters for the add_paragraph tool: required docId and text, optional formatting object.
    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/index.ts:24-28 (registration)
    Registration of all tools including 'add_paragraph' via the documentTools array provided to the MCP server's ListToolsRequestHandler.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: documentTools, }; });
  • Core implementation of adding a formatted paragraph to the document using 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); }
  • Type definition for FormattingOptions used in add_paragraph tool schema and implementation.
    export interface FormattingOptions { bold?: boolean; italic?: boolean; underline?: boolean; fontSize?: number; font?: string; color?: string; alignment?: "left" | "center" | "right" | "justified"; highlight?: string; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bibash44/word-documet-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server