Skip to main content
Glama

write_docx

Create or overwrite Microsoft Word documents with plain text content. Specify file path and text to generate DOCX files.

Instructions

Create or overwrite a document with plain text content.

Args: filepath: Path to the document content: Text content to write

Returns: Dictionary with status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYes
contentYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The 'write_docx' handler, decorated with @app.tool(), which creates or overwrites a Word document with provided text content.
    @app.tool()
    def write_docx(filepath: str, content: str) -> dict[str, Any]:
        """
        Create or overwrite a document with plain text content.
    
        Args:
            filepath: Path to the document
            content: Text content to write
    
        Returns:
            Dictionary with status
        """
        logger.info("Writing to document", extra={"tool": "write_docx", "filepath": filepath})
    
        try:
            path = normalize_path(filepath)
            path.parent.mkdir(parents=True, exist_ok=True)
    
            doc = Document()
            for paragraph_text in content.split("\n"):
                if paragraph_text.strip():
                    doc.add_paragraph(paragraph_text)
    
            doc.save(str(path))
            logger.info("Document written successfully", extra={"filepath": filepath})
    
            return {
                "status": "success",
                "filepath": str(path),
                "message": f"Document written: {path.name}",
            }
        except DocxMcpError as e:
            logger.warning(e.message, extra={"tool": "write_docx", "error_code": e.error_code})
            return {"status": "error", "error": e.message, "error_code": e.error_code}
        except Exception as e:
            logger.error(f"Unexpected error writing document: {str(e)}")
            return {"status": "error", "error": str(e)}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'create or overwrite' which implies mutation, but doesn't disclose critical behavioral traits: whether overwriting is destructive (replaces entire file), what permissions are needed, error handling for invalid paths, or file format specifics. The return value is minimally described as 'Dictionary with status' without detailing success/failure indicators.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with three clear sections: purpose statement, args, and returns. Each sentence earns its place, and information is front-loaded with the core functionality first. Minor improvement could be integrating the args/returns more seamlessly, but structure is efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 2 parameters with 0% schema coverage and no annotations, the description provides basic purpose and parameter meanings. An output schema exists (implied by 'Has output schema: true'), so describing return values isn't required. However, for a mutation tool that can overwrite files, more behavioral context (e.g., overwrite implications, error conditions) would enhance completeness, leaving it adequate but with gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the schema provides no parameter documentation. The description adds basic semantics: 'filepath: Path to the document' and 'content: Text content to write', explaining what each parameter represents. However, it doesn't provide format details (e.g., path syntax, content encoding) or constraints (e.g., filepath must exist for overwrite), leaving gaps despite compensating somewhat for the schema's lack.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Create or overwrite a document with plain text content.' It specifies the verb ('create or overwrite'), resource ('document'), and content type ('plain text'). However, it doesn't explicitly differentiate from siblings like 'create_docx' or 'append_docx', which would require more specific comparison.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'create_docx' and 'append_docx' available, there's no indication of when this write/overwrite operation is preferred over creation or appending, nor any mention of prerequisites or constraints.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Andrew82106/LLM_Docx_Agent_MCP'

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