Skip to main content
Glama
abrinsmead

Mindpilot MCP

by abrinsmead

render_mermaid

Convert Mermaid diagram syntax into SVG format using specific formatting rules for node IDs, labels, and arrow styles. Ideal for visualizing diagrams in light and dark modes with predefined color schemes.

Instructions

Render a Mermaid diagram to SVG format. CRITICAL RULES: 1) Node IDs must be alphanumeric without spaces (use A1, nodeA, start_node). 2) For node labels with special characters, wrap in quotes: A["Label with spaces"] or A["Process (step 1)"]. 3) For quotes in labels use ", for < use <, for > use >. 4) For square brackets in labels use A["Array[0]"]. 5) Always close all brackets and quotes. 6) Use consistent arrow styles (either --> or ->). Example: graph TD\n A["Complex Label"] --> B{Decision?}\n B -->|Yes| C["Result "OK""]\n\nIMPORTANT: If the diagram fails validation, the error message will explain what needs to be fixed. Please read the error carefully and retry with a corrected diagram.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
backgroundNoBackground colorwhite
diagramYesMermaid diagram syntax. MUST start with diagram type (graph TD, flowchart LR, sequenceDiagram, etc). Node IDs cannot have spaces. Use quotes for labels with spaces/special chars. Avoid forward slashes. Use this colors which work well for both light and dark mode: classDef coral fill:#ff6b6b,stroke:#c92a2a,color:#fff classDef ocean fill:#4c6ef5,stroke:#364fc7,color:#fff classDef forest fill:#51cf66,stroke:#2f9e44,color:#fff classDef sunshine fill:#ffd43b,stroke:#fab005,color:#000 classDef grape fill:#845ef7,stroke:#5f3dc4,color:#fff classDef amber fill:#ff922b,stroke:#e8590c,color:#fff classDef teal fill:#20c997,stroke:#12b886,color:#fff classDef pink fill:#ff8cc8,stroke:#e64980,color:#fff classDef tangerine fill:#fd7e14,stroke:#e8590c,color:#fff classDef sky fill:#74c0fc,stroke:#339af0,color:#000 classDef lavender fill:#d0bfff,stroke:#9775fa,color:#000 classDef mint fill:#8ce99a,stroke:#51cf66,color:#000 classDef rose fill:#ffa8a8,stroke:#ff6b6b,color:#000 classDef lemon fill:#ffe066,stroke:#ffd43b,color:#000 classDef violet fill:#a78bfa,stroke:#8b5cf6,color:#fff classDef peach fill:#ffc9c9,stroke:#ffa8a8,color:#000
titleYesTitle for the diagram (max 50 characters)

Implementation Reference

  • Registration of the 'render_mermaid' tool including name, description, and input schema definition.
    {
      name: "render_mermaid",
      description:
        'Render a Mermaid diagram to SVG format. CRITICAL RULES: 1) Node IDs must be alphanumeric without spaces (use A1, nodeA, start_node). 2) For node labels with special characters, wrap in quotes: A["Label with spaces"] or A["Process (step 1)"]. 3) For quotes in labels use ", for < use <, for > use >. 4) For square brackets in labels use A["Array[0]"]. 5) Always close all brackets and quotes. 6) Use consistent arrow styles (either --> or ->). Example: graph TD\\n  A["Complex Label"] --> B{Decision?}\\n  B -->|Yes| C["Result "OK""]\\n\\nIMPORTANT: If the diagram fails validation, the error message will explain what needs to be fixed. Please read the error carefully and retry with a corrected diagram.',
      inputSchema: {
        type: "object",
        properties: {
          diagram: {
            type: "string",
            description: `Mermaid diagram syntax. MUST start with diagram type (graph TD, flowchart LR, sequenceDiagram, etc). Node IDs cannot have spaces. Use quotes for labels with spaces/special chars. Avoid forward slashes. Use this colors which work well for both light and dark mode: ${colorPrompt}`,
          },
          background: {
            type: "string",
            description: "Background color",
            default: "white",
          },
          title: {
            type: "string",
            description: "Title for the diagram (max 50 characters)",
            maxLength: 50,
          },
        },
        required: ["diagram", "title"],
      },
    },
  • The primary handler method for executing the render_mermaid tool, proxying the request to the HTTP server's /api/render endpoint and handling the RenderResult.
    private async renderMermaid(
      diagram: string,
      background?: string,
      title?: string,
    ): Promise<RenderResult> {
      // Use HTTP API endpoint
      try {
        const response = await fetch(
          `http://localhost:${this.httpPort}/api/render`,
          {
            method: "POST",
            headers: {
              "Content-Type": "application/json",
            },
            body: JSON.stringify({
              diagram,
              background,
              title,
              clientId: this.clientId,
              clientName: this.clientName,
              workingDir: process.cwd(),
            }),
            signal: this.getAbortSignal(),
          },
        );
    
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
    
        const result = (await response.json()) as RenderResult;
    
        return result;
      } catch (error) {
        return {
          type: "error",
          diagram,
          error:
            error instanceof Error ? error.message : "Failed to render diagram",
        };
      }
    }
  • The switch case in the CallToolRequestHandler that invokes the renderMermaid method for the 'render_mermaid' tool.
    case "render_mermaid":
      const renderResult = await this.renderMermaid(
        args?.diagram as string,
        args?.background as string,
        args?.title as string,
      );
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(renderResult, null, 2),
          },
        ],
      };
  • Core rendering helper function that validates Mermaid syntax and prepares the RenderResult for client-side SVG rendering. Used by the HTTP server.
    export async function renderMermaid(
      diagram: string,
      background?: string,
    ): Promise<RenderResult> {
      try {
        // Validate the diagram first
        const validation = await validateMermaidSyntax(diagram);
    
        if (!validation.valid) {
          return {
            type: "error",
            diagram,
            error: validation.errors?.[0] || "Invalid diagram syntax",
            details: validation.errors?.join("\n"),
          };
        }
    
        // Return the validated diagram for client-side rendering
        // The actual SVG rendering happens in the browser
        return {
          type: "success",
          diagram,
          background,
          // Note: svg field is populated by the client after rendering
        };
      } catch (error) {
        return {
          type: "error",
          diagram,
          error: error instanceof Error ? error.message : "Failed to process diagram",
        };
      }
    }
  • Input schema definition for the render_mermaid tool, specifying properties and requirements.
    inputSchema: {
      type: "object",
      properties: {
        diagram: {
          type: "string",
          description: `Mermaid diagram syntax. MUST start with diagram type (graph TD, flowchart LR, sequenceDiagram, etc). Node IDs cannot have spaces. Use quotes for labels with spaces/special chars. Avoid forward slashes. Use this colors which work well for both light and dark mode: ${colorPrompt}`,
        },
        background: {
          type: "string",
          description: "Background color",
          default: "white",
        },
        title: {
          type: "string",
          description: "Title for the diagram (max 50 characters)",
          maxLength: 50,
        },
      },
      required: ["diagram", "title"],
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure and excels at this. It provides extensive validation rules, error handling guidance ('If the diagram fails validation, the error message will explain what needs to be fixed'), and specific formatting requirements that go beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with clear sections (purpose, critical rules, example, error handling). Every sentence serves a purpose, though it's somewhat lengthy due to the detailed formatting rules. The information is front-loaded with the core purpose first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and no output schema, the description provides exceptional completeness. It covers purpose, detailed usage rules, parameter guidance, error handling, and examples. The comprehensive formatting instructions compensate for the lack of structured metadata.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

While the input schema has 100% description coverage, the description adds significant value by providing detailed formatting rules, examples, and validation requirements for the 'diagram' parameter that aren't captured in the schema. It doesn't add much for 'background' or 'title' parameters, but the comprehensive diagram guidance compensates well.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Render a Mermaid diagram to SVG format') and distinguishes it from the only sibling tool 'open_ui' by focusing on diagram rendering rather than UI operations. It provides a complete verb+resource+output format specification.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool (for rendering Mermaid diagrams to SVG) and includes critical formatting rules. However, it doesn't explicitly mention when NOT to use it or compare it to potential alternatives beyond the single sibling tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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/abrinsmead/mindpilot-mcp'

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