Skip to main content
Glama

download_chart

Save chart images locally by providing Chart.js configurations and output paths for various chart types like bar, line, and pie charts.

Instructions

Download a chart image to a local file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
configYesChart configuration object
outputPathYesPath where the chart image should be saved

Implementation Reference

  • Handler for the 'download_chart' tool. Parses arguments, generates chart config and URL using helpers, downloads the image with axios, saves to outputPath using fs.promises.writeFile, and returns success message.
    case 'download_chart': {
      try {
        const { config, outputPath } = request.params.arguments as { 
          config: Record<string, unknown>;
          outputPath: string;
        };
        const chartConfig = this.generateChartConfig(config);
        const url = await this.generateChartUrl(chartConfig);
        
        const response = await axios.get(url, { responseType: 'arraybuffer' });
        const fs = await import('fs');
        await fs.promises.writeFile(outputPath, response.data);
        
        return {
          content: [
            {
              type: 'text',
              text: `Chart saved to ${outputPath}`
            }
          ]
        };
      } catch (error: any) {
        if (error instanceof McpError) {
          throw error;
        }
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to download chart: ${error?.message || 'Unknown error'}`
        );
      }
    }
  • Input schema for download_chart tool, defining required 'config' object and 'outputPath' string.
    inputSchema: {
      type: 'object',
      properties: {
        config: {
          type: 'object',
          description: 'Chart configuration object'
        },
        outputPath: {
          type: 'string',
          description: 'Path where the chart image should be saved'
        }
      },
      required: ['config', 'outputPath']
    }
  • src/index.ts:197-214 (registration)
    Tool registration entry in ListTools response, including name, description, and input schema.
    {
      name: 'download_chart',
      description: 'Download a chart image to a local file',
      inputSchema: {
        type: 'object',
        properties: {
          config: {
            type: 'object',
            description: 'Chart configuration object'
          },
          outputPath: {
            type: 'string',
            description: 'Path where the chart image should be saved'
          }
        },
        required: ['config', 'outputPath']
      }
    }
  • Key helper function used by download_chart to validate and construct the ChartConfig from the input config argument.
    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;
    }
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