Skip to main content
Glama

generate_funnel_chart

Visualize the progressive reduction of data through stages, such as conversion rates from browsing to purchase. Input stage categories and values to generate a funnel chart highlighting drop-offs.

Instructions

Generate a funnel chart to visualize the progressive reduction of data as it passes through stages, such as, the conversion rates of users from visiting a website to completing a purchase.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesData for funnel chart, such as, [{ category: 'Browse Website', value: 50000 }, { category: 'Add to Cart', value: 35000 }, { category: 'Generate Order', value: 25000 }].
heightNoSet the height of the chart, default is 600px.
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.
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

Implementation Reference

  • The `run` function that executes the funnel chart generation logic. Transforms input data into ECharts funnel series options and calls `generateChartImage` to render the chart.
      run: async (params: {
        data: Array<{ category: string; value: number }>;
        height: number;
        theme?: "default" | "dark";
        title?: string;
        width: number;
        outputType?: "png" | "svg" | "option";
      }) => {
        const { data, height, theme, title, width, outputType } = params;
    
        // Transform data for ECharts funnel chart
        const funnelData = data.map((item) => ({
          name: item.category,
          value: item.value,
        }));
    
        const series: Array<SeriesOption> = [
          {
            type: "funnel",
            data: funnelData,
            left: "10%",
            top: 60,
            width: "80%",
            height: "80%",
            min: 0,
            max: Math.max(...data.map((item) => item.value)),
            minSize: "0%",
            maxSize: "100%",
            sort: "descending",
            gap: 2,
            label: {
              show: true,
              position: "inside",
              fontSize: 12,
              color: "#fff",
            },
            labelLine: {
              length: 10,
              lineStyle: {
                width: 1,
                type: "solid",
              },
            },
            itemStyle: {
              borderColor: "#fff",
              borderWidth: 1,
            },
            emphasis: {
              label: {
                fontSize: 16,
              },
            },
          },
        ];
    
        const echartsOption: EChartsOption = {
          series,
          title: {
            left: "center",
            text: title,
          },
          tooltip: {
            trigger: "item",
          },
          legend: {
            left: "center",
            orient: "horizontal",
            bottom: 10,
            data: funnelData.map((item) => item.name),
          },
        };
    
        return await generateChartImage(
          echartsOption,
          width,
          height,
          theme,
          outputType,
          "generate_funnel_chart",
        );
      },
    };
  • Input schema definition for the funnel chart tool. Defines the 'data' array (with category/value objects), height, theme, title, width, and outputType fields using Zod schemas.
    // Funnel chart data schema
    const data = z.object({
      category: z
        .string()
        .describe("Stage category name, such as 'Browse Website'."),
      value: z.number().describe("Value at this stage, such as 50000."),
    });
    
    export const generateFunnelChartTool = {
      name: "generate_funnel_chart",
      description:
        "Generate a funnel chart to visualize the progressive reduction of data as it passes through stages, such as, the conversion rates of users from visiting a website to completing a purchase.",
      inputSchema: z.object({
        data: z
          .array(data)
          .describe(
            "Data for funnel chart, such as, [{ category: 'Browse Website', value: 50000 }, { category: 'Add to Cart', value: 35000 }, { category: 'Generate Order', value: 25000 }].",
          )
          .nonempty({ message: "Funnel chart data cannot be empty." }),
        height: HeightSchema,
        theme: ThemeSchema,
        title: TitleSchema,
        width: WidthSchema,
        outputType: OutputTypeSchema,
      }),
  • Registration of `generateFunnelChartTool` in the tools array at line 29, making it available to the MCP server.
    export const tools = [
      generateEChartsTool,
      generateAreaChartTool,
      generateLineChartTool,
      generateBarChartTool,
      generatePieChartTool,
      generateRadarChartTool,
      generateScatterChartTool,
      generateSankeyChartTool,
      generateFunnelChartTool,
  • src/index.ts:28-31 (registration)
    The MCP server registration loop that iterates over all tools (including generate_funnel_chart) and registers them with the MCP SDK via `server.tool()`.
    for (const tool of tools) {
      const { name, description, inputSchema, run } = tool;
      // biome-ignore lint/suspicious/noExplicitAny: <explanation>
      server.tool(name, description, inputSchema.shape as any, run as any);
  • The `generateChartImage` helper function called by the funnel chart handler. Renders the ECharts option and returns the result as Base64 image, SVG text, or MinIO URL.
    export async function generateChartImage(
      echartsOption: EChartsOption,
      width = 800,
      height = 600,
      theme: "default" | "dark" = "default",
      outputType: ImageOutputFormat = "png",
      toolName = "unknown",
    ): Promise<ImageHandlerResult> {
      // Debug logging
      if (process.env.DEBUG_MCP_ECHARTS) {
        console.error(`[DEBUG] ${toolName} generating chart:`, {
          width,
          height,
          theme,
          outputType,
          optionKeys: Object.keys(echartsOption),
        });
      }
    
      try {
        // Render chart
        const result = await renderECharts(
          echartsOption,
          width,
          height,
          theme,
          outputType,
        );
    
        // Determine output type
        const isImage = outputType !== "svg" && outputType !== "option";
    
        if (!isImage) {
          // SVG or configuration options, return text directly
          const response = {
            content: [
              {
                type: "text" as const,
                text: result as string,
              },
            ],
          };
    
          if (process.env.DEBUG_MCP_ECHARTS) {
            console.error(`[DEBUG] ${toolName} chart generated successfully:`, {
              contentType: "text",
              textLength: (result as string).length,
            });
          }
    
          return response;
        }
    
        // PNG image type
        const buffer = result as Buffer;
    
        if (isMinIOConfigured()) {
          try {
            // Use MinIO storage, return URL
            const url = await storeBufferToMinIO(buffer, "png", "image/png");
    
            const response = {
              content: [
                {
                  type: "text" as const,
                  text: url,
                },
              ],
            };
    
            if (process.env.DEBUG_MCP_ECHARTS) {
              console.error(`[DEBUG] ${toolName} chart generated successfully:`, {
                contentType: "text",
                url: url,
              });
            }
    
            return response;
          } catch (minioError) {
            // MinIO failed, log warning and fallback to Base64
            if (process.env.DEBUG_MCP_ECHARTS) {
              console.error(
                `[DEBUG] ${toolName} MinIO storage failed, falling back to Base64:`,
                {
                  error:
                    minioError instanceof Error
                      ? minioError.message
                      : String(minioError),
                },
              );
            }
            // Continue to Base64 fallback below
          }
        }
    
        // Fallback to Base64
        const base64Data = buffer.toString("base64");
    
        const response = {
          content: [
            {
              type: "image" as const,
              data: base64Data,
              mimeType: "image/png",
            },
          ],
        };
    
        if (process.env.DEBUG_MCP_ECHARTS) {
          console.error(`[DEBUG] ${toolName} chart generated successfully:`, {
            contentType: "image",
            dataLength: base64Data.length,
          });
        }
    
        return response;
      } catch (error) {
        // Error logging
        if (process.env.DEBUG_MCP_ECHARTS) {
          console.error(`[DEBUG] ${toolName} chart generation failed:`, {
            error: error instanceof Error ? error.message : String(error),
            stack: error instanceof Error ? error.stack : undefined,
          });
        }
    
        throw new Error(
          `Chart rendering failed: ${
            error instanceof Error ? error.message : String(error)
          }`,
        );
      }
    }
Behavior3/5

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

No annotations provided, so the description carries full burden. It does not disclose behavioral traits beyond the chart type; for example, it doesn't mention that the tool returns an image or ECharts option (though outputType parameter hints at it). Minimal disclosure.

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?

Single sentence with an embedded example, no wordiness, front-loaded with the tool's purpose.

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 no annotations and no output schema, the description effectively explains the tool's purpose and provides a typical use case. However, it could mention output format or behavior more explicitly.

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 coverage is 100%, so baseline is 3. The description adds no additional meaning beyond the schema; it does not explain parameters or their usage.

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 it generates a funnel chart and explains its purpose (visualizing progressive reduction through stages) with a concrete example (conversion rates). It distinguishes from sibling chart tools by specifying the chart type.

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 implies when to use (for conversion rates, progressive reduction), but does not explicitly mention when not to use or compare with alternatives. However, the context is clear.

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

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