{
  "openapi": "3.1.1",
  "info": {
    "title": "Sketchboard Mermaid to Diagram API",
    "version": "1.0.0",
    "summary": "Turn a Mermaid flowchart into a laid-out, editable diagram with an SVG export.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://sketchboardmermaidtodiagram.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Turn a Mermaid flowchart into a laid-out, editable diagram with an SVG export.",
        "description": "Parses the flowchart part of Mermaid (directions, node shapes, labelled and dotted links, chains, subgraphs), places the nodes with a layered layout so few lines cross, routes the connectors around the boxes and returns an SVG plus a Sketchboard board where every box and arrow can be moved and restyled.\n\nMethodology:\n- Supported: flowchart/graph with TB, TD, BT, LR or RL; node shapes [ ], ( ), ([ ]), [[ ]], [( )], (( )), { }, {{ }}, \u003e ], [/ /], [\\ \\], [/ \\], [\\ /]; links --\u003e, ---, -.-\u003e, ==\u003e, --o, --x, \u003c--\u003e, labels as --\u003e|text| or -- text --\u003e; chains (A --\u003e B --\u003e C), A \u0026 B --\u003e C, subgraph … end (drawn as a frame), %% comments. Styling lines (classDef, class, style, linkStyle, click) are ignored and counted.\n- Node size comes from its text (deterministic width estimate, wrapping at 260 units); decisions are drawn larger so their text fits the diamond.\n- Layout (Sugiyama et al. 1981): cycles are broken by reversing DFS back edges, each node gets the rank of its longest path from a source, long links get dummy nodes, 12 barycentre sweeps reduce crossings (the ordering with the fewest crossings wins), and median alignment passes straighten the links. Gaps: 50 units across, 70 along the direction.\n- Connectors are glued to the shapes and routed by Sketchboard’s router (orthogonal A* around the boxes with a bend penalty for the elbow style), so moving a box later keeps the arrows attached.\n\nOnly the flowchart subset of Mermaid is read; sequence, class and other Mermaid diagram types are not converted. Mermaid is an open-source project and not affiliated with usefulweb.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "sketchboard_mermaid_to_diagram",
        "x-owner-app": "sketchboard",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SketchboardMermaidToDiagramInput"
              },
              "examples": {
                "example1": {
                  "summary": "Sign-up flow with decisions",
                  "value": {
                    "mermaid": "flowchart TD\n  start([Visitor opens the sign-up page]) --\u003e form[Fill in name and e-mail]\n  form --\u003e valid{Is the e-mail valid?}\n  valid -- no --\u003e err[Show a clear error message] --\u003e form\n  valid -- yes --\u003e exists{Account exists already?}\n  exists -- yes --\u003e login[Offer to sign in instead]\n  exists -- no --\u003e create[(Create the account)]\n  create --\u003e mail[Send the welcome e-mail]\n  mail --\u003e done([Show the dashboard])\n  login --\u003e done"
                  }
                },
                "example2": {
                  "summary": "Release pipeline left to right, hand-drawn",
                  "value": {
                    "mermaid": "flowchart LR\n  code[Commit] --\u003e ci{{CI checks}}\n  ci --\u003e|green| stage[Deploy to staging]\n  ci -.-\u003e|red| fix[Fix the build] --\u003e code\n  stage --\u003e qa{QA OK?}\n  qa -- yes --\u003e prod([Release])\n  qa -- no --\u003e fix\n  subgraph Automated\n    ci\n    stage\n  end",
                    "direction": "",
                    "route": "elbow",
                    "style": "sketchy"
                  }
                },
                "example3": {
                  "summary": "Small graph with curved links",
                  "value": {
                    "mermaid": "graph TD\n  A((Hub)) --- B[North] \u0026 C[East] \u0026 D[South]\n  B --\u003e E[(Archive)]",
                    "route": "curved"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SketchboardMermaidToDiagramResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SketchboardMermaidToDiagramInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mermaid": {
            "title": "Mermaid flowchart",
            "description": "Starts with “flowchart TD” (or graph LR …). One link per line, for example A[Start] --\u003e B{OK?}.",
            "type": "string",
            "maxLength": 200000,
            "default": ""
          },
          "direction": {
            "title": "Direction",
            "type": "string",
            "enum": [
              "",
              "TB",
              "LR",
              "BT",
              "RL"
            ],
            "default": ""
          },
          "route": {
            "title": "Connector style",
            "type": "string",
            "enum": [
              "elbow",
              "straight",
              "curved"
            ],
            "default": "elbow"
          },
          "style": {
            "title": "Drawing style",
            "type": "string",
            "enum": [
              "clean",
              "sketchy",
              "file"
            ],
            "default": "clean"
          }
        },
        "required": []
      },
      "SketchboardMermaidToDiagramResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object"
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}