Skip to main content
Glama

markdown_to_html

Convert Markdown content into HTML format using this tool. Ideal for developers and content creators looking to transform text for web integration.

Instructions

Convert Markdown to HTML

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mdContentYesMarkdown content to convert

Implementation Reference

  • Core implementation of Markdown to HTML conversion using marked.js with custom renderer that supports themes, syntax highlighting, footnotes, and styling.
    export const renderMarkdown = ( markdownText: string, themeStyles?: ThemeStyles, fontFamily?: string, fontSize?: string ): string => { // 创建基础样式 const baseStyles = createBaseStyles(themeStyles, fontFamily, fontSize); // 获取渲染器和脚注处理器 const { renderer, generateFootnotesHtml } = createMarkdownRenderer(themeStyles, baseStyles); // 配置渲染器 marked.use({ renderer }); // 渲染Markdown const rawHtml = marked.parse(markdownText) as string; // 获取脚注HTML const footnotesHtml = generateFootnotesHtml(); // 组合HTML内容 const combinedHtml = rawHtml + footnotesHtml; // 处理首段落的margin const modifiedHtml = adjustFirstParagraphMargin(combinedHtml); // 包装并返回 return wrappedHtml(modifiedHtml); };
  • MCP CallTool request handler specifically for 'markdown_to_html' tool, validates input, calls renderMarkdown, and returns HTML content.
    this.server.setRequestHandler( CallToolRequestSchema, async (request) => { if (request.params.name !== "markdown_to_html") { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!request.params.arguments) { throw new McpError(ErrorCode.InvalidParams, "Missing request arguments"); } const mdContent = request.params.arguments.mdContent; if (typeof mdContent !== 'string') { throw new McpError(ErrorCode.InvalidParams, "mdContent must be a string"); } try { const htmlContent = renderMarkdown(mdContent, themes.grace, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE); return { content: [{ type: "text", text: htmlContent }] }; } catch (error) { throw error; } } ); }
  • src/index.ts:60-78 (registration)
    Registers the 'markdown_to_html' tool in the ListTools response, including name, description, and input schema.
    this.server.setRequestHandler( ListToolsRequestSchema, async () => ({ tools: [{ name: "markdown_to_html", description: "Convert Markdown to HTML", inputSchema: { type: "object", properties: { mdContent: { type: "string", description: "Markdown content to convert", } }, required: ["mdContent"] } }] }) );
  • Input schema definition for the markdown_to_html tool, requiring a 'mdContent' string property.
    inputSchema: { type: "object", properties: { mdContent: { type: "string", description: "Markdown content to convert", } }, required: ["mdContent"] }
  • Theme definitions used in rendering, with 'grace' theme specifically used in the tool handler.
    export const themes = { default: defaultTheme, classic: classicTheme, grace: graceTheme, simple: simpleTheme, };

Other Tools

Related 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/fashionzzZ/markdown-to-html'

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