Original MCP total: 9,618 tokens (15 tools) Ultra-optimized MCP total: 9,234 tokens (15 tools) Actual savings: 384 tokens (4.0% reduction)
Why lower than expected?
- Schema JSON optimization: 528 tokens (22%)
- MCP protocol overhead: ~7,200 tokens (unchanged)
- Result: Only 4% total reduction because protocol overhead dominates
Key insight: The MCP protocol adds 303% overhead (~7,200 tokens) for metadata/serialization, which our optimizations cannot reduce.
- Token reduction: 22% (528 tokens)
- MCP total: ~7,500 tokens (down from ~9,618)
- Changes: Compressed descriptions, removed verbose property descriptions
- Compatibility: 100% - all tool/property names unchanged
- Recommended for: All users
- Token reduction: ~35-40% (~800+ tokens)
- MCP total: ~6,000 tokens (estimated)
- Changes: Shortened tool names + property names
trm.submitCandidate→trm.submitsessionId→sidrepoPath→repocheckpointId→cid
- Compatibility: Requires client code updates
- Recommended for: Advanced users needing maximum token savings
# Backup current
cp src/tools/schemas.ts src/tools/schemas.optimized.backup.ts
# Apply ultra optimization
cp src/tools/schemas.ultra.ts src/tools/schemas.ts
# Rebuild
npm run buildNote: Ultra mode requires updating any client code that calls these tools to use the shortened names.
| Tool | Original | Optimized | Saved |
|---|---|---|---|
| startSession | "Initialize a TRM session on a local repository with evaluation commands and halting policy." (23 tokens) | "Init TRM session with eval commands & halt policy." (13 tokens) | 10 |
| submitCandidate | "Apply candidate changes and run evaluation. STRONGLY PREFERRED: Use 'diff' mode (per-file diffs) or 'patch' mode (unified diff) for efficiency. Use trm.getFileContent first to read current file state, then generate diffs. Only use 'files' mode for new files or complete rewrites (discouraged for large files)." (79 tokens) | "Apply changes & eval. Prefer diff/patch modes; use getFileContent first." (18 tokens) | 61 |
| getFileContent | "Read current content of files from the repository. Use this before generating diffs to ensure accurate changes. Returns file contents indexed by path." (30 tokens) | "Read file contents from repo." (8 tokens) | 22 |
| validateCandidate | "Validate candidate changes without applying them (dry-run). Returns validation results with errors, warnings, and preview of changes." (25 tokens) | "Validate changes (dry-run)." (6 tokens) | 19 |
| getSuggestions | "Get AI-powered suggestions for code improvements based on evaluation results and code analysis. Returns top suggestions prioritized by criticality." (25 tokens) | "Get AI improvement suggestions." (6 tokens) | 19 |
| getFileLines | "Read a specific line range from a file. Returns lines with line numbers for easy reference. Useful for reading large files incrementally without loading entire content." (33 tokens) | "Read file line range." (6 tokens) | 27 |
| suggestFix | "Generate actionable fix candidates based on error analysis from the last evaluation. Returns ready-to-apply candidates that can be directly submitted via trm.submitCandidate. Analyzes TypeScript errors, test failures, and lint issues to provide concrete fix suggestions." (50 tokens) | "Generate fix candidates from eval errors." (9 tokens) | 41 |
Removed verbose property descriptions where the property name is self-explanatory:
repoPath: "Absolute path to the project repository" → removedzNotes: "Optional initial reasoning notes/hints" → removedrationale: "LLM notes: why these changes, expected effects, hypotheses" → removedpath: "Relative path to file" → removed (4 occurrences)diff: "Unified diff format (git diff style)" → removedpatch: "Complete unified diff (git diff output)" → removedfiles: "Complete file contents (use only for new files)" → removeddescription: "Optional description for the checkpoint" → removed
Removed inline examples from descriptions:
pathsdescription: Removed example['src/server.ts', 'package.json']
The /context report shows 9,618 tokens for the 15 tools (~641 tokens/tool), but the actual JSON schema is only 2,384 tokens (~159 tokens/tool).
MCP overhead: ~7,234 tokens (~303% overhead)
This overhead likely includes:
- Protocol metadata
- JSON serialization formatting
- Type information expansion
- Tool registration structures
Important: The 22.1% schema reduction should translate proportionally to the MCP-reported token count.
✅ Standard optimization applied (schemas.optimized.ts → schemas.ts) ✅ Build successful ✅ README.md updated ✅ Original schema backed up (schemas.original.ts)
All 15 tools maintain identical functionality:
- ✅ Parameter schemas unchanged
- ✅ Required fields unchanged
- ✅ Type constraints unchanged
- ✅ Default values unchanged
- ✅ oneOf unions unchanged
Pros:
- 22% token reduction improves context availability
- Avg 36 tokens saved per tool
- No functionality loss
- Cleaner, more maintainable definitions
- Zero breaking changes
Cons:
- Less detailed descriptions (may require users to reference docs)
- No inline examples in schemas
- Property names must be more self-documenting
The 4% savings (384 tokens) is worth keeping. Every token counts.
For more significant token savings:
- Use
getFileLinesinstead ofgetFileContent: 30-50% savings on large files - Only read files you'll modify: Avoid loading entire codebase
- Keep changes small: Smaller candidates = less context needed
The 7,200 token overhead from MCP protocol (303%) is the real issue. This requires improvements in the MCP SDK itself, not our schemas.
- ❌ Schema optimizations provide 4% savings (not 22%)
- ✅ Usage pattern optimizations provide 30-50% savings
- ✅ Combined with tool features, can achieve up to 40% total efficiency gain
Original: 9,618 tokens (641 tokens/tool avg)
Ultra: 9,234 tokens (616 tokens/tool avg)
Savings: 384 tokens (4.0% reduction)
Top 3 tools by savings:
submitCandidate → submit: -158 tokens (16.6%)getFileLines → lines: -74 tokens (10.9%)startSession → start: -70 tokens (7.7%)
This frees up 384 tokens for other context (equivalent to ~100 lines of code).
For detailed tool-by-tool comparison, see token-comparison.md.
Use node analyze-tokens.js to compare token usage between schema versions.