Skip to main content
Glama
Orchardxyz

Mammoth MCP Server

by Orchardxyz

convert_docx_to_html

Convert Microsoft Word DOCX files to clean HTML while preserving formatting, tables, and lists. This tool transforms document content for web use.

Instructions

Convert a DOCX file to HTML using mammoth. Supports reading from a file path and returns the HTML content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the DOCX file to convert

Implementation Reference

  • The handler function that implements the core logic of the 'convert_docx_to_html' tool. It reads the DOCX file using mammoth, converts it to HTML, formats the output with markdown including the HTML code block and any messages, and handles errors.
    async ({ filePath }) => {
      try {
        const absolutePath = path.resolve(filePath);
        await fs.access(absolutePath);
    
        const result = await mammoth.convertToHtml({ path: absolutePath });
    
        let output = `# Conversion Result\n\n`;
        output += `**File**: ${absolutePath}\n\n`;
        output += `## HTML Output:\n\n\`\`\`html\n${result.value}\n\`\`\`\n\n`;
    
        if (result.messages.length > 0) {
          output += `## Messages:\n\n`;
          result.messages.forEach((msg: any) => {
            output += `- ${msg.type}: ${msg.message}\n`;
          });
        }
    
        return {
          content: [
            {
              type: 'text',
              text: output,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error converting DOCX file: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.ts:15-62 (registration)
    The registration of the 'convert_docx_to_html' tool on the MCP server, specifying the tool name, description, input schema, and handler function.
    server.registerTool(
      'convert_docx_to_html',
      {
        description:
          'Convert a DOCX file to HTML using mammoth. Supports reading from a file path and returns the HTML content.',
        inputSchema: {
          filePath: z.string().describe('Absolute path to the DOCX file to convert'),
        },
      },
      async ({ filePath }) => {
        try {
          const absolutePath = path.resolve(filePath);
          await fs.access(absolutePath);
    
          const result = await mammoth.convertToHtml({ path: absolutePath });
    
          let output = `# Conversion Result\n\n`;
          output += `**File**: ${absolutePath}\n\n`;
          output += `## HTML Output:\n\n\`\`\`html\n${result.value}\n\`\`\`\n\n`;
    
          if (result.messages.length > 0) {
            output += `## Messages:\n\n`;
            result.messages.forEach((msg: any) => {
              output += `- ${msg.type}: ${msg.message}\n`;
            });
          }
    
          return {
            content: [
              {
                type: 'text',
                text: output,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `Error converting DOCX file: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • The input schema for the tool, defining 'filePath' as a required string using Zod validation.
    inputSchema: {
      filePath: z.string().describe('Absolute path to the DOCX file to convert'),
    },
Behavior2/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 states the tool 'returns the HTML content', which gives basic output information, but lacks details on error handling, performance traits (e.g., speed, memory usage), or constraints like file size limits. For a conversion tool, this leaves gaps in understanding its operational behavior and reliability.

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 concise and front-loaded, stating the core functionality in the first sentence. Both sentences earn their place by covering conversion purpose and input method. However, it could be slightly more structured by explicitly separating input and output details, but overall, it avoids unnecessary verbosity.

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's moderate complexity (file conversion), no annotations, and no output schema, the description is adequate but incomplete. It covers the basic what and how but misses key contextual elements like error cases, output format details beyond 'HTML content', or integration with the sibling tool. For a standalone tool, it meets minimum viability but lacks depth for robust agent use.

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?

The input schema has 100% description coverage, with 'filePath' clearly documented as an absolute path. The description adds minimal value beyond this, only reiterating 'reading from a file path' without providing additional context like supported file formats beyond DOCX or path validation rules. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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: converting DOCX files to HTML using mammoth. It specifies the verb ('convert'), resource ('DOCX file'), and technology ('using mammoth'), making it specific and actionable. However, it doesn't explicitly differentiate from its sibling tool 'convert_docx_to_html_with_images', which likely handles images differently, so it doesn't reach the highest score.

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. It mentions 'supports reading from a file path', which hints at input method, but doesn't clarify scenarios where this tool is preferred over its sibling or other conversion methods. There's no mention of prerequisites, limitations, or comparative contexts, leaving usage decisions ambiguous.

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/Orchardxyz/mammoth-mcp'

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