Skip to main content
Glama

export_json

Export color data as structured JSON for API integration, design systems, and programmatic use with customizable format options.

Instructions

Generate JSON format for programmatic use and API integration with multiple structure options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that validates input parameters, parses colors, generates JSON in specified format (simple, detailed, api, design_tokens), creates additional CSS/SCSS exports, and returns structured success/error response.
    async function exportJson(
      params: ExportJsonParams
    ): Promise<ToolResponse | ErrorResponse> {
      const startTime = Date.now();
    
      try {
        // Validate parameters
        const { error, value: validatedParams } = exportJsonSchema.validate(params);
        if (error) {
          return createErrorResponse(
            'export_json',
            'INVALID_PARAMETERS',
            `Invalid parameters: ${error.details.map(d => d.message).join(', ')}`,
            Date.now() - startTime
          );
        }
    
        // Parse colors
        const colors: UnifiedColor[] = [];
        for (const colorStr of validatedParams.colors) {
          try {
            const color = new UnifiedColor(colorStr);
            colors.push(color);
          } catch {
            return createErrorResponse(
              'export_json',
              'INVALID_COLOR',
              `Invalid color format: ${colorStr}`,
              Date.now() - startTime,
              {
                details: { provided: colorStr },
                suggestions: [
                  'Use hex format like #FF0000',
                  'Use RGB format like rgb(255, 0, 0)',
                  'Use HSL format like hsl(0, 100%, 50%)',
                ],
              }
            );
          }
        }
    
        // Generate JSON based on format
        const jsonData = generateJSON(colors, validatedParams);
        const jsonString = validatedParams.pretty_print
          ? JSON.stringify(jsonData, null, 2)
          : JSON.stringify(jsonData);
    
        // Generate additional export formats
        const exportFormats = {
          json: jsonData,
          css: generateCSSFromJSON(jsonData),
          scss: generateSCSSFromJSON(jsonData),
        };
    
        const executionTime = Date.now() - startTime;
    
        return createSuccessResponse(
          'export_json',
          {
            json_output: jsonString,
            format: validatedParams.format,
            color_count: colors.length,
            includes_metadata: validatedParams.include_metadata,
            includes_accessibility: validatedParams.include_accessibility,
            includes_variations: validatedParams.include_variations,
            file_size: jsonString.length,
          },
          executionTime,
          {
            recommendations: [
              'Use the detailed format for comprehensive color information',
              'Consider the API format for web service integration',
              'Use design tokens format for design system integration',
            ],
            exportFormats,
          }
        );
      } catch (error) {
        return createErrorResponse(
          'export_json',
          'PROCESSING_ERROR',
          error instanceof Error ? error.message : 'Unknown error occurred',
          Date.now() - startTime
        );
      }
    }
  • Joi schema defining the input parameters for the tool, including required colors array, optional format (simple/detailed/api/design_tokens), metadata/accessibility/variations flags, semantic names, group name, version, and pretty_print option.
    const exportJsonSchema = Joi.object({
      colors: Joi.array()
        .items(Joi.string())
        .min(1)
        .max(100)
        .required()
        .description('Array of colors to export'),
    
      format: Joi.string()
        .valid('simple', 'detailed', 'api', 'design_tokens')
        .default('detailed')
        .description('JSON format structure'),
    
      include_metadata: Joi.boolean()
        .default(true)
        .description('Include color analysis metadata'),
    
      include_accessibility: Joi.boolean()
        .default(true)
        .description('Include accessibility information'),
    
      include_variations: Joi.boolean()
        .default(false)
        .description('Include color variations (tints, shades)'),
    
      semantic_names: Joi.array()
        .items(Joi.string())
        .description('Optional semantic names for colors'),
    
      group_name: Joi.string().description('Name for the color group/palette'),
    
      version: Joi.string()
        .default('1.0.0')
        .description('Version number for the palette'),
    
      pretty_print: Joi.boolean()
        .default(true)
        .description('Format JSON with indentation'),
    });
  • ToolHandler definition and export for 'export_json', including name, description, parameters from schema, and handler that delegates to the main exportJson function.
    export const exportJsonTool: ToolHandler = {
      name: 'export_json',
      description:
        'Generate JSON format for programmatic use and API integration with multiple structure options',
      parameters: exportJsonSchema.describe(),
      handler: async (params: unknown) => exportJson(params as ExportJsonParams),
    };
  • Registration of export format tools including exportJsonTool into the central ToolRegistry singleton.
    // Register export format tools
    toolRegistry.registerTool(exportCssTool);
    toolRegistry.registerTool(exportScssTool);
    toolRegistry.registerTool(exportTailwindTool);
    toolRegistry.registerTool(exportJsonTool);
  • Helper function that dispatches to specific JSON generators based on the requested format: simple, detailed, api, or design_tokens.
    function generateJSON(
      colors: UnifiedColor[],
      params: ExportJsonParams
    ): Record<string, unknown> | DetailedJsonResult {
      const { format } = params;
    
      switch (format) {
        case 'simple':
          return generateSimpleJSON(colors, params.semantic_names);
    
        case 'detailed':
          return generateDetailedJSON(colors, params);
    
        case 'api':
          return generateAPIJSON(colors, params);
    
        case 'design_tokens':
          return generateDesignTokensJSON(colors, params);
    
        default:
          return generateDetailedJSON(colors, params);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'programmatic use and API integration' which hints at technical usage, but doesn't describe what the tool actually does behaviorally - that it takes color inputs and produces structured JSON output with various formatting options. It doesn't mention whether this is a read-only operation, what the output looks like, or any performance considerations.

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 a single, efficient sentence that gets straight to the point. It's appropriately sized for what it communicates, though what it communicates is limited. There's no wasted verbiage or unnecessary elaboration.

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 9 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool actually produces (JSON representation of color data), doesn't provide context about typical use cases, and doesn't help the agent understand when this would be the right choice among multiple export options. The description leaves too much unexplained given the tool's complexity.

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 schema description coverage is 100%, so the schema already documents all 9 parameters thoroughly with descriptions, defaults, and constraints. The description adds no additional parameter information beyond mentioning 'multiple structure options' which loosely references the 'format' parameter. This meets the baseline expectation when schema coverage is high.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'Generate[s] JSON format for programmatic use and API integration' which indicates its purpose is to output JSON data. However, it's vague about what exactly is being exported - it mentions 'multiple structure options' but doesn't specify this is for color data, which is clear from the parameters but not from the description alone. It doesn't clearly distinguish from sibling export tools like export_css or export_scss.

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. There's no mention of when JSON export would be preferred over CSS, SCSS, or Tailwind exports (sibling tools), nor any context about prerequisites or typical use cases. The agent receives no help in selecting this tool over other export 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/keyurgolani/ColorMcp'

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