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")]

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