Skip to main content
Glama

create_document

Generate a new Microsoft Word document with customizable metadata such as filename, title, and author. Ideal for managing and organizing documents efficiently.

Instructions

Create a new Word document with optional metadata.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
authorNo
filenameYes
titleNo

Implementation Reference

  • Core handler function that creates a new Word document (.docx) file using python-docx library. Handles filename extension, writability checks, sets document properties (title, author), ensures required styles (headings, tables), saves the file, and returns success/error message.
    async def create_document(filename: str, title: Optional[str] = None, author: Optional[str] = None) -> str:
        """Create a new Word document with optional metadata.
        
        Args:
            filename: Name of the document to create (with or without .docx extension)
            title: Optional title for the document metadata
            author: Optional author for the document metadata
        """
        filename = ensure_docx_extension(filename)
        
        # Check if file is writeable
        is_writeable, error_message = check_file_writeable(filename)
        if not is_writeable:
            return f"Cannot create document: {error_message}"
        
        try:
            doc = Document()
            
            # Set properties if provided
            if title:
                doc.core_properties.title = title
            if author:
                doc.core_properties.author = author
            
            # Ensure necessary styles exist
            ensure_heading_style(doc)
            ensure_table_style(doc)
            
            # Save the document
            doc.save(filename)
            
            return f"Document {filename} created successfully"
        except Exception as e:
            return f"Failed to create document: {str(e)}"
  • MCP tool registration using FastMCP @mcp.tool() decorator. Defines the tool entrypoint with input schema inferred from parameters, docstring, and delegates execution to the core handler in document_tools.create_document.
    @mcp.tool()
    async def create_document(filename: str, title: Optional[str] = None, author: Optional[str] = None):
        """Create a new Word document with optional metadata."""
        return await document_tools.create_document(filename, title, author)

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/franlealp1/mcp-word'

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