Skip to main content
Glama
GongRzhe

Quickchart-MCP-Server

by GongRzhe

generate_chart

Create customizable data visualizations using QuickChart.io, supporting multiple chart types like bar, line, pie, and radar charts with Chart.js configuration.

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

  • Main execution handler for the 'generate_chart' tool. Processes arguments, generates chart configuration, creates QuickChart URL, and returns it as text content.
    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'}`
        );
      }
    }
  • Input schema defining the parameters for the 'generate_chart' tool, including type, labels, datasets, title, and options.
      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']
    }
  • src/index.ts:183-227 (registration)
    Tool registration in the ListTools response, including name, description, and input schema.
    {
      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']
      }
    },
  • Helper method that validates and normalizes input arguments into a ChartConfig object, including chart type validation and special handling for certain types.
    private generateChartConfig(args: any): ChartConfig {
      // Add defensive checks to handle possibly malformed input
      if (!args) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'No arguments provided to generateChartConfig'
        );
      }
      
      if (!args.type) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Chart type is required'
        );
      }
      
      if (!args.datasets || !Array.isArray(args.datasets)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Datasets must be a non-empty array'
        );
      }
      
      const { type, labels, datasets, title, options = {} } = args;
      
      this.validateChartType(type);
    
      const config: ChartConfig = {
        type,
        data: {
          labels: labels || [],
          datasets: datasets.map((dataset: any) => {
            if (!dataset || !dataset.data) {
              throw new McpError(
                ErrorCode.InvalidParams,
                'Each dataset must have a data property'
              );
            }
            return {
              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 method that encodes the ChartConfig as JSON and constructs the QuickChart URL.
    private async generateChartUrl(config: ChartConfig): Promise<string> {
      const encodedConfig = encodeURIComponent(JSON.stringify(config));
      return `${QUICKCHART_BASE_URL}?c=${encodedConfig}`;
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but provides minimal information. It mentions 'using QuickChart' which hints at an external service dependency, but doesn't describe what the tool actually returns (e.g., URL, image data, error handling), rate limits, authentication needs, or whether it's a read-only or mutating operation. For a tool with complex parameters and no annotations, this is inadequate.

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 just 4 words, with zero wasted language. It's front-loaded with the core functionality and uses minimal space to convey the basic purpose. Every word earns its place in this brief description.

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?

For a tool with 5 parameters (including complex nested objects), no annotations, no output schema, and a sibling tool, the description is severely incomplete. It doesn't explain what the tool returns, how to interpret results, error conditions, or how it differs from the sibling 'download_chart' tool. The minimal description leaves too many gaps for effective agent usage.

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?

With only 40% schema description coverage, the description doesn't compensate by explaining any of the 5 parameters. The schema provides some parameter descriptions (like 'labels for data points' and 'chart type'), but the description adds no additional semantic context about what parameters mean, how they interact, or what values are expected beyond what's in the schema.

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'), making the purpose immediately understandable. However, it doesn't differentiate from the sibling 'download_chart' tool, which appears to be a related but distinct operation. The description is specific about what the tool does but lacks sibling differentiation.

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?

The description provides no guidance on when to use this tool versus the sibling 'download_chart' tool, nor does it mention any prerequisites, constraints, or alternative approaches. There's no indication of when this tool is appropriate versus other chart generation methods or the sibling tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools