Skip to main content
Glama
VisActor

vchart-mcp-server

Official
by VisActor

generate_hierarchical_chart

Create hierarchical charts to visualize multi-level categorical data proportions using sunburst, treemap, or circle packing layouts.

Instructions

Generate a chart for hierarchical visualization of multi-level categorical data proportions, include sunburst, treemap, circle_packing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outputNoChart output type. Defaults to 'image'.image
chartTypeYesChart type
widthNoChart width. Optional, defaults to 500.
heightNoChart height. Optional, defaults to 500.
dataTableYesHierarchical data for the chart, e.g., [{ category: 'Category 0', subCategory: 'Category 01', value: 10}].
colorFieldYes
valueFieldYesMeasure field. Must be numeric and exist in the data.
chartThemeNoChart theme. Optional, defaults to 'light'.
titleNoChart title text.
subTitleNoChart subtitle text.
titleOrientNoTitle position in the chart.
backgroundNoChart background color (hex). Optional, defaults to white.
colorsNoColor palette for chart elements.

Implementation Reference

  • MCP CallToolRequest handler that executes all chart generation tools. For 'generate_hierarchical_chart', it resolves to the 'sunburst' chart type, validates arguments using the tool's Zod schema, calls generateChartByType('sunburst', args), and returns the result (spec, image URL, or HTML).
    server.setRequestHandler(CallToolRequestSchema, async request => {
      const toolName = request.params.name;
      const chartType = Object.keys(Charts).find(
        key => (Charts as any)[key].tool.name === toolName
      );
    
      if (!chartType) {
        throw new McpError(
          ErrorCode.MethodNotFound,
          `Unknown tool: ${request.params.name}.`
        );
      }
    
      try {
        // Validate input using Zod before generating chart
        const args = request.params.arguments || {};
    
        // Select the appropriate schema based on the chart type
        const schema = Charts[chartType as keyof typeof Charts].schema;
    
        if (schema) {
          const result = schema.safeParse(args);
          if (!result.success) {
            throw new McpError(
              ErrorCode.InvalidParams,
              `Invalid parameters: ${result.error.message}`
            );
          }
        }
    
        const res = await generateChartByType(chartType, args);
    
        if (res && (res as any).spec) {
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify((res as any).spec, null, 2),
              },
            ],
          };
        }
    
        if (res && (res as any).image) {
          return {
            content: [
              {
                type: 'text',
                text: (res as any).image,
              },
            ],
          };
        }
    
        if (res && (res as any).html) {
          return {
            content: [
              {
                type: 'text',
                text: (res as any).html,
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: 'Failed to generate chart',
            },
          ],
        };
      } catch (error: any) {
        if (error instanceof McpError) {
          throw error;
        }
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to generate chart: ${error?.message || 'Unknown error.'}`
        );
      }
    });
  • Zod input schema for the generate_hierarchical_chart tool, defining parameters like chartType (sunburst/treemap/circle_packing), dataTable, fields, styling options, etc. Used for validation in the handler.
    const schema = z.object({
      output: ChartOutputSchema,
      chartType: z
        .enum(["sunburst", "treemap", "circle_packing"])
        .describe("Chart type"),
    
      width: WidthSchema,
      height: HeightSchema,
      dataTable: z
        .array(z.any())
        .describe(
          "Hierarchical data for the chart, e.g., [{ category: 'Category 0', subCategory: 'Category 01', value: 10}]."
        )
        .nonempty({ message: "Data cannot be empty." }),
    
      colorField: z.array(XFieldSchema).nonempty(),
      valueField: YFieldSchema,
    
      chartTheme: ThemeSchema,
      title: TitleTextSchema,
      subTitle: TitleSubTextSchema,
      titleOrient: TitleOrientSchema,
    
      background: BackgroundSchema,
      colors: ColorsSchema,
    });
  • src/server.ts:34-38 (registration)
    MCP ListToolsRequest handler that registers all chart tools by collecting .tool objects from imported Charts modules (including sunburst.tool for generate_hierarchical_chart).
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: Object.values(Charts).map(chart => (chart as any).tool),
      };
    });
  • Helper function invoked by the tool handler to generate the VChart spec using @visactor/generate-vchart for the given chartType ('sunburst' etc. for hierarchical charts) and options, then renders to image or HTML via external server.
    export async function generateChartByType(chartType: string, options: any) {
      const {
        title,
        subTitle,
        titleOrient,
        xAxisType,
        xAxisOrient,
        xAxisTitle,
        xAxisHasGrid,
        xAxisHasLabel,
        xAxisHasTick,
    
        yAxisType,
        yAxisOrient,
        yAxisTitle,
        yAxisHasGrid,
        yAxisHasLabel,
        yAxisHasTick,
    
        leftYAxisTitle,
        leftYAxisHasGrid,
        leftYAxisHasLabel,
        leftYAxisHasTick,
    
        rightYAxisTitle,
        rightYAxisHasGrid,
        rightYAxisHasLabel,
        rightYAxisHasTick,
    
        angleAxisTitle,
        angleAxisHasGrid,
        angleAxisHasLabel,
        angleAxisHasTick,
        angleAxisType,
    
        radiusAxisHasGrid,
        radiusAxisHasLabel,
        radiusAxisHasTick,
        radiusAxisType,
        radiusAxisTitle,
    
        output,
        width,
        height,
        ...res
      } = options;
    
      const opts = { ...res };
      const titleObj = filterValidAttributes({
        text: title,
        subText: subTitle,
        orient: titleOrient,
      });
      const xAxisObj = filterValidAttributes({
        type: xAxisType,
        orient: xAxisOrient,
        title: xAxisTitle,
        hasGrid: xAxisHasGrid,
        hasLabel: xAxisHasLabel,
        hasTick: xAxisHasTick,
      });
      const yAxisObj = filterValidAttributes({
        type: yAxisType,
        orient: yAxisOrient,
        title: yAxisTitle,
        hasGrid: yAxisHasGrid,
        hasLabel: yAxisHasLabel,
        hasTick: yAxisHasTick,
      });
      const leftYAxisObj = filterValidAttributes({
        title: leftYAxisTitle,
        hasGrid: leftYAxisHasGrid,
        hasLabel: leftYAxisHasLabel,
        hasTick: leftYAxisHasTick,
      });
      const rightYAxisObj = filterValidAttributes({
        title: rightYAxisTitle,
        hasGrid: rightYAxisHasGrid,
        hasLabel: rightYAxisHasLabel,
        hasTick: rightYAxisHasTick,
      });
      const angleAxisObj = filterValidAttributes({
        title: angleAxisTitle,
        hasGrid: angleAxisHasGrid,
        hasLabel: angleAxisHasLabel,
        hasTick: angleAxisHasTick,
        type: angleAxisType,
      });
      const radiusAxisObj = filterValidAttributes({
        hasGrid: radiusAxisHasGrid,
        hasLabel: radiusAxisHasLabel,
        hasTick: radiusAxisHasTick,
        type: radiusAxisType,
        title: radiusAxisTitle,
      });
    
      const cell: Record<string, string> = {};
    
      [
        "xField",
        "yField",
        "colorField",
        "categoryField",
        "valueField",
        "wordField",
        "sizeField",
        "timeField",
        "sourceField",
        "targetField",
        "setsField",
        "radiusField",
      ].forEach((fieldName) => {
        if (isValid(options[fieldName])) {
          cell[fieldName.replace("Field", "")] = options[fieldName];
          delete opts[fieldName];
        }
      });
    
      opts.cell = cell;
    
      if (!isEmpty(titleObj)) {
        opts.title = titleObj;
      }
    
      const axes = [
        xAxisObj,
        yAxisObj,
        leftYAxisObj,
        rightYAxisObj,
        angleAxisObj,
        radiusAxisObj,
      ];
    
      if (axes.some((axis) => !isEmpty(axis))) {
        opts.axes = axes.filter((axis) => !isEmpty(axis));
      }
    
      const { spec } = generateChart(options.chartType ?? chartType, opts);
    
      if (!spec) {
        return null;
      }
    
      if (output === "spec") {
        if (isValid(width)) {
          spec.width = width;
        }
        if (isValid(height)) {
          spec.height = height;
        }
    
        return {
          spec: spec,
        };
      }
    
      return gentrateChartImageOrHtml(output, spec, {
        width: `${width ?? 500}px`,
        height: `${height ?? 500}px`,
      });
    }
  • Tool registration object defining name, description, and JSON schema (converted from Zod), exported as part of sunburst.tool for use in MCP server tool listing and lookup.
    const tool = {
      name: "generate_hierarchical_chart",
      description:
        "Generate a chart for hierarchical visualization of multi-level categorical data proportions, include sunburst, treemap, circle_packing.",
      inputSchema: convertZodToJsonSchema(schema),
    };
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe how it behaves: no information about performance characteristics, error handling, whether it generates files or returns data, authentication needs, or rate limits. For a complex chart generation tool, this leaves significant gaps.

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 appropriately concise with a single sentence that efficiently communicates the core functionality. It's front-loaded with the main purpose and includes the chart types. However, the comma-separated list of chart types at the end feels slightly tacked on rather than integrated.

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 complex tool with 13 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns (image file? HTML string? visualization object?), doesn't address error conditions, and provides no guidance on the hierarchical data structure requirements beyond what's in the schema.

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 92%, so the schema already documents most parameters thoroughly. The description adds minimal value beyond the schema - it mentions 'multi-level categorical data proportions' which hints at the hierarchical nature of dataTable, but doesn't explain parameter relationships or provide additional context not in the schema descriptions.

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 chart for hierarchical visualization of multi-level categorical data proportions' with specific chart types listed. It uses a clear verb ('Generate') and resource ('chart'), but doesn't explicitly differentiate from sibling tools like generate_sankey_chart or generate_wordcloud_venn, which might also handle hierarchical data.

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. It doesn't mention sibling tools, doesn't specify scenarios where hierarchical charts are appropriate, and offers no exclusions or prerequisites. The agent must infer usage from the description alone.

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/VisActor/vchart-mcp-server'

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