Skip to main content
Glama

generate_bar_chart

Read-only

Create horizontal bar charts to visualize numerical comparisons across categories, supporting grouped or stacked data with customizable styles and themes.

Instructions

Generate a horizontal bar chart to show data for numerical comparisons among different categories, such as, comparing categorical data and for horizontal comparisons.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesData for bar chart, such as, [{ category: '分类一', value: 10 }, { category: '分类二', value: 20 }], when grouping or stacking is needed for bar, the data should contain a `group` field, such as, when [{ category: '北京', value: 825, group: '油车' }, { category: '北京', value: 1000, group: '电车' }].
groupNoWhether grouping is enabled. When enabled, bar charts require a 'group' field in the data. When `group` is true, `stack` should be false.
stackNoWhether stacking is enabled. When enabled, bar charts require a 'group' field in the data. When `stack` is true, `group` should be false.
styleNoStyle configuration for the chart with a JSON object, optional.
themeNoSet the theme for the chart, optional, default is 'default'.default
widthNoSet the width of chart, default is 600.
heightNoSet the height of chart, default is 400.
titleNoSet the title of chart.
axisXTitleNoSet the x-axis title of chart.
axisYTitleNoSet the y-axis title of chart.

Implementation Reference

  • Generic MCP tool handler that executes generate_bar_chart: maps to chartType='bar', validates args with Charts.bar.schema, generates chart URL via generateChartUrl, returns content with URL and spec metadata.
    export async function callTool(tool: string, args: object = {}) {
      logger.info(`Calling tool: ${tool}`);
      const chartType = CHART_TYPE_MAP[tool as keyof typeof CHART_TYPE_MAP];
    
      if (!chartType) {
        logger.error(`Unknown tool: ${tool}`);
        throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${tool}.`);
      }
    
      try {
        // Validate input using Zod before sending to API.
        // Select the appropriate schema based on the chart type.
        const schema = Charts[chartType].schema;
    
        if (schema) {
          // Use safeParse instead of parse and try-catch.
          const result = z.object(schema).safeParse(args);
          if (!result.success) {
            logger.error(`Invalid parameters: ${result.error.message}`);
            throw new McpError(
              ErrorCode.InvalidParams,
              `Invalid parameters: ${result.error.message}`,
            );
          }
        }
    
        const isMapChartTool = [
          "generate_district_map",
          "generate_path_map",
          "generate_pin_map",
        ].includes(tool);
    
        if (isMapChartTool) {
          // For map charts, we use the generateMap function, and return the mcp result.
          const { metadata, ...result } = await generateMap(tool, args);
          return result;
        }
    
        const url = await generateChartUrl(chartType, args);
        logger.info(`Generated chart URL: ${url}`);
    
        return {
          content: [
            {
              type: "text",
              text: url,
            },
          ],
          _meta: {
            description:
              "This is the chart's spec and configuration, which can be renderred to corresponding chart by AntV GPT-Vis chart components.",
            spec: { type: chartType, ...args },
          },
        };
        // biome-ignore lint/suspicious/noExplicitAny: <explanation>
      } catch (error: any) {
        logger.error(
          `Failed to generate chart: ${error.message || "Unknown error"}.`,
        );
        if (error instanceof McpError) throw error;
        if (error instanceof ValidateError)
          throw new McpError(ErrorCode.InvalidParams, error.message);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to generate chart: ${error?.message || "Unknown error."}`,
        );
      }
    }
  • Defines the input schema using Zod for generate_bar_chart (data array with category/value/group, options for group/stack/style/theme/size/titles) and the tool descriptor with name, description, inputSchema.
    const schema = {
      data: z
        .array(data)
        .describe(
          "Data for bar chart, such as, [{ category: '分类一', value: 10 }, { category: '分类二', value: 20 }], when grouping or stacking is needed for bar, the data should contain a `group` field, such as, when [{ category: '北京', value: 825, group: '油车' }, { category: '北京', value: 1000, group: '电车' }].",
        )
        .nonempty({ message: "Bar chart data cannot be empty." }),
      group: z
        .boolean()
        .optional()
        .default(false)
        .describe(
          "Whether grouping is enabled. When enabled, bar charts require a 'group' field in the data. When `group` is true, `stack` should be false.",
        ),
      stack: z
        .boolean()
        .optional()
        .default(true)
        .describe(
          "Whether stacking is enabled. When enabled, bar charts require a 'group' field in the data. When `stack` is true, `group` should be false.",
        ),
      style: z
        .object({
          backgroundColor: BackgroundColorSchema,
          palette: PaletteSchema,
          texture: TextureSchema,
        })
        .optional()
        .describe(
          "Style configuration for the chart with a JSON object, optional.",
        ),
      theme: ThemeSchema,
      width: WidthSchema,
      height: HeightSchema,
      title: TitleSchema,
      axisXTitle: AxisXTitleSchema,
      axisYTitle: AxisYTitleSchema,
    };
    
    // Bar chart tool descriptor
    const tool = {
      name: "generate_bar_chart",
      description:
        "Generate a horizontal bar chart to show data for numerical comparisons among different categories, such as, comparing categorical data and for horizontal comparisons.",
      inputSchema: zodToJsonSchema(schema),
      annotations: {
        title: "Generate Bar Chart",
        readOnlyHint: true,
      },
    };
  • src/server.ts:64-77 (registration)
    Dynamically registers all chart tools (including generate_bar_chart from Charts.bar.tool) for ListTools and CallTool requests on the MCP server, delegating execution to callTool.
    function setupToolHandlers(server: Server): void {
      logger.info("setting up tool handlers...");
      server.setRequestHandler(ListToolsRequestSchema, async () => ({
        tools: getEnabledTools().map((chart) => chart.tool),
      }));
    
      // biome-ignore lint/suspicious/noExplicitAny: <explanation>
      server.setRequestHandler(CallToolRequestSchema, async (request: any) => {
        logger.info("calling tool", request.params.name, request.params.arguments);
    
        return await callTool(request.params.name, request.params.arguments);
      });
      logger.info("tool handlers set up");
    }
  • Helper function called by callTool to generate the actual bar chart: POSTs {type: 'bar', ...args, source} to vis server API and returns the chart URL.
    export async function generateChartUrl(
      type: string,
      // biome-ignore lint/suspicious/noExplicitAny: <explanation>
      options: Record<string, any>,
    ): Promise<string> {
      const url = getVisRequestServer();
    
      const response = await axios.post(
        url,
        {
          type,
          ...options,
          source: "mcp-server-chart",
        },
        {
          headers: {
            "Content-Type": "application/json",
          },
        },
      );
      const { success, errorMessage, resultObj } = response.data;
    
      if (!success) {
        throw new Error(errorMessage);
      }
    
      return resultObj;
    }
Behavior3/5

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

Annotations provide readOnlyHint=true, indicating this is a safe read operation that doesn't modify data. The description adds that it 'generates' a chart, which aligns with the read-only nature. However, it doesn't disclose important behavioral aspects like whether this creates a file, returns an image URL, generates HTML, or has any rate limits or authentication requirements. With annotations covering the safety profile, the description adds minimal behavioral context beyond what's already implied.

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 reasonably concise at one sentence that directly states the tool's purpose. However, the phrasing 'such as, comparing categorical data and for horizontal comparisons' is somewhat redundant and awkwardly structured. The core information is front-loaded, but the sentence could be more polished and efficient in its expression.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (10 parameters, nested objects) and lack of output schema, the description is minimally adequate. It identifies the tool as a chart generator but doesn't explain what format the output takes (image, URL, HTML, etc.) or provide context about the visualization library or constraints. With rich schema documentation but no output information, the description meets basic requirements but leaves important contextual gaps.

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%, meaning all parameters are well-documented in the schema itself. The description mentions 'data for numerical comparisons among different categories' which hints at the 'data' parameter's purpose, but doesn't add meaningful semantic context beyond what the schema already provides. With comprehensive schema documentation, the baseline score of 3 is appropriate as the description doesn't significantly enhance parameter understanding.

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: 'Generate a horizontal bar chart to show data for numerical comparisons among different categories.' It specifies the chart type (horizontal bar chart) and its use case (numerical comparisons among categories). However, it doesn't explicitly distinguish this tool from its many sibling chart-generation tools beyond mentioning 'horizontal bar chart,' which leaves some ambiguity about when to choose this over other chart types.

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 alternatives. With 24 sibling chart tools available, there's no mention of when a horizontal bar chart is appropriate compared to column charts, line charts, pie charts, or other visualization types. The description only states what the tool does, not when it should be selected over other options.

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/antvis/mcp-server-chart'

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