Skip to content

Reduce MCP tool output context bloat by ~85%#177

Merged
tnm merged 1 commit into
mainfrom
mcp-context-optimization
Jan 5, 2026
Merged

Reduce MCP tool output context bloat by ~85%#177
tnm merged 1 commit into
mainfrom
mcp-context-optimization

Conversation

@tnm

@tnm tnm commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Reduces context usage from two MCP tool outputs:

Tool Before After Savings
extract_symbols 22K tokens 2K tokens 90%
get_file_tree 18K tokens 3K tokens 82%

Changes

  • extract_symbols: Add include_code param (default false)

    • Code field was 91% of output; now excluded by default
    • Set include_code=true when code is needed
  • get_file_tree: Add compact mode (default true)

    • Returns newline-separated paths instead of verbose JSON
    • Add include_dirs param to optionally include directories
  • New get_symbol_code tool: Lazy load specific symbol code

    • Enables "browse symbols → fetch code for specific one" workflow

Test plan

  • All MCP tests pass (68 passed)
  • New tests for context optimization features
  • Verified token savings with real measurements

- extract_symbols: exclude code by default (90% reduction, 22K→2K tokens)
  - Add include_code param (default false) to control code inclusion
  - AI can request code when needed via include_code=true

- get_file_tree: compact mode by default (82% reduction, 18K→3K tokens)
  - Add compact param (default true) for newline-separated paths
  - Add include_dirs param to optionally include directory entries

- New get_symbol_code tool for lazy code loading
  - Fetch specific symbol's code on-demand
  - Enables efficient "browse then drill down" workflows

These defaults significantly reduce context usage while maintaining
full functionality through optional parameters.
@tnm tnm merged commit 92d99c4 into main Jan 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant