Skip to main content
Glama

write_docx

Create new Microsoft Word documents with structured content including paragraphs and tables. Specify file path and content to generate docx files for documentation or reports.

Instructions

Create a new docx file with given content.Editing exisiting docx file with this tool is not recomended.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to target file. It should be under your current working directory.
contentYesContent to write to the file. Two line breaks in content represent new paragraph.Table should starts with [Table], and separated with '|'.Escape line break when you input multiple lines.

Implementation Reference

  • The main handler function that implements the write_docx tool logic by creating a new Document, parsing content into paragraphs and tables, and saving to the specified path.
    async def write_docx(path: str, content: str) -> None:
        """Create a new docx file with the given content.
        
        Args:
            path: target path to create docx file
            content: text content to write
        """
        document = Document()
        
        # Split content into sections
        sections = content.split("\n\n")
        
        for section in sections:
            if section.startswith("[Table]"):
                table = create_table_from_text(section[7:].strip()) # Remove [Table] prefix
                document.element.body.append(table._element)
            elif section.startswith("[Image]"):
                document.add_paragraph("[Image placeholder]")
            else:
                document.add_paragraph(section)
        
        document.save(path)
  • The input schema and metadata definition for the write_docx tool, including parameters for path and content.
    WRITE_DOCX = types.Tool(
        name="write_docx",
        description=(
            "Create a new docx file with given content."
            "Editing exisiting docx file with this tool is not recomended."
        ),
        inputSchema={
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "Absolute path to target file. It should be under your current working directory.",
                },
                "content": {
                    "type": "string",
                    "description": (
                        "Content to write to the file. Two line breaks in content represent new paragraph."
                        "Table should starts with [Table], and separated with '|'."
                        "Escape line break when you input multiple lines."
                    ),
                }
            },
            "required": ["path", "content"]
        }
    )
  • The server endpoint that registers and lists available tools, including WRITE_DOCX.
    @server.list_tools()
    async def list_tools() -> list[types.Tool]:
        return [READ_DOCX, EDIT_DOCX_PARAGRAPH, WRITE_DOCX, EDIT_DOCX_INSERT]
  • The tool dispatcher in call_tool that handles invocation of write_docx.
    elif name == "write_docx":
        await write_docx(arguments["path"], arguments["content"])
        return [types.TextContent(type="text", text="Document created successfully")]
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It correctly identifies this as a creation/write operation and warns against using it for editing, but doesn't mention important behavioral aspects like file overwriting behavior, permissions required, error conditions, or what happens if the path doesn't exist. The description adds some value but leaves significant gaps.

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 two sentences that each serve a clear purpose: the first states the core functionality, the second provides important usage guidance. There's no wasted verbiage, though the typo ('exisiting') slightly detracts from professionalism.

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?

For a file creation tool with no annotations and no output schema, the description provides basic purpose and usage guidance but lacks important context about what the tool returns, error handling, file system implications, or creation confirmation. The schema covers parameters well, but the overall tool behavior remains under-specified.

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?

With 100% schema description coverage, the schema already documents both parameters thoroughly. The description doesn't add any meaningful parameter semantics beyond what's in the schema - it mentions 'given content' but doesn't elaborate on the content parameter's formatting requirements beyond what the schema already specifies about tables and line breaks.

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

Purpose5/5

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

The description clearly states the specific action ('Create a new docx file') and resource ('with given content'), and explicitly distinguishes it from sibling tools by noting that editing existing files is not recommended. This provides clear differentiation from edit_docx_insert, edit_docx_paragraph, and read_docx.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when NOT to use this tool ('Editing existing docx file with this tool is not recommended'), which clearly distinguishes it from the edit_* sibling tools. This gives the agent clear direction about appropriate use cases versus alternatives.

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/famano/mcp-server-office'

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