Skip to main content
Glama

create-chart-using-googlecharts

Generate chart images from Google Charts code, providing URLs for sharing or saving files locally for integration.

Instructions

Create charts using Google Charts - 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)
codeYesJavaScript drawChart function code
packagesNoGoogle Charts packages to load (default: 'corechart')
widthNoChart width in pixels
heightNoChart height in pixels
mapsApiKeyNoGoogle Maps API key (for geo charts)

Implementation Reference

  • Main handler function implementing the tool logic: input validation, chart generation using QuickChart Google Charts API, image fetching, base64 encoding, and optional file saving.
    export async function handleGoogleChartsTool(args: any): Promise<any> {
      const code = args.code as string;
      const action = args.action as string;
      
      validateCode(code);
      validateAction(action);
      validateOutputPath(args.outputPath, action);
      validatePackages(args.packages);
      validateDimensions(args.width, args.height);
      validateMapsApiKey(args.mapsApiKey);
    
      const postConfig = buildGoogleChartsConfig(code, {
        packages: args.packages as string,
        width: args.width as number,
        height: args.height as number,
        mapsApiKey: args.mapsApiKey as string,
      });
      const chartUrl = buildGoogleChartsUrl(code);
    
      const result: any = {
        content: [
          {
            type: "text",
            text: "Below is the chart URL:",
          },
          {
            type: "text",
            text: chartUrl,
          },
        ],
        metadata: {
          chartType: args.packages || "corechart",
          generatedAt: new Date().toISOString(),
          chartUrl: chartUrl,
        },
      };
    
      try {
        const pngData = await fetchGoogleChartsContent(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 fetchGoogleChartsContent(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)
          }`
        );
      }
    }
  • Tool definition with input schema for parameters like action, code, outputPath, dimensions, etc.
    export const CREATE_CHART_USING_GOOGLECHARTS_TOOL: Tool = {
      name: "create-chart-using-googlecharts",
      description:
        "Create charts using Google Charts - 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)",
          },
          code: {
            type: "string",
            description: "JavaScript drawChart function code",
          },
          packages: {
            type: "string",
            description: "Google Charts packages to load (default: 'corechart')",
          },
          width: {
            type: "integer",
            description: "Chart width in pixels",
          },
          height: {
            type: "integer",
            description: "Chart height in pixels",
          },
          mapsApiKey: {
            type: "string",
            description: "Google Maps API key (for geo charts)",
          },
        },
        required: ["action", "code"],
      },
    };
  • Registration of the tool handler in the central tool handlers mapping.
    "create-chart-using-googlecharts": {
      handler: handleGoogleChartsTool,
      toolName: ToolNames.GOOGLECHARTS,
    },
  • Inclusion of the tool in the ALL_TOOLS array for conditional enabling.
    { tool: CREATE_CHART_USING_GOOGLECHARTS_TOOL, name: ToolNames.GOOGLECHARTS },
    { 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?

With no annotations provided, the description carries full burden but provides minimal behavioral information. It mentions the two action outcomes but doesn't describe authentication needs (mapsApiKey suggests some charts may require API keys), rate limits, error conditions, or what happens when saving files (overwrite behavior, file format).

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?

Extremely concise single sentence that efficiently communicates the core functionality. Every word earns its place with no wasted text. The description is front-loaded with the main purpose followed by the two action outcomes.

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 7 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns (URL format for get_url, success indicators for save_file), doesn't mention the JavaScript code requirements, and provides no context about the Google Charts ecosystem or limitations.

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 schema already documents all 7 parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

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 using Google Charts' with two specific actions (get URL or save file). It distinguishes from siblings by specifying the Google Charts library, but doesn't explicitly contrast with other chart creation tools like create-chart-using-apexcharts or create-chart-using-chartjs.

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. The description mentions the two action types but doesn't provide context for choosing between them or when to prefer Google Charts over other chart libraries available as sibling tools.

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