Skip to main content
Glama

Markdown Converter

convert_markdown

Convert HTML to clean Markdown for LLM processing, or Markdown to HTML for web rendering. Preserves structure like headings, lists, code blocks, links, and tables.

Instructions

Convert HTML to clean Markdown, or Markdown to HTML. Use HTML→Markdown when you've fetched a web page and need readable text for an LLM — strips tags, preserves headings, lists, code blocks, links, and tables. Use Markdown→HTML when rendering content in a web context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesThe content to convert
fromYesInput format
toYesOutput format

Implementation Reference

  • The core logic function 'handler' that performs the conversion between HTML and Markdown using Turndown and Marked libraries.
    async function handler(input: Input) {
      const { content, from, to, options } = input;
    
      if (from === to) {
        return { output: content, from, to, note: "Input and output formats are the same" };
      }
    
      let output: string;
    
      if (from === "html" && to === "markdown") {
        const td = new TurndownService({
          headingStyle: options?.headingStyle ?? "atx",
          bulletListMarker: options?.bulletListMarker ?? "-",
          codeBlockStyle: options?.codeBlockStyle ?? "fenced",
        });
        output = td.turndown(content);
      } else {
        // markdown → html
        output = await marked(content, { async: true });
      }
    
      return {
        output,
        from,
        to,
        inputLength: content.length,
        outputLength: output.length,
      };
    }
  • The Zod schema definition for input validation, including content, from, to, and conversion options.
    const inputSchema = z.object({
      content: z.string().min(1).max(100_000).describe("The content to convert"),
      from: z.enum(["html", "markdown"]).describe("Input format"),
      to: z.enum(["html", "markdown"]).describe("Output format"),
      options: z
        .object({
          headingStyle: z
            .enum(["atx", "setext"])
            .optional()
            .describe("Markdown heading style: atx (#) or setext (underline)"),
          bulletListMarker: z
            .enum(["-", "*", "+"])
            .optional()
            .describe("Bullet list marker character"),
          codeBlockStyle: z
            .enum(["fenced", "indented"])
            .optional()
            .describe("Code block style in markdown output"),
        })
        .optional(),
    });
  • The tool definition and registration call that makes 'markdown-converter' available. Note that mcp-server/src/index.ts calls it via an API bridge, while this file defines the actual underlying tool.
    const markdownConverterTool: ToolDefinition<Input> = {
      name: "markdown-converter",
      description:
        "Convert between HTML and Markdown. HTML → Markdown for clean agent-readable content; Markdown → HTML for rendering. Handles headings, lists, links, code blocks, tables, and more.",
      version: "1.0.0",
      inputSchema,
      handler,
      metadata: {
        tags: ["markdown", "html", "conversion", "formatting", "content"],
        pricing: "$0.0005 per call",
        exampleInput: {
          content: "<h1>Hello World</h1><p>This is a <strong>bold</strong> paragraph with a <a href='https://example.com'>link</a>.</p><ul><li>Item one</li><li>Item two</li></ul>",
          from: "html",
          to: "markdown",
          options: { headingStyle: "atx", bulletListMarker: "-", codeBlockStyle: "fenced" },
        },
      },
    };
    
    registerTool(markdownConverterTool);
Behavior4/5

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

With no annotations provided, the description carries the full burden and successfully discloses key behavioral traits: it 'strips tags' and specifically 'preserves headings, lists, code blocks, links, and tables.' It also notes the output is 'clean Markdown.' Minor gap: no mention of error handling for malformed input or Markdown flavor specifics.

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?

Three sentences with zero waste: first establishes capability, second details HTML→Markdown use case with preservation specifics, third covers Markdown→HTML. Front-loaded with the core function and maintains tight focus throughout.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple conversion utility with 100% schema coverage and no nested complexity, the description is complete. It explains the conversion behavior, directional use cases, and preservation characteristics. No output schema exists, but the return value is implied by the 'to' parameter context.

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 coverage is 100% with clear descriptions for all three parameters (content, from, to) and explicit enums. The description adds directional context (HTML→Markdown vs Markdown→HTML) that contextualizes the enum values, but does not need to explain parameter mechanics since the schema is fully self-documenting.

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 opens with specific verbs ('Convert') and clear resources ('HTML', 'Markdown'), immediately establishing the bidirectional capability. It effectively distinguishes from siblings like extract_from_text or fetch_url_metadata by focusing purely on format conversion rather than extraction or analysis.

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?

Provides explicit directional guidance: 'Use HTML→Markdown when you've fetched a web page and need readable text for an LLM' and 'Use Markdown→HTML when rendering content in a web context.' This clearly defines when to use each conversion direction based on the downstream use case.

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/marras0914/agent-toolbelt'

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