claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[FEATURE] MCP Tools: Support display/context separation to save 50-80% tokens on formatted output

Open byPawel opened this issue 1 month ago • 0 comments

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

When MCP tools return ANSI-formatted terminal output (colors, tables, progress bars, Unicode boxes), users see a beautiful experience, but those escape codes also consume tokens in Claude's context window.

Example from real usage:

  • Content: ~6k tokens (actual information)
  • ANSI codes: ~7k tokens (visual formatting)
  • Total: 13k tokens — but Claude only needs 6k

ANSI sequences like \x1b[38;2;255;136;0m are tokenized as regular text, wasting context on purely visual decoration.

Proposed Solution

Support a "display layer" for MCP tool outputs:

  • Users SEE rich formatted terminal output (colors, gradients, tables)
  • Claude's context receives only semantic content (plain text/markdown)

Option 1: Dual-output schema (leveraging existing structuredContent)

  return {
    content: [{ type: "text", text: "...(beautiful ANSI)..." }],
    structuredContent: { text: "...(plain text)...", contextOnly: true }
  };

Alternative Solutions

Option 2: Auto-strip ANSI (simpler, client-side)

Claude Code strips ANSI escape codes before adding tool output to conversation context.

Fallback Behavior

If structuredContent isn't provided, Claude Code should:

  1. Strip ANSI codes by default
  2. Preserve semantic colors for known patterns (e.g., git diff where red/green = +/-)
  3. Convert box-drawing Unicode to markdown tables where possible

Use Case

I maintain https://github.com/byPawel/tachibot-mcp, a multi-model orchestration MCP server with 30+ tools that renders:

  • Workflow progress bars with gradient colors
  • Comparison tables with syntax highlighting
  • Model badges with provider-specific color schemes
  • Step results in styled Unicode boxes

Real scenario:

  1. User runs workflow_start to execute a 7-step multi-model analysis
  2. Each step returns beautifully formatted results with ANSI colors, tables, dividers
  3. User sees rich, scannable output in their terminal
  4. But Claude's context balloons from ~6k to ~13k tokens PER STEP
  5. A full workflow consumes 50k+ tokens just on visual formatting
  6. With this feature, users would see the same beautiful output while Claude only processes the ~6k semantic content

This would cut my MCP's context footprint by 50-80% without sacrificing UX.

Additional Context

Real-world MCP experiencing this: https://github.com/byPawel/tachibot-mcp

Related issues:

  • #12241 — Reports MCP tools consuming excessive context (50k-100k tokens)
  • #9962 — structuredContent vs TextContent handling (potential mechanism)
  • #881 — ANSI rendering issues (confirms codes pass through to context)

Technical note: I attempted to fix this server-side by sending ANSI to stderr and returning stripped text, but MCP's single output channel means users lose the visual formatting. This needs client-side support in Claude Code.

byPawel avatar Dec 29 '25 18:12 byPawel