Skip to content

Add validation warnings to tool outputs for risky operations #15

Description

@willibrandon

Feature Request

Add warnings field to tool output structs to communicate validation warnings to MCP clients about risky operations.

Motivation

Users need to be warned about operations that are lossy, irreversible, or have known issues. Currently, warnings are only logged server-side (stderr) which MCP clients cannot see.

Background

MCP Protocol: Uses stdin/stdout for JSON messages, stderr for logs
Current logging: mtlog writes to stderr (correct for server-side)
Problem: Claude Code and other MCP clients cannot see stderr logs

Proposed Solution

Add warnings to both server-side logs AND client-side JSON responses:

1. Add warnings field to output structs

type QuantizePaletteOutput struct {
    Success  bool     `json:"success"`
    Warnings []string `json:"warnings,omitempty"`  // NEW
    // ... existing fields
}

2. Log warnings server-side AND return in response

var warnings []string

// Server-side logging (stderr, for debugging)
if input.ConvertToIndexed && currentMode == "rgb" {
    opLogger.Warning("Converting RGB to indexed", 
        "lossy", true,
        "original_mode", "rgb")
}

// Client-side warning (JSON response)
if input.ConvertToIndexed && currentMode == "rgb" {
    warnings = append(warnings, 
        "Converting RGB to indexed is lossy - colors will be quantized to palette")
}

return &QuantizePaletteOutput{
    Success: true,
    Warnings: warnings,
    // ...
}

Operations Needing Warnings

quantize_palette:

  • RGB → indexed conversion (lossy)
  • Target colors < current colors (color loss)

flatten_layers:

  • Operation cannot be undone without snapshots
  • Layer organization will be lost

Any operation changing color mode:

  • RGB → indexed (lossy)
  • Indexed → RGB (palette info lost)
  • Grayscale conversions (color info lost)

scale_sprite:

  • Upscaling with non-pixel-perfect scaling (interpolation artifacts)

Example Output

{
  "success": true,
  "warnings": [
    "Converting RGB to indexed is lossy - colors will be quantized to palette",
    "Target palette size (16) is smaller than original (42) - 26 colors will be lost"
  ],
  "original_colors": 42,
  "quantized_colors": 16,
  ...
}

Implementation Checklist

  • Add warnings []string field to all tool output structs
  • Implement warning generation in quantize_palette
  • Implement warning generation in flatten_layers
  • Implement warning generation for color mode conversions
  • Update tool descriptions to document warning conditions
  • Add integration tests verifying warnings are returned

Benefits

  • MCP clients can display warnings to users
  • Users make informed decisions about risky operations
  • Known issues are communicated proactively
  • Server-side logs still available for debugging

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions