Skip to main content
Glama

generate_diagram_from_mermaid

Convert Mermaid diagram code to D2 format and generate PNG images for flowcharts, sequence diagrams, ER diagrams, and other visualizations.

Instructions

Convert a Mermaid diagram definition into a D2 diagram and return a PNG image. Use this tool when the user has existing Mermaid code (flowchart, sequenceDiagram, erDiagram, etc.) and wants it converted to D2 or rendered as an image. Pass the Mermaid source as content. Returns a link to view and edit the generated diagram in the browser.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesA Mermaid diagram definition to convert to D2. Pass the raw Mermaid source (e.g. flowchart, sequenceDiagram, erDiagram). Example: "flowchart LR A --> B --> C"
promptNoOptional instruction for layout or styling of the converted diagram.
diagramTypeNoPreferred diagram type for the converted D2 output.
isIconEnabledNoSet to true when the user asks to include icons in the diagram.

Implementation Reference

  • Registration of the "generate_diagram_from_mermaid" tool, which uses the shared `generateDiagram` handler.
    export function registerGenerateMermaidTool(server: McpServer): void {
      registerAppTool(
        server,
        "generate_diagram_from_mermaid",
        {
          description:
            "Convert a Mermaid diagram definition into a D2 diagram and return a PNG image. " +
            "Use this tool when the user has existing Mermaid code (flowchart, sequenceDiagram, erDiagram, etc.) " +
            "and wants it converted to D2 or rendered as an image. " +
            "Pass the Mermaid source as content. " +
            "Returns a link to view and edit the generated diagram in the browser.",
          inputSchema,
          _meta: { ui: { resourceUri: DIAGRAM_APP_RESOURCE_URI } },
        },
        async (args) => generateDiagram("mermaid", args)
      );
    }
  • The shared `generateDiagram` function that serves as the actual handler logic for multiple diagram tools, including `generate_diagram_from_mermaid`.
    export async function generateDiagram(
      inputType: GenerateDiagramV2Request["inputType"],
      params: DiagramParams
    ): Promise<CallToolResult> {

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/erajasekar/ai-diagram-maker-mcp'

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