execute
Run synchronous JavaScript against the mermaid SDK in an isolated sandbox. Code runs as an expression or statement body — return the final value. Promise jobs, async/await, and dynamic import are not supported. Multi-step diagram edits should be one execute() call. The SDK declaration is TypeScript-shaped for guidance; the sandbox does not transpile type annotations. Hosted note: execute runs in an on-demand isolate and costs more than the direct render_svg/render_ascii/render_png/verify/describe tools — prefer those for plain render/verify calls. For straightforward structured edits, prefer the declarative mutate/build tools; reserve execute for logic the ops don't express. SDK declaration: // Mermaid agent SDK available as the global `mermaid`. All calls are // synchronous and pure. Compose multi-step edits in one execute() call. // Code Mode is synchronous: async/await, Promise jobs, and dynamic import are not supported. type Result<T, E> = { ok: true; value: T } | { ok: false; error: E } type CheckMermaidSpec = string[] | { include?: string[]; expected?: string[]; required?: string[]; require?: string[] exclude?: string[]; absent?: string[]; forbidden?: string[]; forbid?: string[]; unexpected?: string[] exact?: boolean } interface CheckMermaidResult { ok: boolean; missing: string[]; unexpected: string[]; facts: string[] } type MermaidConfigScalar = string | number | boolean | null type MermaidConfigValue = MermaidConfigScalar | MermaidConfigValue[] | { [key: string]: MermaidConfigValue | undefined } type MermaidRuntimeConfig = { [key: string]: MermaidConfigValue | undefined theme?: string fontFamily?: string themeVariables?: { [key: string]: MermaidConfigValue | undefined; fontFamily?: string } timeline?: { [key: string]: MermaidConfigValue | undefined; disableMulticolor?: boolean; sectionFills?: string[]; sectionColours?: string[] } xyChart?: { [key: string]: MermaidConfigValue | undefined } gantt?: { [key: string]: MermaidConfigValue | undefined; displayMode?: string } useMaxWidth?: boolean useWidth?: number themeCSS?: string } type DiagramKind = 'flowchart' | 'state' | 'sequence' | 'class' | 'er' | 'timeline' | 'journey' | 'xychart' | 'architecture' | 'pie' | 'quadrant' | 'gantt' interface ValidDiagram { readonly kind: DiagramKind readonly meta: { frontmatter?: Record<string, unknown> initDirectives: { raw: string; parsed: Record<string, unknown> }[] comments: { text: string; line: number }[] accessibility: { title?: string; descr?: string } } readonly body: | { kind: 'flowchart'; graph: FlowchartGraph } | StateBody | SequenceBody | TimelineBody | ClassBody | ErBody | JourneyBody | ArchitectureBody | XyChartBody | PieBody | QuadrantBody | GanttBody | { kind: 'opaque'; family: DiagramKind; source: string } readonly canonicalSource: string // normalized renderer input; opaque fidelity uses body.source } type FlowchartValidDiagram = ValidDiagram & { body: { kind: 'flowchart'; graph: FlowchartGraph } } type StateValidDiagram = ValidDiagram & { body: StateBody } type SequenceValidDiagram = ValidDiagram & { body: SequenceBody } type TimelineValidDiagram = ValidDiagram & { body: TimelineBody } type ClassValidDiagram = ValidDiagram & { body: ClassBody } type ErValidDiagram = ValidDiagram & { body: ErBody } type JourneyValidDiagram = ValidDiagram & { body: JourneyBody } type ArchitectureValidDiagram = ValidDiagram & { body: ArchitectureBody } type XyChartValidDiagram = ValidDiagram & { body: XyChartBody } type PieValidDiagram = ValidDiagram & { body: PieBody } type QuadrantValidDiagram = ValidDiagram & { body: QuadrantBody } type GanttValidDiagram = ValidDiagram & { body: GanttBody } interface FlowchartGraph { direction: 'TD' | 'TB' | 'LR' | 'BT' | 'RL' nodes: Map<string, { id: string; label: string; shape: string }> edges: { source: string; target: string; label?: string; style: string hasArrowStart?: boolean; hasArrowEnd?: boolean; startMarker?: st
Parameters2
| code | string | required | JavaScript to execute; mermaid.* SDK is global. |
| timeoutMs | number | optional | Optional CPU-time budget (default 5000ms, max 30000ms). |
Raw schema
{
"type": "object",
"properties": {
"code": {
"type": "string",
"description": "JavaScript to execute; mermaid.* SDK is global."
},
"timeoutMs": {
"type": "number",
"description": "Optional CPU-time budget (default 5000ms, max 30000ms)."
}
},
"required": [
"code"
]
}