Skip to main content
Glama

Sankey Diagram

render_sankey_chart
Read-onlyIdempotent

Visualize flows between nodes with width proportional to value. Ideal for budget flows, user journeys, and conversion funnels, showing where resources go.

Instructions

Render a sankey flow diagram - 'Where does it go?' Shows flows between nodes with width proportional to value. Great for budget flows, user journeys, energy transfers, conversion funnels with multiple paths.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesChart title
dataYesArray of flows between nodes
optionsNo
themeNoTheme preset: boardroom, corporate, sales-floor, golden-treasury, clinical, startup, ops-control, tokyo-midnight, zen-garden, consultant, black-tron, black-elegance, black-matrix, forest-amber, forest-earth, sky-light, sky-ocean, sky-twilight, gray-hf, gray-copilot
paletteNoOverride palette only (mix-and-match)
typographyNoOverride typography: professional, luxury, cyberpunk, editorial, mono, bold, system, techno
effectsNoOverride effects: none, subtle, shimmer, neon, energetic

Implementation Reference

  • The main handler function that renders a Sankey chart. It takes a container HTMLElement and a SankeyData payload, creates a Chart.js sankey chart with color mapping, tooltips, click handling, export/refresh buttons, and theme support.
    export function renderSankeyChart(container: HTMLElement, payload: SankeyData): void {
      const { title, data, options } = payload;
      const colorMode = options.colorMode ?? "gradient";
    
      const theme = resolveTheme(payload.theme, {
        palette: payload.palette,
        typography: payload.typography,
        effects: payload.effects,
      });
      if (theme) applyTheme(container, theme);
    
      // Build color map for all unique nodes
      const nodes = [...new Set(data.flatMap(d => [d.from, d.to]))];
      const palette = resolveColors(options.colors, nodes.length);
      const colorMap = new Map<string, string>();
      nodes.forEach((n, i) => colorMap.set(n, palette[i % palette.length]));
    
      container.innerHTML = `
        <div class="chart-view">
          <div class="card chart-card">
            <div class="chart-card__header">
              <div>
                <div class="chart-card__title${theme?.effects.shimmerTitle ? " shimmer-text" : ""}">${escapeHtml(title)}</div>
                <div class="chart-card__subtitle">${data.length} flows - ${nodes.length} nodes</div>
              </div>
            </div>
            <div class="chart-card__body">
              <canvas id="chart-canvas"></canvas>
            </div>
          </div>
        </div>
      `;
    
      const canvas = container.querySelector<HTMLCanvasElement>("#chart-canvas")!;
    
      const chartInstance = new Chart(canvas, {
        type: "sankey" as any,
        data: {
          datasets: [{
            data,
            colorFrom: (ctx: any) => {
              const flow = ctx.dataset.data[ctx.dataIndex];
              return flow ? (colorMap.get(flow.from) ?? palette[0]) : palette[0];
            },
            colorTo: (ctx: any) => {
              const flow = ctx.dataset.data[ctx.dataIndex];
              return flow ? (colorMap.get(flow.to) ?? palette[1]) : palette[1];
            },
            colorMode,
            borderWidth: 0,
            nodeWidth: 12,
            color: getCSSVar("--text-primary"),
            font: { size: 11 },
          }] as any,
        },
        options: {
          responsive: true,
          maintainAspectRatio: false,
          onClick: (_event, elements) => {
            if (elements.length === 0) return;
            const el = elements[0] as any;
            const idx = el.index;
            const flow = data[idx];
            if (flow) {
              sendClickMessage(`${flow.from} → ${flow.to}: ${flow.flow.toLocaleString()} in "${title}"`);
            }
          },
          plugins: {
            legend: { display: false },
            tooltip: {
              ...tooltipStyle(),
              callbacks: {
                label: (ctx: any) => {
                  const flow = ctx.dataset.data[ctx.dataIndex];
                  if (!flow) return "";
                  return `${flow.from} → ${flow.to}: ${flow.flow.toLocaleString()}`;
                },
              },
            },
          },
        },
      });
    
      deferResize(chartInstance);
      addExportButton(container, chartInstance, title);
      addRefreshButton(container, () => (window as any).__mcpRefresh?.());
    }
  • Type definitions for SankeyData and SankeyFlow interfaces, specifying the input schema: title, data (array of from/to/flow), options (colorMode, colors), and theme/palette/typography/effects properties.
    interface SankeyFlow {
      from: string;
      to: string;
      flow: number;
    }
    
    interface SankeyData {
      type: "sankey";
      title: string;
      data: SankeyFlow[];
      options: {
        colorMode?: "gradient" | "from" | "to";
        colors?: string[];
      };
      theme?: string;
      palette?: string;
      typography?: string;
      effects?: string;
    }
  • Registration call that maps the chart type 'sankey' to the tool name 'render_sankey_chart' and the renderSankeyChart handler function.
    registerChart("sankey", "render_sankey_chart", renderSankeyChart);
  • The registerChart utility function that stores chart entries in a CHART_REGISTRY record, mapping a chart type to its tool name and render function.
    export function registerChart(
      type: string,
      toolName: string,
      render: (root: HTMLElement, data: any) => void,
    ): void {
      CHART_REGISTRY[type] = { toolName, render };
    }
Behavior3/5

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

Annotations already provide readOnlyHint=true and destructiveHint=false, so the description carries less burden. It adds that the diagram 'shows flows between nodes with width proportional to value', which is useful but not extensive. No contradictions with annotations.

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

Conciseness5/5

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

The description is extremely concise at two sentences, front-loaded with the main purpose, and every sentence adds value. No redundant information.

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

Completeness4/5

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

Given the complexity (7 parameters, nested objects) and no output schema, the description is reasonably complete. It explains the chart type and use cases, though it could mention that it produces a visual output (implied). Sibling differentiation is handled by purpose and examples.

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

Parameters3/5

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

Schema description coverage is 86%, meaning parameters are already well-documented in the schema. The description does not add any additional meaning to individual parameters beyond what the schema provides. Baseline score of 3 applies.

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 tool renders a Sankey flow diagram, with a specific verb 'Render' and resource 'sankey flow diagram'. It explains the visual encoding (width proportional to value) and provides example use cases (budget flows, user journeys), effectively distinguishing it from sibling chart tools like render_funnel_chart.

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 gives explicit context for when to use the tool ('Great for budget flows, user journeys, energy transfers, conversion funnels'), but does not mention when not to use it or explicitly name alternative tools for other scenarios. The guidance is clear but lacks exclusions.

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

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/KyuRish/mcp-dashboards'

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