Skip to main content
Glama
gianlucamazza

MCP ASCII Charts

create_line_chart

Generate ASCII line charts to visualize temporal data trends in terminal environments using numeric arrays and optional labels.

Instructions

Generate ASCII line charts for temporal data visualization

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYesArray of numeric values to plot
labelsNoOptional labels for x-axis (must match data length)
titleNoOptional chart title
widthNoChart width (10-200, default: 60)
heightNoChart height (5-50, default: 15)
colorNoANSI color name (red, green, blue, yellow, etc.)

Implementation Reference

  • Core handler function that implements the ASCII line chart generation. Handles data validation, grid setup, axis drawing, point plotting, line interpolation using a custom drawLine function, coloring, and formatting.
    export function createLineChart(data: ChartData): ChartResult {
      const { data: values, labels, title, width = 60, height = 15, color = 'white' } = data;
      
      if (values.length === 0) {
        throw new Error('Data array cannot be empty');
      }
    
      const chartWidth = width - 10; // Reserve space for y-axis labels
      const chartHeight = height - 2; // Reserve space for x-axis
      
      const minValue = Math.min(...values);
      const maxValue = Math.max(...values);
      const valueRange = maxValue - minValue;
      
      // Create the chart grid
      const grid = createGrid(width, height);
      
      // Draw y-axis labels and grid lines
      for (let y = 0; y < chartHeight; y++) {
        const value = maxValue - (y / (chartHeight - 1)) * valueRange;
        const label = value.toFixed(1);
        const labelStr = padLeft(label, 8);
        
        // Place y-axis label
        for (let i = 0; i < Math.min(labelStr.length, 8); i++) {
          if (8 - i < width) {
            grid[y][8 - i] = labelStr[i];
          }
        }
        
        // Draw y-axis line
        if (9 < width) {
          grid[y][9] = y === chartHeight - 1 ? ASCII_CHARS.bottomLeft : 
                       y === 0 ? ASCII_CHARS.topLeft : ASCII_CHARS.teeRight;
        }
        
        // Draw horizontal grid lines (optional light lines)
        for (let x = 10; x < width; x++) {
          if (y === chartHeight - 1) {
            grid[y][x] = ASCII_CHARS.horizontal;
          } else if (y % 2 === 0) {
            grid[y][x] = '·'; // Light grid dots
          }
        }
      }
      
      // Draw x-axis labels
      if (labels && labels.length === values.length) {
        // const labelSpacing = Math.max(1, Math.floor(chartWidth / Math.min(labels.length, 8)));
        for (let i = 0; i < labels.length && i < 8; i++) {
          const x = 10 + Math.floor((i / (labels.length - 1)) * (chartWidth - 1));
          const label = labels[i].substring(0, 6); // Truncate long labels
          
          if (x + label.length <= width && height - 1 >= 0) {
            for (let j = 0; j < label.length && x + j < width; j++) {
              grid[height - 1][x + j] = label[j];
            }
          }
        }
      }
      
      // Plot the line
      const plotPoints: { x: number; y: number }[] = [];
      
      for (let i = 0; i < values.length; i++) {
        const x = values.length === 1 ? 
          10 + Math.floor(chartWidth / 2) : 
          10 + Math.floor((i / (values.length - 1)) * (chartWidth - 1));
        const normalizedValue = valueRange === 0 ? 0.5 : normalize(values[i], minValue, maxValue);
        const y = Math.floor((1 - normalizedValue) * (chartHeight - 1));
        
        plotPoints.push({ x: clamp(x, 10, width - 1), y: clamp(y, 0, chartHeight - 1) });
      }
      
      // Draw line segments between points
      for (let i = 0; i < plotPoints.length; i++) {
        const point = plotPoints[i];
        
        // Draw the point
        if (point.x < width && point.y < chartHeight) {
          grid[point.y][point.x] = '●';
        }
        
        // Draw line to next point
        if (i < plotPoints.length - 1) {
          const nextPoint = plotPoints[i + 1];
          drawLine(grid, point.x, point.y, nextPoint.x, nextPoint.y, chartWidth, chartHeight);
        }
      }
      
      // Convert grid to string and apply coloring
      let chart = gridToString(grid);
      
      if (color !== 'white') {
        chart = colorize(chart, color);
      }
      
      // Add title if provided
      if (title) {
        const titleLine = center(title, width);
        chart = titleLine + '\n' + chart;
      }
      
      return {
        chart,
        title,
        dimensions: { width, height }
      };
    }
  • src/index.ts:339-346 (registration)
    Tool dispatch/registration in the generateChart switch statement, calling the createLineChart handler with validated chartData.
    case 'create_line_chart': {
      progress.nextStep('Generating line chart');
      result = await withRequestTracking(
        () => Promise.resolve(createLineChart(chartData)),
        'create_line_chart'
      )();
      break;
    }
  • MCP tool input schema definition for 'create_line_chart', specifying parameters, types, descriptions, constraints, and examples.
    type: 'object',
    properties: {
      data: {
        type: 'array',
        items: { type: 'number' },
        description: 'Array of numeric values to plot'
      },
      labels: {
        type: 'array',
        items: { type: 'string' },
        description: 'Optional labels for x-axis (must match data length)',
        optional: true
      },
      title: {
        type: 'string',
        description: 'Optional chart title',
        optional: true
      },
      width: {
        type: 'number',
        description: 'Chart width (10-200, default: 60)',
        minimum: 10,
        maximum: 200,
        optional: true
      },
      height: {
        type: 'number',
        description: 'Chart height (5-50, default: 15)',
        minimum: 5,
        maximum: 50,
        optional: true
      },
      color: {
        type: 'string',
        description: 'ANSI color name (red, green, blue, yellow, etc.)',
        optional: true
      }
    },
    required: ['data'],
    examples: getToolExamples('create_line_chart')
  • TypeScript interface defining the ChartData input structure used by the handler and validation.
    export interface ChartData {
      data: number[];
      labels?: string[];
      title?: string;
      width?: number;
      height?: number;
      color?: string;
    }
  • Helper function implementing line drawing algorithm for connecting data points in the chart.
    function drawLine(
      grid: string[][],
      x1: number,
      y1: number,
      x2: number,
      y2: number,
      maxWidth: number,
      maxHeight: number
    ): void {
      const dx = Math.abs(x2 - x1);
      const dy = Math.abs(y2 - y1);
      const sx = x1 < x2 ? 1 : -1;
      const sy = y1 < y2 ? 1 : -1;
      let err = dx - dy;
      
      let x = x1;
      let y = y1;
      
      // eslint-disable-next-line no-constant-condition
      while (true) {
        // Draw line character based on direction
        if (x >= 10 && x < maxWidth + 10 && y >= 0 && y < maxHeight) {
          if (grid[y][x] === ' ' || grid[y][x] === '·') {
            if (dx > dy) {
              grid[y][x] = ASCII_CHARS.horizontal;
            } else if (dy > dx) {
              grid[y][x] = ASCII_CHARS.vertical;
            } else {
              grid[y][x] = x < x2 ? ASCII_CHARS.curveUpRight : ASCII_CHARS.curveUpLeft;
            }
          }
        }
        
        if (x === x2 && y === y2) break;
        
        const e2 = 2 * err;
        if (e2 > -dy) {
          err -= dy;
          x += sx;
        }
        if (e2 < dx) {
          err += dx;
          y += sy;
        }
      }
    }
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 ('Generate ASCII line charts') but doesn't describe important behavioral aspects like output format (ASCII text), whether it's read-only or has side effects, error handling, or performance characteristics. The description is minimal and lacks behavioral context.

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?

The description is a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized and front-loaded with the essential information. Every word earns its place in this concise formulation.

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 6 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the output looks like (ASCII format), doesn't mention behavioral constraints, and provides minimal context about when to use it. The description should do more to compensate for the lack of structured metadata.

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 6 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. According to guidelines, when schema coverage is high (>80%), the baseline is 3 even with no param info in description.

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 with a specific verb ('Generate') and resource ('ASCII line charts'), and specifies the use case ('for temporal data visualization'). However, it doesn't explicitly differentiate from sibling tools like create_bar_chart or create_scatter_plot, which would require a 5.

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 its siblings (create_bar_chart, create_histogram, create_scatter_plot, create_sparkline). It mentions 'temporal data visualization' which implies time-series data, but doesn't explicitly state when to choose line charts over other chart types or when not to use it.

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/gianlucamazza/mcp-ascii-charts'

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