Commit 6bb77e6
feat(mcp): compact tool-result serialization — phase 1 output compaction
The MCP tool-call choke point pretty-printed every result; the consumer is
an LLM agent that parses JSON identically with or without indentation, so the
indentation was pure cost. Default the tool-call text channel to compact JSON.
Measured on a representative symbol_search payload (25 hits): 8742 → 6676
chars, ~24% smaller, ~517 tokens/call — lossless, zero schema change, no
parseability risk. symbol_search is the most-called tool fleet-wide (~3k
installs), so this compounds.
Scope: only the MCP tool-call hot path. The --run-tool CLI (human output piped
to PR comments) and resource stats stay pretty. CODEGRAPH_MCP_PRETTY=1 restores
indentation for inspection. Split into serialize_tool_result (env) +
serialize_tool_result_mode (pure) so the win is unit-tested deterministically.
Phase 2 (per-tool structural: columnar rows + path legend) measured at a
further ~48% on top (60% total vs pretty) but carries agent-comprehension cost
— deferred until phase 1's resultSizeBucket delta is read.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 8bc90ec commit 6bb77e6
1 file changed
Lines changed: 51 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
62 | 85 | | |
63 | 86 | | |
64 | 87 | | |
| |||
1638 | 1661 | | |
1639 | 1662 | | |
1640 | 1663 | | |
1641 | | - | |
1642 | | - | |
| 1664 | + | |
1643 | 1665 | | |
1644 | 1666 | | |
1645 | 1667 | | |
| |||
4857 | 4879 | | |
4858 | 4880 | | |
4859 | 4881 | | |
| 4882 | + | |
| 4883 | + | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
4860 | 4909 | | |
4861 | 4910 | | |
4862 | 4911 | | |
| |||
0 commit comments