Skip to main content
Glama
zeph-gh

DOCX MCP Server

by zeph-gh

convert_to_html

Convert DOCX documents to HTML while preserving original formatting and styles for web-friendly content creation.

Instructions

Convert DOCX file to HTML with formatting preserved

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the .docx file
include_stylesNoInclude inline styles (default: true)

Implementation Reference

  • Handler function that processes the DOCX file conversion to HTML using mammoth library. Resolves file path, handles options for styles, performs conversion, extracts warnings/errors, and returns structured JSON response or error.
    async ({ file_path, include_styles = true }) => {
      try {
        const absolutePath = path.resolve(file_path)
    
        if (!fs.existsSync(absolutePath)) {
          throw new Error(`File not found: ${absolutePath}`)
        }
    
        const options = include_styles
          ? {}
          : {
              styleMap: [
                "p[style-name='Heading 1'] => h1:fresh",
                "p[style-name='Heading 2'] => h2:fresh",
                "p[style-name='Heading 3'] => h3:fresh",
                "r[style-name='Strong'] => strong",
                "r[style-name='Emphasis'] => em",
              ],
            }
    
        const result = await mammoth.convertToHtml(
          { path: absolutePath },
          options
        )
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  html: result.value,
                  messages: result.messages,
                  warnings: result.messages.filter(
                    (m: any) => m.type === 'warning'
                  ),
                  errors: result.messages.filter((m: any) => m.type === 'error'),
                },
                null,
                2
              ),
            },
          ],
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error converting to HTML: ${(error as Error).message}`,
            },
          ],
          isError: true,
        }
      }
    }
  • Zod input schema defining parameters: required file_path (string) and optional include_styles (boolean).
    {
      file_path: z.string().describe('Path to the .docx file'),
      include_styles: z
        .boolean()
        .optional()
        .describe('Include inline styles (default: true)'),
    },
  • src/index.ts:68-134 (registration)
    MCP server.tool registration call that defines the tool name, description, input schema, and references the handler function.
    server.tool(
      'convert_to_html',
      'Convert DOCX file to HTML with formatting preserved',
      {
        file_path: z.string().describe('Path to the .docx file'),
        include_styles: z
          .boolean()
          .optional()
          .describe('Include inline styles (default: true)'),
      },
      async ({ file_path, include_styles = true }) => {
        try {
          const absolutePath = path.resolve(file_path)
    
          if (!fs.existsSync(absolutePath)) {
            throw new Error(`File not found: ${absolutePath}`)
          }
    
          const options = include_styles
            ? {}
            : {
                styleMap: [
                  "p[style-name='Heading 1'] => h1:fresh",
                  "p[style-name='Heading 2'] => h2:fresh",
                  "p[style-name='Heading 3'] => h3:fresh",
                  "r[style-name='Strong'] => strong",
                  "r[style-name='Emphasis'] => em",
                ],
              }
    
          const result = await mammoth.convertToHtml(
            { path: absolutePath },
            options
          )
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(
                  {
                    html: result.value,
                    messages: result.messages,
                    warnings: result.messages.filter(
                      (m: any) => m.type === 'warning'
                    ),
                    errors: result.messages.filter((m: any) => m.type === 'error'),
                  },
                  null,
                  2
                ),
              },
            ],
          }
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `Error converting to HTML: ${(error as Error).message}`,
              },
            ],
            isError: true,
          }
        }
      }
    )
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions 'with formatting preserved', which adds some behavioral context about output quality, but does not disclose other traits such as error handling, file size limits, performance characteristics, or what happens if the file is invalid. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose ('Convert DOCX file to HTML') and adds a key detail ('with formatting preserved') without any wasted words. It is appropriately sized for the tool's complexity and easy to parse.

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 the tool has no annotations and no output schema, the description provides basic purpose but lacks details on behavior, error cases, or output format. It is minimally viable for understanding what the tool does, but does not compensate for the missing structured data, leaving gaps in completeness for a conversion tool with potential complexities.

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 100%, so the schema already documents both parameters ('file_path' and 'include_styles') with descriptions. The description does not add any meaning beyond what the schema provides (e.g., it doesn't explain the implications of 'include_styles' or provide examples). Baseline 3 is appropriate as the schema does the heavy lifting.

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 ('Convert DOCX file to HTML') and the resource ('DOCX file'), with the additional detail 'with formatting preserved' that distinguishes it from sibling tools like 'convert_to_markdown' or 'extract_text' which likely handle different formats or outputs. It uses precise verbs and specifies the input format and output format explicitly.

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

Usage Guidelines3/5

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

The description implies usage for converting DOCX files to HTML, but does not explicitly state when to use this tool versus alternatives like 'convert_to_markdown' or 'extract_text'. It provides basic context (format conversion with formatting) but lacks guidance on exclusions or specific scenarios where this tool is preferred over others.

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/zeph-gh/Docx-Mcp-Server'

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