How To Cut MCP Token Costs? Save Up To 92% At Scale With Code Mode 💎 Bifrost, an open-source MCP gateway, introduces Code Mode that reduces token costs by up to 92% at scale. By replacing direct exposure of hundreds of tools with four generic tools that generate Starlark code in a sandbox, Code Mode cuts input tokens from 1.15M to 83K per query in benchmarks with 500+ tools. The feature addresses the problem of LLMs spending most of their context budget reading tool catalogs instead of performing actual work. Today, new artificial intelligence models are released every six months, such as GPT 5.6, Fable 5, Kimi K3 and many others. And now the most active discussion in the technical community is the concept of tokens, which allows us to use LLM in our favorite IDEs such as Cursor. Plans are quite expensive today and every request is important to the business. In this article, I would like to tell you how you can save your money using LLM using one tool. Well, let's get started Instead of words, let's look at one small example that I prepared for you: Request 1 2,350 tokens : "Fetch the data from the endpoint..." ↓ Model reasons about what to do Request 2 3,100 tokens : "Here's the response. Now transform it..." ↓ Model reasons again Request 3 2,900 tokens : "Now check these projects..." ↓ Model reasons about results Request 4 2,500 tokens : "Generate a summary based on..." ↓ Total: 10,850 tokens = $0.32 per execution Now let's imagine that our entire business is built on these requests. The site can have as many users as you like, and each such request to LLM spends our money. Considering that the plans of providers like Claude, although not so expensive, are still a serious budget expenditure. You will have to think through a business model so that it makes a profit. If you have a small business and want to cut down on the costs of using tokens, I suggest you try Bifrost https://github.com/maximhq/bifrost , which recently made a super useful feature called Code Mode. Code Mode is a transformative approach to using MCP that solves a critical problem at scale: The Problem: When you connect 8-10 MCP servers 150+ tools , every single request includes all tool definitions in the context. The LLM spends most of its budget reading tool catalogs instead of doing actual work. Instead of exposing 150 tools directly, Code Mode exposes just four generic tools. The LLM uses those tools to write Starlark that orchestrates everything else in a sandbox. Since I have written many articles on the topic of Bifrost, you already know how to work with it. Let's try to apply what I wanted. First of all, here's what I want to do: Default Mode: Request 1: "Use the database tool to fetch data" → Model reasons, calls tool → Response: 2,450 tokens Request 2: "Transform the result..." → Model reasons, calls tool → Response: 3,100 tokens Total Requests: 4+ API calls Total Tokens: 10,850+ Now working with the solution: Code Mode: Request 1: "Here's what I need. Write Python to do it." → Model writes code single request → Python executes all tools in sequence → Results fed back in one batch Total Requests: 1 API call Total Tokens: 850 If you think this is some kind of deception, then no. The reason here is very simple. Language models are good at writing code. Bad at reasoning step-by-step through tool chains. | Round | MCP Footprint | Pass Rate Classic | Pass Rate Code Mode | Input Tokens Classic | Input Tokens Code Mode | Token Reduction | Cost Classic | Cost Code Mode | Cost Savings | |---|---|---|---|---|---|---|---|---|---| | 1 | 96 tools / 6 servers | 64/64 100% | 64/64 100% | 19.9M | 8.3M | -58.2% | $104.04 | $46.06 | -55.7% | | 2 | 251 tools / 11 servers | 64/65 98.5% | 65/65 100% | 35.7M | 5.5M | -84.5% | $180.07 | $29.80 | -83.4% | | 3 | 508 tools / 16 servers | 65/65 100% | 65/65 100% | 75.1M | TBD | TBD | TBD | TBD | TBD | At around 500 tools, Code Mode reduced average input tokens per query by roughly 14x: from 1.15M tokens to 83K tokens. See the Bifrost MCP Gateway benchmark writeup, or explore the complete benchmark report. Let's set up a virtual key for our employee in the company. To do this, let's describe the following json: { "virtual key": "vk-data", "token budget": { "daily limit": 1000000, "monthly limit": 20000000, "cost limit": "$500/day" }, "token alerts": { "threshold percent": 75, 90, 100 , "notify": "worker@company.com" }, "allowed mcp tools": "database", "api-client", "csv-processor" , "blocked mcp tools": "file-system", "external-web-scraper" } And enable Code Mode for the product: { "virtual key": "vk-product", "code mode": { "enabled": true, "max code memory": 512, // MB "allowed imports": "requests" , "blocked imports": "subprocess", "os" }, "mcp token budget": 1000000 } Let's say our company works with Code Mode enabled, here are the results the business will have when working: Organization Token Budget: 100,000,000 tokens/month ├─ Engineering: 40,000,000 tokens │ ├─ Backend services: 30,000,000 Code Mode enabled │ ├─ Data processing: 10,000,000 Code Mode enabled │ ├─ Product: 20,000,000 tokens │ ├─ Analytics: 15,000,000 Code Mode enabled │ ├─ User research: 5,000,000 No Code Mode needed │ ├─ Research: 40,000,000 tokens │ ├─ Experiments: 30,000,000 Mixed mode │ └─ Exploration: 10,000,000 Text As a result, we fit within the company's budget. If we were to create a budget based on a simple request for LLM, then we would use more tokens for requests, and accordingly, money would also be spent on tokens. Also, along with code mode, you can configure MCP Tool Groups, which will allow us to conveniently configure the context without adding several dozen tools there manually. { "mcp tool groups": { "name": "api-integration", "tools": "http-get", "http-post", "http-auth", "rate-limiter" , "required for": "backend", "integrations" }, { "name": "data-transformation", "tools": "csv-parse", "json-transform", "data-validate", "format-output" , "required for": "data-processing", "analytics" } } Then assign Tool Groups to Virtual Keys: { "virtual key": "vk-backend", "allowed tool groups": "database-operations", "api-integration" , "code mode": { "enabled": true, "max code memory": 512, } } This will also save time on use, improve security, and, most importantly, LLM will only see groups of tools, not the entire list, which will save time on data processing. Without Tool Groups 50 tools visible : ├─ Initial prompt: 8,000 tokens reading all tool definitions ├─ Code generation: 4,000 tokens └─ Total: 10,000 tokens With Tool Groups 5 tools visible : ├─ Initial prompt: 1,500 tokens reading relevant tools only ├─ Code generation: 600 tokens └─ Total: 4,000 tokens In my opinion, the code mode is not just a function, but a super method in the approach of enterprises to the agency economy. At scale, Code Mode achieves a 58% to 85% reduction in token count depending on complexity, which directly translates to 56% to 83% cost savings. You can spend this money on marketing. npx -y @maximhq/bifrost-cli Thanks for reading this article ❤️ I'd love to hear your thoughts on this mode in the comments