Skip to main content
Glama

generate_sankey_chart

Visualize data flow between stages or categories, such as user journeys, with a Sankey chart. Customize height, width, node alignment, theme, and output formats (PNG, SVG, or ECharts option).

Instructions

Generate a sankey chart to visualize the flow of data between different stages or categories, such as, the user journey from landing on a page to completing a purchase.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesData for sankey chart, such as, [{ source: 'Landing Page', target: 'Product Page', value: 50000 }, { source: 'Product Page', target: 'Add to Cart', value: 35000 }].
heightNoSet the height of the chart, default is 600px.
nodeAlignNoAlignment of nodes in the sankey chart, such as, 'left', 'right', or 'justify'.justify
outputTypeNoThe output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option.png
themeNoSet the theme for the chart, optional, default is 'default'.default
titleNoSet the title of the chart.
widthNoSet the width of the chart, default is 800px.

Implementation Reference

  • The 'run' function that processes the input parameters to create nodes and links from the data, constructs the ECharts Sankey chart options, and generates the output image using generateChartImage.
    run: async (params: {
      data: Array<{ source: string; target: string; value: number }>;
      height: number;
      nodeAlign?: "left" | "right" | "justify";
      theme?: "default" | "dark";
      title?: string;
      width: number;
      outputType?: "png" | "svg" | "option";
    }) => {
      const {
        data,
        height,
        nodeAlign = "justify",
        theme,
        title,
        width,
        outputType,
      } = params;
    
      // Extract unique nodes from data
      const nodeSet = new Set<string>();
      for (const item of data) {
        nodeSet.add(item.source);
        nodeSet.add(item.target);
      }
    
      // Create nodes array
      const nodes = Array.from(nodeSet).map((name) => ({ name }));
    
      // Create links array
      const links = data.map((item) => ({
        source: item.source,
        target: item.target,
        value: item.value,
      }));
    
      const series: Array<SeriesOption> = [
        {
          type: "sankey",
          data: nodes,
          links: links,
          emphasis: {
            focus: "adjacency",
          },
          nodeAlign: nodeAlign,
          left: "10%",
          top: "10%",
          right: "10%",
          bottom: "10%",
          label: {
            position: "right",
            color: "#000",
          },
          lineStyle: {
            color: "gradient",
            curveness: 0.5,
          },
        },
      ];
    
      const echartsOption: EChartsOption = {
        series,
        title: {
          left: "center",
          text: title,
        },
        tooltip: {
          trigger: "item",
          triggerOn: "mousemove",
        },
      };
    
      return await generateChartImage(
        echartsOption,
        width,
        height,
        theme,
        outputType,
        "generate_sankey_chart",
      );
    },
  • Zod schema definitions for the Sankey data structure and the tool's inputSchema including data array, dimensions, theme, title, and outputType.
    const data = z.object({
      source: z.string().describe("Source node name, such as 'Landing Page'."),
      target: z.string().describe("Target node name, such as 'Product Page'."),
      value: z
        .number()
        .describe("Flow value between source and target, such as 50000."),
    });
    
    export const generateSankeyChartTool = {
      name: "generate_sankey_chart",
      description:
        "Generate a sankey chart to visualize the flow of data between different stages or categories, such as, the user journey from landing on a page to completing a purchase.",
      inputSchema: z.object({
        data: z
          .array(data)
          .describe(
            "Data for sankey chart, such as, [{ source: 'Landing Page', target: 'Product Page', value: 50000 }, { source: 'Product Page', target: 'Add to Cart', value: 35000 }].",
          )
          .nonempty({ message: "Sankey chart data cannot be empty." }),
        height: HeightSchema,
        nodeAlign: z
          .enum(["left", "right", "justify"])
          .optional()
          .default("justify")
          .describe(
            "Alignment of nodes in the sankey chart, such as, 'left', 'right', or 'justify'.",
          ),
        theme: ThemeSchema,
        title: TitleSchema,
        width: WidthSchema,
        outputType: OutputTypeSchema,
      }),
  • The generateSankeyChartTool is included in the exported 'tools' array, which likely registers it for use in the MCP server.
    export const tools = [
      generateEChartsTool,
      generateLineChartTool,
      generateBarChartTool,
      generatePieChartTool,
      generateRadarChartTool,
      generateScatterChartTool,
      generateSankeyChartTool,
      generateFunnelChartTool,
      generateGaugeChartTool,
      generateTreemapChartTool,
      generateSunburstChartTool,
      generateHeatmapChartTool,
      generateCandlestickChartTool,
      generateBoxplotChartTool,
      generateGraphChartTool,
      generateParallelChartTool,
      generateTreeChartTool,
    ];
  • Re-export of generateSankeyChartTool from index.ts for convenient access.
    generateSankeyChartTool,
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool generates a chart but doesn't mention what happens after generation (e.g., where the chart is saved/displayed, whether it's interactive, or if there are rate limits). The example hints at data transformation but lacks details on error handling or performance characteristics. For a chart generation tool with 7 parameters, this leaves significant behavioral gaps.

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 a single, well-structured sentence that efficiently communicates the core purpose with a relevant example. It's appropriately sized for a chart generation tool and front-loads the essential information. The example ('user journey from landing on a page to completing a purchase') is helpful and doesn't waste space.

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

Completeness3/5

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

Given the tool's complexity (7 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks information about output format, error conditions, or integration context. Without annotations or output schema, the agent won't know what the tool returns (e.g., image data, file path, or chart object). The description should address these gaps for better completeness.

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 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema - it mentions 'data' in the context of flow visualization but doesn't provide additional syntax, format details, or usage examples beyond what's in the schema descriptions. The baseline of 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Generate a sankey chart to visualize the flow of data between different stages or categories.' It specifies the verb ('generate'), resource ('sankey chart'), and provides a concrete example ('user journey from landing on a page to completing a purchase'). However, it doesn't explicitly differentiate this from sibling tools like generate_funnel_chart or generate_graph_chart, which might also visualize flows or relationships.

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

Usage Guidelines3/5

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

The description implies usage context through the example ('visualize the flow of data between different stages or categories, such as, the user journey'), suggesting this tool is for flow visualization. However, it doesn't provide explicit guidance on when to use this versus alternatives like generate_funnel_chart (for conversion flows) or generate_graph_chart (for network relationships). No exclusion criteria or prerequisites are mentioned.

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/hustcc/mcp-echarts'

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