Open-source proxy to reduce MATLAB/Simulink MCP token usage in Claude Code (48–66% reduction)


Background: I've been using Claude Code with the MATLAB MCP Core Server and Simulink Agentic Toolkit for powertrain simulation work — building PMSM FOC controllers, Simscape thermal models, and suspension systems. After a few sessions I noticed a large fraction of my context window was being consumed by output that's useful to a human but not to an LLM: aligned whos tables, repeated solver warnings (one per timestep), deep call stacks with HTML hyperlinks, Simulink build logs, etc.
What I built: A transparent Python stdio proxy that sits between Claude Code and matlab-mcp-core-server. It intercepts tool responses and applies 14 MATLAB/Simulink/Simscape-specific compression rules before the output reaches Claude's context window. Requests are never touched — only responses.
Example reductions:
  • whos variable table → 74% reduction (1,800 chars → 189 chars)
  • Repeated solver warnings (×10 RCOND warnings) → 71% reduction
  • Large array auto-display (1000-row vector) → 85% reduction
  • Simulink build log → 56% reduction
  • DOE progress loop (55 points) → 79% reduction
  • Session average: 48–66% reduction
It also fixes the simulink session attach problem. Without --initialize-matlab-on-startup=true on the matlab server, the simulink server's 30-second discovery window expires before MATLAB is ready. The proxy config includes this flag and documents why it's necessary (root cause traced through server logs).
Validated on: A 2-DOF Simscape quarter-car active suspension model built entirely via model_edit from the SATK — active PD controller achieved 61.7% lower peak chassis velocity and settled 34% faster than passive.
Includes 37 unit tests, full HTML documentation, and the validated Simscape model. Would be interested to hear if others have run into the same output verbosity issues and what workarounds you've tried.

Tags

No tags entered yet.