Skip to main content
Glama

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
NameRequiredDescriptionDefault
docIdYesDocument identifier
textYesParagraph text
formattingNoOptional formatting options

Implementation Reference

  • 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.`, }, ], };
  • 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"], }, },
  • 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); }

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