Skip to main content
Glama
Orchardxyz

Mammoth MCP Server

by Orchardxyz

convert_docx_to_html_with_images

Convert DOCX files to HTML with images embedded as base64 data URIs for web display or content migration.

Instructions

Convert a DOCX file to HTML with embedded images as base64 data URIs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the DOCX file to convert

Implementation Reference

  • The main handler function for the 'convert_docx_to_html_with_images' tool. It resolves the file path, converts the DOCX to HTML using mammoth with custom image conversion to base64 data URIs, formats the output with markdown, and handles errors.
    async ({ filePath }) => {
      try {
        const absolutePath = path.resolve(filePath);
        await fs.access(absolutePath);
    
        const result = await mammoth.convertToHtml(
          { path: absolutePath },
          {
            convertImage: mammoth.images.imgElement(async (image: any) => {
              const buffer = await image.read();
              const base64 = buffer.toString('base64');
              const contentType = image.contentType || 'image/png';
              return {
                src: `data:${contentType};base64,${base64}`,
              };
            }),
          }
        );
    
        let output = `# Conversion Result (with images)\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 and description for the tool, defining the 'filePath' parameter using Zod.
    {
      description: 'Convert a DOCX file to HTML with embedded images as base64 data URIs',
      inputSchema: {
        filePath: z.string().describe('Absolute path to the DOCX file to convert'),
      },
  • src/index.ts:64-122 (registration)
    The registration of the 'convert_docx_to_html_with_images' tool using server.registerTool, including schema and inline handler.
    server.registerTool(
      'convert_docx_to_html_with_images',
      {
        description: 'Convert a DOCX file to HTML with embedded images as base64 data URIs',
        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 },
            {
              convertImage: mammoth.images.imgElement(async (image: any) => {
                const buffer = await image.read();
                const base64 = buffer.toString('base64');
                const contentType = image.contentType || 'image/png';
                return {
                  src: `data:${contentType};base64,${base64}`,
                };
              }),
            }
          );
    
          let output = `# Conversion Result (with images)\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,
          };
        }
      }
    );
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. While it describes the core transformation behavior, it lacks critical details like error handling, performance characteristics, file size limitations, or what happens with unsupported DOCX features. For a file conversion tool with zero annotation coverage, this is insufficient.

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 conveys the complete purpose without any wasted words. It's appropriately sized for a single-parameter tool and front-loads the key information.

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 single-parameter tool with 100% schema coverage but no annotations and no output schema, the description adequately covers the basic transformation purpose. However, it lacks information about the output format details, error conditions, or limitations that would be important for practical usage.

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 fully documents the single parameter 'filePath'. The description doesn't add any parameter-specific information beyond what the schema provides, such as file format requirements or path validation rules.

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'), resource ('DOCX file'), and output format ('HTML with embedded images as base64 data URIs'). It distinguishes from the sibling tool 'convert_docx_to_html' by explicitly mentioning the image embedding feature.

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

Usage Guidelines4/5

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

The description implies usage context by specifying the input format (DOCX) and output format (HTML with images). However, it doesn't explicitly state when to use this tool versus the sibling 'convert_docx_to_html' or provide any exclusion criteria or prerequisites.

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