Tutorial

How to Cut MCP Context Tokens with a Gateway

Replace 50K-token MCP schema loads with sub-500-token tool descriptions. Practical patterns from a real opencodeCLI build.

An r/opencodeCLI build reported a 99.3% reduction in MCP schema load via a gateway. This tutorial walks the pattern: tool description compression, lazy schema loading, and surface-specific gateways.

Prerequisites

  • MCP gateway running (see related tutorial)

Walkthrough

Step 1: Audit current token cost per session

Measure schema-load tokens at session start.

Text
// In Claude Code, run /context and inspect tools section.

Step 2: Identify duplicate or overlapping tools

If three MCPs each expose `search`, the model wastes tokens.

Text
// Replace 4 single-surface search MCPs with 1 multi-surface MCP (Scavio).

Step 3: Use Scavio MCP for the search surface

One MCP, six tools, ~80 tokens per tool description.

JSON
{ "scavio": { "url": "https://mcp.scavio.dev/mcp", "headers": { "x-api-key": "${SCAVIO_API_KEY}" } } }

Step 4: Use a gateway for non-search MCPs

Postgres, GitHub, internal tools proxy through the gateway.

Text
// Already covered in 'mcp-proxy-setup' tutorial.

Step 5: Re-measure tokens

Schema load should drop dramatically.

Text
// Expected: from 30K-50K to under 5K.

Python Example

Python
# Configuration-driven. No code beyond the JSON above.

JavaScript Example

JavaScript
// See JSON above.

Expected Output

JSON
Schema-load tokens drop 80-99% depending on starting fleet size. A 30-turn session that cost $0.50 on schema overhead drops under $0.05.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

MCP gateway running (see related tutorial). A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Replace 50K-token MCP schema loads with sub-500-token tool descriptions. Practical patterns from a real opencodeCLI build.