Skip to main content
Glama

create-chart-using-natural-language

Generate charts by describing them in plain English, then get a shareable URL or save the image file directly.

Instructions

Create charts from natural language descriptions - get chart image URL or save chart image to file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesWhether to get chart URL or save as file
outputPathNoPath where to save the file (only used with action=save_file)
descriptionYesNatural language chart description
widthNoChart width in pixels
heightNoChart height in pixels
backgroundColorNoBackground color
data1NoFirst dataset values (comma-separated)
data2NoSecond dataset values (comma-separated)
labelsNoData labels (comma-separated)
titleNoChart title

Implementation Reference

  • The primary handler function for the 'create-chart-using-natural-language' tool. Validates input parameters, constructs the chart configuration from natural language description, fetches the PNG image from QuickChart's text-to-chart API, embeds the base64 image in the response, and optionally saves the image to a file.
    export async function handleTextChartTool(args: any): Promise<any> {
      const description = args.description as string;
      const action = args.action as string;
      
      validateDescription(description);
      validateAction(action);
      validateOutputPath(args.outputPath, action);
      validateDimensions(args.width, args.height);
      validateBackgroundColor(args.backgroundColor);
      validateDataString(args.data1, "Data1");
      validateDataString(args.data2, "Data2");
      validateDataString(args.labels, "Labels");
      validateDataString(args.title, "Title");
    
      const postConfig = buildTextChartConfig(description, {
        width: args.width as number,
        height: args.height as number,
        backgroundColor: args.backgroundColor as string,
        data1: args.data1 as string,
        data2: args.data2 as string,
        labels: args.labels as string,
        title: args.title as string,
      });
      const chartUrl = buildTextChartUrl(description);
    
      const result: any = {
        content: [
          {
            type: "text",
            text: "Below is the chart URL:",
          },
          {
            type: "text",
            text: chartUrl,
          },
        ],
        metadata: {
          chartType: "natural-language",
          generatedAt: new Date().toISOString(),
          chartUrl: chartUrl,
        },
      };
    
      try {
        const pngData = await fetchTextChartContent(postConfig, "png");
        const pngBase64 = Buffer.from(pngData).toString("base64");
    
        result.content.push(
          {
            type: "text",
            text: "Below is the PNG image:",
          },
          {
            type: "image",
            data: pngBase64,
            mimeType: "image/png",
          }
        );
        result.metadata.pngBase64 = pngBase64;
      } catch (error) {
        result.content.unshift({
          type: "text",
          text: "⚠️ Failed to fetch chart image",
        });
        result.content.push({
          type: "text",
          text: `Error: ${error instanceof Error ? error.message : String(error)}`,
        });
        result.metadata.error =
          error instanceof Error ? error.message : String(error);
      }
    
      if (action === "get_url") {
        return result;
      }
    
      const format = "png";
      const outputPath = getDownloadPath(
        args.outputPath as string | undefined,
        format
      );
    
      try {
        const dir = path.dirname(outputPath);
        if (!fs.existsSync(dir)) {
          fs.mkdirSync(dir, { recursive: true });
        }
    
        const data = await fetchTextChartContent(postConfig, format);
        fs.writeFileSync(outputPath, data);
    
        result.metadata.savedPath = outputPath;
        result.content.push({
          type: "text",
          text: "Below is the saved file path:",
        });
        result.content.push({
          type: "text",
          text: outputPath,
        });
        return result;
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to save chart: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • Defines the Tool object with name, description, and detailed inputSchema for parameters including action (get_url/save_file), required description, optional dimensions, data sets, labels, title, and output path.
    export const CREATE_CHART_USING_NATURAL_LANGUAGE_TOOL: Tool = {
      name: "create-chart-using-natural-language",
      description:
        "Create charts from natural language descriptions - get chart image URL or save chart image to file",
      inputSchema: {
        type: "object",
        properties: {
          action: {
            type: "string",
            enum: ["get_url", "save_file"],
            description: "Whether to get chart URL or save as file",
          },
          outputPath: {
            type: "string",
            description:
              "Path where to save the file (only used with action=save_file)",
          },
          description: {
            type: "string",
            description: "Natural language chart description",
          },
          width: {
            type: "integer",
            description: "Chart width in pixels",
          },
          height: {
            type: "integer",
            description: "Chart height in pixels",
          },
          backgroundColor: {
            type: "string",
            description: "Background color",
          },
          data1: {
            type: "string",
            description: "First dataset values (comma-separated)",
          },
          data2: {
            type: "string",
            description: "Second dataset values (comma-separated)",
          },
          labels: {
            type: "string",
            description: "Data labels (comma-separated)",
          },
          title: {
            type: "string",
            description: "Chart title",
          },
        },
        required: ["action", "description"],
      },
    };
  • Imports the tool definition (schema) and handler function from the implementation file textchart.ts for registration.
      CREATE_CHART_USING_NATURAL_LANGUAGE_TOOL,
      handleTextChartTool,
    } from "./textchart.js";
  • Registers the tool name to its handler function in the ALL_TOOL_HANDLERS record, which is filtered and used to create the TOOL_HANDLERS export.
    "create-chart-using-natural-language": {
      handler: handleTextChartTool,
      toolName: ToolNames.TEXTCHART,
    },
  • Adds the tool to the ALL_TOOLS array, which is filtered by enabled tools to create the exported TOOLS array.
    { tool: CREATE_CHART_USING_NATURAL_LANGUAGE_TOOL, name: ToolNames.TEXTCHART },
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the two possible actions (get URL or save file) but doesn't disclose important behavioral traits: what format the chart image is (PNG, SVG, etc.), whether there are rate limits, authentication requirements, error handling, or what the URL/file output looks like.

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 efficiently structured in a single sentence that covers the core functionality and two main outcomes. It's appropriately sized for the tool's complexity, though it could be slightly more front-loaded with the primary purpose.

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 10-parameter tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns (beyond mentioning URL or file save), doesn't cover error cases, and provides no context about the chart generation process or limitations of the natural language approach.

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 description coverage is 100%, so the baseline is 3. The description adds minimal value beyond the schema - it mentions 'natural language descriptions' which aligns with the 'description' parameter, but doesn't provide additional context about parameter interactions or usage examples.

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 tool's purpose: 'Create charts from natural language descriptions' with specific outcomes ('get chart image URL or save chart image to file'). It distinguishes from some siblings (e.g., create-barcode, create-qr-code) by focusing on charts, but doesn't differentiate from other chart-creation siblings like create-chart-using-apexcharts.

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 on when to use this tool versus alternatives like create-chart-using-apexcharts or create-chart-using-chartjs. The description mentions the action parameter options but doesn't provide context for choosing between them or when this natural language approach is preferable.

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/TakanariShimbo/quickchart-mcp-server'

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