Skip to main content
Glama

generate_gauge_chart

Create a gauge chart to monitor a single indicator's current status, such as CPU usage, progress, or score. Configure min, max, title, theme, and output as PNG, SVG, or ECharts option for easy embedding.

Instructions

Generate a gauge chart to display single indicator's current status, such as, CPU usage rate, completion progress, or performance scores.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesData for gauge chart, such as, [{ name: 'CPU Usage', value: 75 }]. Multiple gauges can be displayed.
heightNoSet the height of the chart, default is 600px.
maxNoMaximum value of the gauge, default is 100.
minNoMinimum value of the gauge, default is 0.
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 handler function that executes generate_gauge_chart tool logic. It builds ECharts gauge series options from input data and calls generateChartImage to render the chart.
    run: async (params: {
      data: Array<{ name: string; value: number }>;
      height: number;
      max?: number;
      min?: number;
      theme?: "default" | "dark";
      title?: string;
      width: number;
      outputType?: "png" | "svg" | "option";
    }) => {
      const {
        data,
        height,
        max = 100,
        min = 0,
        theme,
        title,
        width,
        outputType,
      } = params;
    
      // For multiple gauges, arrange them horizontally
      const series: Array<SeriesOption> = data.map((item, index) => {
        const isMultiple = data.length > 1;
    
        return {
          name: item.name,
          type: "gauge",
          data: [{ name: item.name, value: item.value }],
          center: isMultiple
            ? [`${(100 / (data.length + 1)) * (index + 1)}%`, "60%"]
            : ["50%", "55%"],
          radius: isMultiple ? `${Math.min(80 / data.length, 30)}%` : "80%",
          min: min,
          max: max,
          startAngle: 180,
          endAngle: 0,
          axisLine: {
            lineStyle: {
              width: 6,
              color: [
                [0.3, "#67e0e3"],
                [0.7, "#37a2da"],
                [1, "#fd666d"],
              ],
            },
          },
          pointer: {
            itemStyle: {
              color: "inherit",
            },
          },
          axisTick: {
            distance: -30,
            length: 8,
            lineStyle: {
              color: "#fff",
              width: 2,
            },
          },
          splitLine: {
            distance: -30,
            length: 30,
            lineStyle: {
              color: "#fff",
              width: 4,
            },
          },
          axisLabel: {
            color: "inherit",
            distance: 40,
            fontSize: isMultiple ? 10 : 12,
          },
          detail: {
            valueAnimation: true,
            formatter: "{value}",
            color: "inherit",
            fontSize: isMultiple ? 16 : 20,
            offsetCenter: [0, "30%"],
          },
          title: {
            offsetCenter: [0, "50%"],
            fontSize: isMultiple ? 12 : 14,
          },
        };
      });
    
      const echartsOption: EChartsOption = {
        legend:
          data.length > 1
            ? {
                bottom: 10,
                left: "center",
                orient: "horizontal",
                data: data.map((item) => item.name),
              }
            : undefined,
        series,
        title: {
          left: "center",
          text: title,
          top: data.length > 1 ? "5%" : undefined,
        },
      };
    
      return await generateChartImage(
        echartsOption,
        width,
        height,
        theme,
        outputType,
        "generate_gauge_chart",
      );
    },
  • Input schema for generate_gauge_chart tool using Zod validations: array of {name, value} data objects, min/max range, height, width, theme, title, and outputType.
    inputSchema: z.object({
      data: z
        .array(data)
        .describe(
          "Data for gauge chart, such as, [{ name: 'CPU Usage', value: 75 }]. Multiple gauges can be displayed.",
        )
        .nonempty({ message: "Gauge chart data cannot be empty." }),
      height: HeightSchema,
      max: z
        .number()
        .optional()
        .default(100)
        .describe("Maximum value of the gauge, default is 100."),
      min: z
        .number()
        .optional()
        .default(0)
        .describe("Minimum value of the gauge, default is 0."),
      theme: ThemeSchema,
      title: TitleSchema,
      width: WidthSchema,
      outputType: OutputTypeSchema,
    }),
  • Tool registration in the tools array that gets passed to McpServer.tool() in src/index.ts.
    generateGaugeChartTool,
    generateTreemapChartTool,
  • generateChartImage helper function called by the handler to render and return the chart as PNG (Base64 or MinIO URL), SVG, or raw ECharts option.
    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)
          }`,
        );
      }
    }
  • renderECharts helper that uses napi-rs canvas and server-side ECharts to render the chart option into a Buffer (PNG) or string (SVG/JSON).
    export async function renderECharts(
      echartsOption: EChartsOption,
      width = 800,
      height = 600,
      theme = "default",
      outputType: "png" | "svg" | "option" = "png",
    ): Promise<Buffer | string> {
      if (outputType === "svg" || outputType === "option") {
        const chart = echarts.init(null, theme, {
          renderer: "svg",
          ssr: true,
          width,
          height,
        });
    
        chart.setOption({
          ...echartsOption,
          animation: false,
        });
    
        // Output string
        const svgStr = chart.renderToSVGString();
    
        // If the chart is no longer needed, call dispose to free memory
        chart.dispose();
        // Return SVG string or validated ECharts configuration options
        return outputType === "svg"
          ? svgStr
          : JSON.stringify(echartsOption, null, 2);
      }
    
      // Other output types (such as PNG) need to use Canvas
      const canvas = createCanvas(width, height) as unknown as HTMLCanvasElement;
      const chart = echarts.init(canvas, theme, {
        devicePixelRatio: 3,
      });
    
      echarts.setPlatformAPI({
        loadImage(src, onload, onerror) {
          const img = new Image();
          img.onload = onload.bind(img);
          img.onerror = onerror.bind(img);
          img.src = src;
          return img;
        },
      });
    
      chart.setOption({
        ...echartsOption,
        animation: false,
      });
    
      // @ts-ignore
      const buffer = canvas.toBuffer("image/png");
    
      chart.dispose();
    
      return buffer;
    }
Behavior2/5

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

No annotations are provided, and the description only states it 'generates' a chart without any behavioral details such as side effects, permission requirements, or output format. Critical context is missing.

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 sentence that directly states purpose. It is concise and front-loaded, though it could be slightly expanded for clarity.

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

Completeness2/5

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

With 8 parameters, no output schema, and no behavioral context from annotations or description, the description is insufficient for an agent to fully understand the tool's behavior and return value.

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?

The input schema has 100% description coverage for all 8 parameters, providing adequate meaning. The description adds no extra value beyond the schema, so baseline score applies.

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 it generates a gauge chart for single indicator status, but the input schema allows multiple data items for multiple gauges, creating a minor inconsistency. Nonetheless, the verb and resource are specific and distinct from sibling tools.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. The description does not indicate when-not to use it or mention any prerequisite conditions.

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