Skip to main content
Glama

validate_spec

Validate Vega-Lite JSON specifications to identify and correct errors in data visualization configurations.

Instructions

Validate a Vega-Lite specification and check for errors

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
specYesVega-Lite JSON specification to validate

Implementation Reference

  • Core implementation of the validate_spec tool: async function that validates Vega-Lite spec for required properties, valid marks, encoding channels/types, data presence, and schema.
    export async function validateSpec(
      spec: Record<string, unknown>
    ): Promise<ValidationResult> {
      const errors: string[] = [];
      const warnings: string[] = [];
    
      // Check required top-level properties
      if (!spec.$schema) {
        errors.push("Missing required property: $schema");
      }
    
      if (!spec.mark && !spec.layer && !spec.hconcat && !spec.vconcat && !spec.concat) {
        errors.push("Missing required property: must have one of 'mark', 'layer', 'hconcat', 'vconcat', or 'concat'");
      }
    
      if (!spec.data) {
        warnings.push("No data specified - spec may not render without data");
      }
    
      // Check mark type if present
      if (spec.mark) {
        const validMarks = [
          "arc",
          "area",
          "bar",
          "circle",
          "geoshape",
          "image",
          "line",
          "point",
          "rect",
          "rule",
          "square",
          "text",
          "tick",
          "trail",
        ];
    
        const markType = typeof spec.mark === "string" ? spec.mark : (spec.mark as any)?.type;
    
        if (markType && !validMarks.includes(markType)) {
          errors.push(`Invalid mark type: '${markType}'. Valid types are: ${validMarks.join(", ")}`);
        }
      }
    
      // Check encoding channels
      if (spec.encoding) {
        const encoding = spec.encoding as Record<string, unknown>;
        const validChannels = [
          "x", "y", "x2", "y2",
          "color", "fill", "stroke",
          "opacity", "fillOpacity", "strokeOpacity",
          "size", "shape", "angle", "radius", "theta",
          "text", "tooltip", "href", "url",
          "row", "column", "facet",
          "detail", "key", "order",
        ];
    
        for (const channel of Object.keys(encoding)) {
          if (!validChannels.includes(channel)) {
            warnings.push(`Unknown encoding channel: '${channel}'`);
          }
        }
      }
    
      // Check data types in encoding
      if (spec.encoding) {
        const encoding = spec.encoding as Record<string, any>;
        const validTypes = ["quantitative", "temporal", "nominal", "ordinal", "geojson"];
    
        for (const [channel, def] of Object.entries(encoding)) {
          if (def.type && !validTypes.includes(def.type)) {
            errors.push(`Invalid type '${def.type}' in encoding channel '${channel}'. Valid types are: ${validTypes.join(", ")}`);
          }
    
          if (!def.field && !def.value && !def.datum && channel !== "detail" && channel !== "order") {
            warnings.push(`Encoding channel '${channel}' has no field, value, or datum specified`);
          }
        }
      }
    
      // Check schema version
      if (spec.$schema && typeof spec.$schema === "string") {
        if (!spec.$schema.includes("vega-lite")) {
          errors.push("Schema URL should point to a vega-lite schema");
        }
      }
    
      return {
        valid: errors.length === 0,
        errors,
        warnings,
        spec,
      };
    }
  • src/index.ts:66-80 (registration)
    Registration of the 'validate_spec' tool in the ListTools handler, defining name, description, and input schema.
    {
      name: "validate_spec",
      description: "Validate a Vega-Lite specification and check for errors",
      inputSchema: {
        type: "object",
        properties: {
          spec: {
            type: "object",
            description: "Vega-Lite JSON specification to validate",
          },
        },
        required: ["spec"],
        additionalProperties: false,
      },
    },
  • Input schema for validate_spec tool: requires a 'spec' object.
    inputSchema: {
      type: "object",
      properties: {
        spec: {
          type: "object",
          description: "Vega-Lite JSON specification to validate",
        },
      },
      required: ["spec"],
      additionalProperties: false,
    },
  • src/index.ts:138-151 (registration)
    Dispatch case in CallToolRequest handler that invokes the validateSpec function for 'validate_spec' tool calls.
    case "validate_spec": {
      if (!args?.spec) {
        throw new Error("Spec parameter is required");
      }
      const validation = await validateSpec(args.spec as Record<string, unknown>);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(validation, null, 2),
          },
        ],
      };
    }
  • Type definition for the output of validateSpec (ValidationResult).
    interface ValidationResult {
      valid: boolean;
      errors: string[];
      warnings: string[];
      spec: Record<string, unknown>;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the tool validates and checks for errors, but doesn't disclose behavioral traits like what types of errors are detected, whether validation is strict or lenient, if it returns detailed error messages, or any performance considerations. This leaves significant gaps for a validation tool.

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 directly states the tool's function without unnecessary words. It's front-loaded with the core purpose, making it easy to understand quickly. Every part of the sentence earns its place.

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?

Given the tool's complexity (validation of nested JSON specs) and lack of annotations and output schema, the description is insufficient. It doesn't explain what the validation entails, what outputs to expect (e.g., success/failure, error details), or how errors are reported. For a validation tool with no structured output, more context is needed.

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?

The input schema has 100% description coverage, with the 'spec' parameter documented as 'Vega-Lite JSON specification to validate'. The description adds no additional meaning beyond this, such as format examples or validation scope. With high schema coverage, a baseline score of 3 is appropriate as the schema handles the heavy lifting.

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 ('validate') and resource ('Vega-Lite specification'), and mentions checking for errors. It doesn't explicitly differentiate from sibling tools like 'get_example' or 'search_docs', but the validation focus is distinct enough to avoid confusion.

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 prerequisites, such as needing a valid spec, or compare it to siblings like 'get_schema_info' for schema-related tasks. Usage is implied by the name but not explicitly stated.

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/inteligencianegociosmmx/vegaLite_mcp_server'

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