<< Home | Tech
cut token usage by 50%+
| Area | Tech |
| AI used | Any |
| Source | r/mcp |
| Posted | 2026-02-25 |
The move
Switch from exposing all tool schemas to having the LLM write TypeScript code to orchestrate tools.Steps
- Identify the core tools required for your specific task.
- Instruct the LLM to write TypeScript code to orchestrate these tools.
- Execute the generated code instead of passing all tool schemas to the model.
- Monitor token usage to verify the reduction in costs.
Prompt for your AI
Act as an orchestrator. Instead of using direct tool calls, write a TypeScript script that performs [task] by calling the following tools: [list tools and their functions]. Ensure the script handles the logic and data flow between these tools.
What happened
The developer managed over 15 MCP servers and faced high token costs due to schema bloat. By implementing a 'Code Mode' where the LLM writes TypeScript to execute tool sequences instead of providing every schema, they reduced token consumption. This approach also helped resolve issues with tool name collisions and context window limits.Watch out
The LLM may generate syntactically incorrect code if the tool definitions are complex. Ensure your environment has a secure sandbox for executing generated TypeScript.Give it to your agent
Read https://howtheyuse.ai/p/cut-token-usage-by-50.md and help me do this.