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
| Name | Required | Description | Default |
|---|---|---|---|
| mdContent | Yes | Markdown content to convert |
Implementation Reference
- src/utils/render.ts:509-538 (handler)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); }; - src/index.ts:80-114 (handler)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"] } }] }) ); - src/index.ts:66-75 (schema)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"] } - src/theme/theme.ts:363-368 (helper)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, };