Skip to main content
Glama

generate_chart

Create customizable charts (bar, line, pie, radar, etc.) using QuickChart.io and Chart.js configurations to visualize data with options for URLs or image downloads.

Instructions

Generate a chart using QuickChart

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesChart type (bar, line, pie, doughnut, radar, polarArea, scatter, bubble, radialGauge, speedometer)
labelsNoLabels for data points
datasetsYes
titleNo
optionsNo

Implementation Reference

  • The handler function for the 'generate_chart' tool. It processes the input arguments, generates the chart configuration, creates a QuickChart URL, and returns the URL as text content. Includes error handling.
    case 'generate_chart': {
      try {
        const config = this.generateChartConfig(request.params.arguments);
        const url = await this.generateChartUrl(config);
        return {
          content: [
            {
              type: 'text',
              text: url
            }
          ]
        };
      } catch (error: any) {
        if (error instanceof McpError) {
          throw error;
        }
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to generate chart: ${error?.message || 'Unknown error'}`
        );
      }
    }
  • src/index.ts:152-196 (registration)
    Tool registration in the ListTools response, including name, description, and detailed input schema for validation.
    {
      name: 'generate_chart',
      description: 'Generate a chart using QuickChart',
      inputSchema: {
        type: 'object',
        properties: {
          type: {
            type: 'string',
            description: 'Chart type (bar, line, pie, doughnut, radar, polarArea, scatter, bubble, radialGauge, speedometer)'
          },
          labels: {
            type: 'array',
            items: { type: 'string' },
            description: 'Labels for data points'
          },
          datasets: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                label: { type: 'string' },
                data: { type: 'array' },
                backgroundColor: { 
                  oneOf: [
                    { type: 'string' },
                    { type: 'array', items: { type: 'string' } }
                  ]
                },
                borderColor: {
                  oneOf: [
                    { type: 'string' },
                    { type: 'array', items: { type: 'string' } }
                  ]
                },
                additionalConfig: { type: 'object' }
              },
              required: ['data']
            }
          },
          title: { type: 'string' },
          options: { type: 'object' }
        },
        required: ['type', 'datasets']
      }
    },
  • TypeScript interface defining the structure of the ChartConfig used throughout the chart generation.
    interface ChartConfig {
      type: string;
      data: {
        labels?: string[];
        datasets: Array<{
          label?: string;
          data: number[];
          backgroundColor?: string | string[];
          borderColor?: string | string[];
          [key: string]: any;
        }>;
        [key: string]: any;
      };
      options?: {
        title?: {
          display: boolean;
          text: string;
        };
        scales?: {
          y?: {
            beginAtZero?: boolean;
          };
        };
        [key: string]: any;
      };
    }
  • Helper function that transforms input arguments into a validated ChartConfig object, with special handling for certain chart types.
    private generateChartConfig(args: any): ChartConfig {
      const { type, labels, datasets, title, options = {} } = args;
      
      this.validateChartType(type);
    
      const config: ChartConfig = {
        type,
        data: {
          labels: labels || [],
          datasets: datasets.map((dataset: any) => ({
            label: dataset.label || '',
            data: dataset.data,
            backgroundColor: dataset.backgroundColor,
            borderColor: dataset.borderColor,
            ...dataset.additionalConfig
          }))
        },
        options: {
          ...options,
          ...(title && {
            title: {
              display: true,
              text: title
            }
          })
        }
      };
    
      // Special handling for specific chart types
      switch (type) {
        case 'radialGauge':
        case 'speedometer':
          if (!datasets?.[0]?.data?.[0]) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `${type} requires a single numeric value`
            );
          }
          config.options = {
            ...config.options,
            plugins: {
              datalabels: {
                display: true,
                formatter: (value: number) => value
              }
            }
          };
          break;
    
        case 'scatter':
        case 'bubble':
          datasets.forEach((dataset: any) => {
            if (!Array.isArray(dataset.data[0])) {
              throw new McpError(
                ErrorCode.InvalidParams,
                `${type} requires data points in [x, y${type === 'bubble' ? ', r' : ''}] format`
              );
            }
          });
          break;
      }
    
      return config;
    }
  • Helper function that generates the QuickChart URL from the ChartConfig by encoding it as a query parameter.
    private async generateChartUrl(config: ChartConfig): Promise<string> {
      const encodedConfig = encodeURIComponent(JSON.stringify(config));
      return `${QUICKCHART_BASE_URL}?c=${encodedConfig}`;
    }
Behavior2/5

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

With no annotations, the description carries the full burden of behavioral disclosure. It mentions 'generate' but doesn't specify output format (e.g., URL, image data), error handling, or performance aspects like rate limits. This leaves critical behavioral traits undocumented.

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 with a single sentence, front-loaded and free of redundancy. Every word serves a purpose, making it efficient for quick understanding.

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?

Given the complexity (5 parameters with nested objects, no output schema, and no annotations), the description is inadequate. It doesn't explain the output, error cases, or parameter interactions, leaving the agent with insufficient context for effective tool use.

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

Parameters2/5

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

Schema description coverage is low at 40%, with only 'type' and 'labels' having descriptions. The description adds no parameter details, failing to compensate for the coverage gap. For example, it doesn't explain 'datasets' structure or 'options' usage, leaving key parameters unclear.

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 action ('generate') and resource ('chart using QuickChart'), providing a specific purpose. However, it doesn't differentiate from the sibling tool 'download_chart', which likely handles chart retrieval rather than creation.

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 lacks context about prerequisites, such as data formatting or when to choose this over 'download_chart', leaving the agent without usage direction.

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/Magic-Sauce/Quickchart-MCP-Server'

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