convert_html
Convert HTML content to clean Markdown optimized for LLM processing, extracting main content and resolving links for better AI analysis.
Instructions
Convert an HTML string to clean, LLM-optimized Markdown. Use this when you already have HTML content and need it as Markdown.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| html | Yes | The HTML content to convert | |
| url | No | Base URL for resolving relative links and images | |
| include_header | No | Include title/source/author header in output | |
| raw | No | Use full HTML content instead of extracting main article |
Implementation Reference
- src/index.ts:113-128 (handler)Handler function for 'convert_html' tool - takes HTML string and converts it to Markdown using the readdown library. Accepts optional url, include_header, and raw parameters, then returns the markdown content.
async ({ html, url, include_header, raw }) => { const result = readdown(html, { url, includeHeader: include_header, raw, }); return { content: [ { type: "text" as const, text: result.markdown, }, ], }; } - src/index.ts:96-112 (schema)Zod schema definition for 'convert_html' tool inputs: html (required string), url (optional URL string for resolving relative links), include_header (optional boolean, default true), and raw (optional boolean, default false).
html: z.string().describe("The HTML content to convert"), url: z .string() .url() .optional() .describe("Base URL for resolving relative links and images"), include_header: z .boolean() .optional() .default(true) .describe("Include title/source/author header in output"), raw: z .boolean() .optional() .default(false) .describe("Use full HTML content instead of extracting main article"), }, - src/index.ts:91-129 (registration)Tool registration for 'convert_html' using server.tool() - registers the tool name, description, input schema, and handler function with the MCP server.
server.tool( "convert_html", "Convert an HTML string to clean, LLM-optimized Markdown. " + "Use this when you already have HTML content and need it as Markdown.", { html: z.string().describe("The HTML content to convert"), url: z .string() .url() .optional() .describe("Base URL for resolving relative links and images"), include_header: z .boolean() .optional() .default(true) .describe("Include title/source/author header in output"), raw: z .boolean() .optional() .default(false) .describe("Use full HTML content instead of extracting main article"), }, async ({ html, url, include_header, raw }) => { const result = readdown(html, { url, includeHeader: include_header, raw, }); return { content: [ { type: "text" as const, text: result.markdown, }, ], }; } );