𝗟𝗮𝘇𝘆 𝗟𝗼𝗮𝗱𝗶𝗻𝗴 𝗠𝗖𝗣 𝗧𝗼𝗼𝗹𝘀: 𝗪𝗵𝗼 𝗦𝘂𝗽𝗽𝗼𝗿𝘁𝘀 𝗜𝘁 𝗮𝗻𝗱 𝗛𝗼𝘄
Most people think MCP server costs live in the code. They are wrong.
If you build an MCP server, you face two types of token costs:
- Fixed cost: Tool definitions loaded into context every turn.
- Variable cost: The size of the response a tool returns.
You control the variable cost. You can paginate results or limit output size.
You do not control the fixed cost. That is the job of the host (the client).
If you have ten servers with many tools, you might waste 40,000 tokens before the model even reads your first message. This happens because the host loads every tool definition upfront.
The solution is lazy loading. This means the host only loads a tiny search tool and pulls other definitions only when needed.
The problem? Most clients do not support this yet.
Current status of lazy loading:
- Claude Code: Supports it. Tools load on demand via a search tool.
- Cursor, Devin, and others: They do not support it. They load everything at once.
If your context is bloating on a client that lacks lazy loading, you have two options:
Use a lazy proxy Point your host to a proxy server instead of your real servers. The proxy exposes only two tools: search_tools and execute_tool. It loads your real definitions only when requested. This shrinks your context but removes fine-grained permission control.
Use a router pattern If one server is getting too big, do not add more tools. Instead, create one tool with an operation parameter. For example, use one "docs" tool with commands like "list", "get", or "search". This reduces the number of schemas the host must load.
Summary of strategy:
- 6 to 15 tools: Do nothing. The cost is too low to worry.
- Many tools in one server: Use a router pattern.
- Many different servers: Use a lazy proxy.
Check your client behavior before you spend hours optimizing your code. The fix might not be in your server at all.
Source: https://dev.to/ismaestro/lazy-loading-mcp-tools-which-clients-support-it-and-how-4414
Optional learning community: https://t.me/GyaanSetuAi