Skip to main content
Glama

add_paragraph

Insert formatted text paragraphs into Microsoft Word documents. Specify content, styles, fonts, and formatting options to customize document structure.

Instructions

Add a paragraph to a Word document with optional formatting.

Args: filename: Path to Word document text: Paragraph text content style: Optional paragraph style name font_name: Font family (e.g., 'Helvetica', 'Times New Roman') font_size: Font size in points (e.g., 14, 36) bold: Make text bold italic: Make text italic color: Text color as hex RGB (e.g., '000000')

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
textYes
styleNo
font_nameNo
font_sizeNo
boldNo
italicNo
colorNo

Implementation Reference

  • Registration of the 'add_paragraph' MCP tool using FastMCP @mcp.tool() decorator. Includes docstring that defines input schema. Delegates execution to content_tools.add_paragraph.
    @mcp.tool() def add_paragraph(filename: str, text: str, style: str = None, font_name: str = None, font_size: int = None, bold: bool = None, italic: bool = None, color: str = None): """Add a paragraph to a Word document with optional formatting. Args: filename: Path to Word document text: Paragraph text content style: Optional paragraph style name font_name: Font family (e.g., 'Helvetica', 'Times New Roman') font_size: Font size in points (e.g., 14, 36) bold: Make text bold italic: Make text italic color: Text color as hex RGB (e.g., '000000') """ return content_tools.add_paragraph(filename, text, style, font_name, font_size, bold, italic, color)
  • Core handler implementation for add_paragraph tool. Loads Word document using python-docx, adds new paragraph with given text, applies optional style and text formatting (font, size, bold, italic, color), handles errors like missing styles or file issues, and saves the document.
    async def add_paragraph(filename: str, text: str, style: Optional[str] = None, font_name: Optional[str] = None, font_size: Optional[int] = None, bold: Optional[bool] = None, italic: Optional[bool] = None, color: Optional[str] = None) -> str: """Add a paragraph to a Word document with optional formatting. Args: filename: Path to the Word document text: Paragraph text style: Optional paragraph style name font_name: Font family (e.g., 'Helvetica', 'Times New Roman') font_size: Font size in points (e.g., 14, 36) bold: True/False for bold text italic: True/False for italic text color: RGB color as hex string (e.g., '000000' for black) """ filename = ensure_docx_extension(filename) if not os.path.exists(filename): return f"Document {filename} does not exist" # Check if file is writeable is_writeable, error_message = check_file_writeable(filename) if not is_writeable: # Suggest creating a copy return f"Cannot modify document: {error_message}. Consider creating a copy first or creating a new document." try: doc = Document(filename) paragraph = doc.add_paragraph(text) if style: try: paragraph.style = style except KeyError: # Style doesn't exist, use normal and report it paragraph.style = doc.styles['Normal'] doc.save(filename) return f"Style '{style}' not found, paragraph added with default style to {filename}" # Apply formatting to all runs in the paragraph if any([font_name, font_size, bold is not None, italic is not None, color]): for run in paragraph.runs: if font_name: run.font.name = font_name if font_size: run.font.size = Pt(font_size) if bold is not None: run.font.bold = bold if italic is not None: run.font.italic = italic if color: # Remove any '#' prefix if present color_hex = color.lstrip('#') run.font.color.rgb = RGBColor.from_string(color_hex) doc.save(filename) return f"Paragraph added to {filename}" except Exception as e: return f"Failed to add paragraph: {str(e)}"
  • Input schema defined via detailed docstring in the registered tool function, describing parameters, types, and examples. Used by FastMCP for tool schema generation.
    """Add a paragraph to a Word document with optional formatting. Args: filename: Path to Word document text: Paragraph text content style: Optional paragraph style name font_name: Font family (e.g., 'Helvetica', 'Times New Roman') font_size: Font size in points (e.g., 14, 36) bold: Make text bold italic: Make text italic color: Text color as hex RGB (e.g., '000000') """

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/GongRzhe/Office-Word-MCP-Server'

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