---
title: How Bifrost&#x27;s Code Mode Cuts Token Usage by 50% in Multi-Tool MCP Workflows
description: "TL;DR\n\nBifrost&#x27;s Code Mode reduces token usage by 50%+ and execution latency by 40-50% when working with multiple MCP servers. Instead of loading hundreds of tool schemas, it lets AI write TypeScript to orchestrate tools programmatically, enabling faster execution and lower costs.\n\n\nThe Token Bloat Problem with"
image: https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w1200/2026/07/how-bifrost-s-code-mode-cuts-token-usage-by-50-in-multi-tool-bifrost-paper-waves.optimized.png
---

Try Bifrost Enterprise free for 14 days. [Request access](https://www.getmaxim.ai/#enterprise-trial)

## TL;DR

Bifrost's Code Mode reduces token usage by **50%+** and execution latency by **40-50%** when working with multiple MCP servers. Instead of loading hundreds of tool schemas, it lets AI write TypeScript to orchestrate tools programmatically, enabling faster execution and lower costs.

---

## The Token Bloat Problem with Traditional MCP

When connecting AI agents to multiple [Model Context Protocol (MCP)](https://www.anthropic.com/news/model-context-protocol) servers, teams hit a critical bottleneck: **tool bloat**. Each server exposes tools with detailed schemas that must be loaded into the LLM's context window.

| MCP Servers | Tools Exposed | Context Impact |
| --- | --- | --- |
| 3 servers | 90 tools | \~45,000 tokens |
| 5 servers | 150 tools | \~75,000 tokens |
| 10 servers | 300 tools | \~150,000 tokens |

This creates three problems:

- **Massive token overhead** - Tool schemas consume 30-50% of context before tasks begin
- **Degraded performance** - More tools increase latency and hallucination rates
- **Sequential execution waste** - Each tool call requires a separate LLM round trip

## How Code Mode Solves This

[Bifrost's Code Mode](https://docs.getbifrost.ai/mcp/code-mode) uses a different approach: **LLMs are better at writing code to call tools than calling tools directly**.

Instead of loading hundreds of tool definitions, Code Mode exposes four meta-tools:

- **listToolFiles** - Discover available MCP servers and tools
- **readToolFile** - Read tool documentation on demand
- **getToolDocs** - Fetch specific tool schemas when needed
- **executeToolCode** - Run TypeScript that orchestrates multiple tools

### The Workflow Comparison

**Traditional MCP**:

```
Load 100+ schemas → Call tool #1 → Return to LLM →
Call tool #2 → Return to LLM → Repeat
```

**Code Mode**:

```
Discover tools → Write TypeScript → Execute in sandbox →
Return final results
```

## Real-World Example: GitHub PR Analysis

**Traditional MCP**:

- GitHub tools: 20 tools, \~10,000 tokens
- Code analysis: 15 tools, \~7,500 tokens
- Notifications: 10 tools, \~5,000 tokens
- **Total**: \~22,500 tokens, 8 round trips

**Code Mode**:

- 4 meta-tools: \~400 tokens
- TypeScript orchestrates all operations
- **Total**: \~400 tokens, 1 execution

**Result**: 97% reduction in schema overhead, 75% fewer round trips.

## Security Benefits

Code Mode eliminates a major security risk. Traditional approaches might leak API keys in generated code. Code Mode uses pre-authenticated bindings:

```tsx
// Traditional - API keys in code (risky)
const github = new GitHub({ token: process.env.GITHUB_TOKEN });

// Code Mode - pre-authenticated (secure)
const github = servers['github'];
```

The sandbox provides:

- **Isolated execution** - Controlled TypeScript runtime
- **Pre-authenticated clients** - No API keys in generated code
- **Network isolation** - Only configured MCP server access
- **Timeout controls** - Prevents runaway scripts

## When to Use Code Mode

Bifrost recommends Code Mode for **3+ MCP servers**:

| Servers | Recommendation | Why |
| --- | --- | --- |
| 1-2 | Traditional MCP | Code generation overhead not worth it |
| 3-5 | Code Mode | Significant savings |
| 6+ | Code Mode (required) | Traditional becomes impractical |

**Best for**:

- Multi-step operations across tools
- Large dataset processing
- Production systems needing optimization
- Workflows with loops and conditionals

## Performance Metrics

Teams report:

- **50%+ lower token usage**
- **30-40% faster execution**
- **3x more MCP servers** supported
- **Reduced hallucination rates**

## Getting Started

Enable Code Mode in [Bifrost configuration](https://docs.getbifrost.ai/mcp/code-mode):

```json
{
  "mcp": {
    "mode": "code",
    "sandbox": {
      "timeout": 30000,
      "memory_limit": "512mb"
    }
  }
}
```

## MCP Gateway Features

Code Mode is part of Bifrost's [MCP Gateway](https://docs.getbifrost.ai/mcp/overview), which includes:

- [MCP Client](https://docs.getbifrost.ai/mcp/connecting-to-servers) - Connect to any MCP-compatible server
- [MCP Server](https://docs.getbifrost.ai/mcp/gateway-url) - Expose tools to external clients
- [Agent Mode](https://docs.getbifrost.ai/mcp/agent-mode) - Autonomous tool execution
- [Tool Filtering](https://docs.getbifrost.ai/mcp/filtering) - Granular access control
- [OAuth Support](https://docs.getbifrost.ai/mcp/oauth) - Secure authentication with token refresh

Combined with [semantic caching](https://docs.getbifrost.ai/features/semantic-caching), [automatic fallbacks](https://docs.getbifrost.ai/features/fallbacks), and [multi-provider routing](https://docs.getbifrost.ai/providers/provider-routing), Bifrost provides complete infrastructure for production AI systems.

## The Bigger Picture

The shift toward Code Mode represents a broader trend: moving from "AI calls tools" to "AI writes code that calls tools". This leverages LLM strengths (code generation) while avoiding weaknesses (managing complex tool schemas).

For teams using [Maxim AI's evaluation and observability platform](https://www.getmaxim.ai/), Bifrost's Code Mode complements your workflow. While [Maxim helps measure and improve AI quality](https://www.getmaxim.ai/products/agent-simulation-evaluation), Bifrost ensures your infrastructure handles multi-tool complexity at scale.

When evaluating AI agents that use MCP tools, Maxim's [agent evaluation framework](https://www.getmaxim.ai/blog/ai-agent-evaluation-metrics/) can measure the quality improvements from Code Mode's efficiency gains, helping teams quantify both cost savings and performance improvements.

---

**Ready to cut token costs by 50%?** [Try Bifrost Enterprise](https://www.getmaxim.ai/enterprise) free for 14 days or [join our Discord](https://getmax.im/bifrost-discord) to optimize your MCP workflows.

## Read next

[![MCP Connectors Explained: How They Work and How to Govern Them](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/10/mcp-connectors-explained-how-they-work-and-how-to-govern-the-bifrost-1920x1080.png) An MCP connector is the configured link between an AI application and an external system, made of an MCP client, a transport, credentials, and an MCP server. This guide explains how connectors work, where they break down at scale, and how an MCP gateway governs them centrally.](https://www.getmaxim.ai/articles/mcp-connectors/)

[![MCP Authorization: OAuth Scopes and Per-Tool Permissions](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/10/mcp-authorization-oauth-scopes-and-per-tool-permissions-bifrost-1920x1080.png) MCP authorization controls which clients may call a protected MCP server and what their tokens allow. This guide walks through the OAuth 2.1 flow in the current MCP spec, scopes and step-up, token audience rules, the gaps teams hit in production, and per-tool enforcement at a gateway.](https://www.getmaxim.ai/articles/mcp-authorization/)

[![Top 5 Gateways for Hosting and Securing Remote MCP Servers in 2026](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/10/top-5-gateways-for-hosting-and-securing-remote-mcp-servers-i-bifrost-1920x1080@2x.png) Remote MCP servers expose tools to AI agents over HTTP, which makes authentication and tool access the first problems to solve. This guide compares five gateways for hosting and securing them, including Bifrost, Cloudflare, Azure API Management, and Amazon Bedrock AgentCore Gateway.](https://www.getmaxim.ai/articles/remote-mcp-server-gateways/)

## More in MCP Gateway

[![Transform Your AI Applications with Bifrost MCP Gateway](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/07/ChatGPT-Image-Jan-26--2026--08_26_19-PM--1-.optimized.png) Build secure, production-grade AI agents with enterprise-level tool orchestration As AI applications evolve beyond simple chat interfaces, developers face a critical challenge: how do you enable AI models to interact with external tools, databases, and APIs safely and efficiently? Bifrost's Model Context Protocol (MCP) Gateway solves](https://www.getmaxim.ai/articles/transform-your-ai-applications-with-bifrost-mcp-gateway/)

[![Top 5 MCP Gateways for Engineering Teams in 2026](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/07/top-5-mcp-gateways-for-engineering-teams-in-2026-bifrost-paper-waves.optimized.png) The Model Context Protocol (MCP), introduced by Anthropic in late 2024, has become the de facto standard for connecting AI models to external tools, data sources, and services. As agentic AI workflows move into production, engineering teams need more than a basic MCP client integration. They need a production-grade](https://www.getmaxim.ai/articles/top-5-mcp-gateways-for-engineering-teams-in-2026/)

```json
{
    "@context": "https://schema.org",
    "@type": "Article",
    "publisher": {
        "@type": "Organization",
        "name": "Maxim Articles",
        "url": "https://www.getmaxim.ai/articles/",
        "logo": {
            "@type": "ImageObject",
            "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w256h256/2025/08/thumbnail.png",
            "width": 60,
            "height": 60
        }
    },
    "author": {
        "@type": "Person",
        "name": "Kamya Shah",
        "image": {
            "@type": "ImageObject",
            "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/2025/09/WhatsApp-Image-2025-08-29-at-17.40.40-1.jpeg",
            "width": 1200,
            "height": 1600
        },
        "url": "https://www.getmaxim.ai/articles/author/kamya/",
        "sameAs": []
    },
    "headline": "How Bifrost's Code Mode Cuts Token Usage by 50% in Multi-Tool MCP Workflows",
    "url": "https://www.getmaxim.ai/articles/how-bifrosts-code-mode-cuts-token-usage-by-50-in-multi-tool-mcp-workflows/",
    "datePublished": "2026-02-14T08:22:08.000Z",
    "dateModified": "2026-10-13T11:03:39.000Z",
    "image": {
        "@type": "ImageObject",
        "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w1200/2026/07/how-bifrost-s-code-mode-cuts-token-usage-by-50-in-multi-tool-bifrost-paper-waves.optimized.png",
        "width": 1200,
        "height": 630
    },
    "keywords": "MCP Gateway",
    "description": "TL;DR\n\nBifrost's Code Mode reduces token usage by 50%+ and execution latency by 40-50% when working with multiple MCP servers. Instead of loading hundreds of tool schemas, it lets AI write TypeScript to orchestrate tools programmatically, enabling faster execution and lower costs.\n\n\nThe Token Bloat Problem with Traditional MCP\n\nWhen connecting AI agents to multiple Model Context Protocol (MCP) servers, teams hit a critical bottleneck: tool bloat. Each server exposes tools with detailed schemas t",
    "mainEntityOfPage": "https://www.getmaxim.ai/articles/how-bifrosts-code-mode-cuts-token-usage-by-50-in-multi-tool-mcp-workflows/"
}
```
