Skip to main content
Glama

MCP Server Mermaid

render.ts1.19 kB
import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; import { type MermaidRenderer, type RenderResult, createMermaidRenderer, } from "mermaid-isomorphic"; // Cache the renderer to avoid creating a new one every time. let renderer: MermaidRenderer; /** * Ref: * - https://github.com/mermaid-js/mermaid-cli/blob/master/src/index.js * - https://github.com/remcohaszing/mermaid-isomorphic * @returns */ export async function renderMermaid( mermaid: string, theme = "default", backgroundColor = "white", ): Promise<RenderResult> { if (!renderer) renderer = createMermaidRenderer(); const cssContent = `svg { background: ${backgroundColor}; }`; const cssTmpPath = path.join(os.tmpdir(), "mermaid-tmp-css.css"); fs.writeFileSync(cssTmpPath, cssContent); const r = await renderer([mermaid], { // Image is needed. screenshot: true, css: cssTmpPath, mermaidConfig: { // biome-ignore lint/suspicious/noExplicitAny: <explanation> theme: theme as any, }, }); const r0 = r[0] as PromiseSettledResult<RenderResult>; return r0.status === "fulfilled" ? r0.value : Promise.reject(r0.reason); }

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/hustcc/mcp-mermaid'

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