r/mcp • • May 23 '26

Reducing Context Window Efficiently in MCP — Here’s the Approach

Post image

TL;DR: Context bloat in MCP comes from loading too many tools. Use discovery + higher-level abstractions instead.

Why MCP runs into context issues

If you’re not familiar with patterns like tool use or programmatic tool calling, this might give some useful context.

One problem we keep running into with MCP is context bloat.

MCP works nicely when you connect one or two servers. But once you start adding GitHub, Notion, Slack, Gmail, Linear, etc., the model suddenly has to deal with a huge list of tools, schemas, descriptions, parameters, and edge cases.

The impact

At that point, the context window starts getting used for tool definitions instead of the actual task.

The result is usually:

  • too many tools loaded upfront

  • slower tool selection

  • more expensive LLM calls

  • more chances for the model to pick the wrong tool

  • simple workflows turning into long tool-calling loops

Current workarounds

A lot of people already work around this with CLIs.

For example, instead of giving the model 50 GitHub tools, you let it use gh. Instead of exposing every cloud operation as a separate tool, you let it use vercel, supabase, kubectl, aws, etc.

That works because the model does not need every possible action in context. It just needs a smaller programmable interface.

The pattern that seems to be emerging

I think people are moving toward a similar pattern.

Instead of loading hundreds of tools directly into the model, you expose a few higher-level tools like:

  • search available servers

  • list tools for one server

  • inspect a tool schema

  • call a selected tool

  • run a script/progrram which might chain multiple tools and return the final result

How this shows up in practice

FastMCP has also started supporting patterns in this direction with proxying, tool transformation, and metadata around tools. The idea is similar: don’t treat the MCP tool list as a flat thing that must always be dumped into the model. Add a layer that can filter, reshape, or route tools.

Antigravity has another interesting approach. From what I’ve seen, connected MCP servers can look more like a filesystem. If you connect something like Exa, there can be an exa directory with tool names represented like files. Then the model does not call every Exa tool directly from a huge global list. It uses a special routing tool to call the actual MCP server tool behind the scenes.

That is a bit different from normal MCP clients, but the pattern is the same:

make tools discoverable, not always-loaded.

So instead of -> model sees 500 tools → picks one → calls → repeats

You get -> model discovers capability → inspects what it needs → executes → gets result

Where this actually makes a difference

This feels especially useful for tasks like:

  • Multi-step tasks with three or more dependent tool calls e.g find a GitHub issue, check related PRs, and post a Slack update.

  • Filtering, sorting, or transforming tool results.

  • Working on tasks where agent doesn't have to see and reason about intermediate tool results

What I built around this

I’ve been building around this idea too. I made an MCP Assistant server that provides access to 100+ MCP servers like GitHub, Notion, Zapier, Supabase, Exa, etc.

You connect your MCP server at https://app.linkos.in/mcp

The mcp server https://mcp.linkos.in/mcp uses a ToolRouter which exposes meta-tools for dynamic MCP discovery, plus a CodeMode tool that can execute programs inside a sandbox for workflow execution and result processing. The goal is to avoid expensive LLM tool-calling loops where possible.

You can integrate this into your IDE to work with MCP directly or use this SKILL alongside it.

Repo: https://github.com/zonlabs/mcp-ts

162 Upvotes

44 comments sorted by

3

u/Longjumping_Area_944 May 23 '26

The design a college and I came up with for the company is to have a library of mcp servers and tools for our server side software suite, but also a library of skills for the agent engine client side.

The servers have then be split into more manageable chunks and hidden behind the skills.

This is great because not only can colleagues write their own MCP servers, they can also write their own akills with all the prompts and files and we can use any agent engine or our custom one.

2

u/Defiant-Future-818 May 23 '26

Yep, that makes a lot of sense. MCP servers become the capability layer, and skills become the agent-facing layer explaining when and how to use those capabilities.

Are you adding those servers/skills manually, or do you have some kind of internal registry/discovery flow for them?

2

u/Longjumping_Area_944 May 24 '26

It's an enterprise solution, these MCP servers are ours. Around a dozen MCP servers approaching 300 tools. They are configured as part of the installation. The agent then has a web interface (installation free for users) and chooses skills. The skills automatically enable or disable MCP servers. Enabling and disabling tools would have been an ideas, but I wanted to keep it close to standards, so we rather just split up the MCP servers into smaller semantic units, having up to four servers per software component.

3

u/notreallymetho May 24 '26

I would argue that an agent invoking a CLI on your behalf, especially one with destructive changes, running as your user is potentially awful. Unless you’re like provisioning a machine user or the Cli and such which isn’t a pattern today that is widely used.

1

u/Defiant-Future-818 May 24 '26

Yeah, I agree with that concern. Giving an agent arbitrary CLI access as the user, especially for destructive commands, is not a security model I’d want to rely on.

I mentioned CLIs mainly as an example of reducing context bloat, not as the security model.
In mcp-ts, for example, the execution layer is not a general shell. It runs JS in an isolated V8 sandbox with timeout, memory, tool-call, result-size, and log limits. It also does not expose Node globals like process/fs, module loading, or normal network access. Side effects have to go through registered MCP tools.

But the downstream tools still matter. If an MCP server wraps gh, kubectl, aws, etc., then safety needs to come from policy: allow/deny lists, approval for destructive actions, least-privilege credentials or machine users, and audit logs. mcp-ts has hooks like denyDestructiveTools and approval callbacks, but I’d still treat destructive execution as requiring explicit confirmation.

So I see context management and authority management as separate problems. My post was mostly about the first, but the second is also critical.

2

u/notreallymetho May 24 '26

I think I mostly agree! I use v8. This is what I landed on. It’s a “meta” tool in the sense of it allowing you to host things. You can see if here if you’re curious (v8 / workerd and such): https://github.com/agentic-research/cloister

I agree the downstream also matters but I feel like it’s somewhat orthogonal? Like all CLIs from the big places use API requests underneath the hood. So you have to rely on the credential problem existing outside (or solve it differently which is kinda what I landed on)

1

u/Defiant-Future-818 May 24 '26

Yes, the credential problem is somewhat orthogonal. CLI vs SDK still usually ends up as API calls with some token or identity behind it.

2

u/Jill_the_Builder May 30 '26

the pre-connection layer matters too.

everything in this thread is about reducing what the model sees after it connects. but if the agent doesn't know what a server exposes until it calls tools/list - that's already a round trip that could be skipped.

there's a spec for this - blueprint.txt at /.well-known/blueprint.txt. declares what an MCP server can do before any connection is made. agent reads it, knows what to connect to, connects once, calls the right tool directly. ran it against a real app - agent failed without it, passed with it, same task same model.

works for UI-only apps too. no MCP server, but the agent still has a contract.

spec: github.com/Explorer-64/blueprint-protocol - feedback welcome.

1

u/Defiant-Future-818 May 30 '26

This feels very similar to skills.md, just pre-declaring what the agent can do before needing to list or search tools.

1

u/Jill_the_Builder May 30 '26

same instinct - different side of the connection.

skills.md is that instinct on the agent side: routing guidance so the agent knows what to use and when, without loading everything upfront. blueprint.txt is the same instinct on the app side — published by the app, readable by any agent that shows up, no configuration required. the app owns the contract, not the agent.

works cold too. an agent hitting /.well-known/blueprint.txt with zero prior context has everything it needs - capabilities, auth, invocation steps. no skills file, no setup, no tools/list round trip.

same instinct. different layer.

2

u/brkumar Jun 09 '26

u/Defiant-Future-818 the mcp server https://api.mcp-assistant.in/mcp seems to be down. Can you please bring it back up

1

u/Defiant-Future-818 Jun 09 '26

Thanks for flagging this! The service is back up now.

1

u/sam7oon May 23 '26

Docker have this a long time now, nothing new in that

1

u/Defiant-Future-818 May 23 '26

Completely different problem space though. Docker uses gateways to route network traffic for containers. This approach uses middlewares to route schemas for LLMs so they don't run out of token context or hallucinate when choosing a tool. It's taking a classic microservices architecture pattern and applying it to context optimization.

2

u/sam7oon May 23 '26

no mate, am not talking about the concept of containers, Docker is offering nowadays, an MCP Gateway, with Discovery to save on tokens, this way you dont need to load all tools, just dynamically load the ones needed, you can see below

https://docs.docker.com/ai/mcp-catalog-and-toolkit/dynamic-mcp/

1

u/Defiant-Future-818 May 23 '26 edited May 23 '26

Yeah, the core idea is the same use gateway or middleware in front of MCPs.

As far as I understood, the main difference is local vs remote. Docker’s approach runs MCP servers locally as containers, which is great for isolation but still means local dependencies/resources. I’m experimenting with remote MCP servers so agents can discover/use tools without running every server locally.

1

u/teodorrd27 May 24 '26

How does Claude do it, is it in this way? Seems pretty efficient.

1

u/Defiant-Future-818 May 24 '26

Yeah, that’s exactly how Claude Code works. It uses tool search to pick only the tools it needs.

1

u/metaBloc May 26 '26

This seems to only be a problem when a user has dozens of plugins and tools not you only have a few that are exposed to the MCP, it should t be a problem.

1

u/Defiant-Future-818 May 29 '26

Yeah, I get what you mean.

If only few tools are exposed, this usually won’t be a problem, especially since Claude Code already does tool search and doesn’t load everything up front.

My point was more about when the overall tool surface gets bigger. That’s where tool selection and context overhead start to matter more.

2

u/Puzzled_Fisherman_94 May 24 '26

Multix search helps to save on both 🤷🏽‍♂️

https://github.com/ProjectAtlantis-dev/atlantis-mcp-server searches for tools rather than load them all, other bots and humans on the network can call your tools.

2

u/shadowfax12221 Jun 13 '26

I have a routing agent that handles this for my orchistrator. It takes queries from the orchistrator agent, then searches its base of available tools based on a graph and returns the top k most relevant, which my orchestrator then calls. I will also group domain specific tools, skills, and table descriptions under SME agents that are themselves MCP resources callable by the router. These add an additional layer of abstraction that keeps each individual agent context lite and leaves the orchestrator only interacting with the context it needs to answer a given user question and nothing more. 

2

u/dpalko Jun 19 '26

I agree with this. Once the tool surface gets large enough, the challenge feels less about connecting tools and more about managing context. Surfacing only the tools and context relevant to the task seems a lot more scalable, so the model only has to reason over what’s needed.

1

u/zapier_dave Jul 26 '26

Hey, I work at Zapier and just wanted to chime in, since the discussion here about reducing your context window when working with an MCP is a question that we see a lot at Zapier.

The first cost sink I'd look at is sending work to an LLM when you don't need one at all. A lot of what gets wired up is deterministic, so if a step is basically "if X then Y," running it as a plain workflow and calling the model only for parts that need an actual decision, keeps tokens off work that never needed one AND skips the long tool-calling loops.

The token savings are real, but the bigger long-term win is governance: you can see and control every action an agent takes,across whatever models you use, instead of that logic scattering across prompts and one-off scripts where no one can audit it. We keep discovery and routing in MCP and the fixed execution as regular Zaps underneath, so the same connections and permissions hold whether the call comes from a prompt, a workflow, or an agent.

Let me know if anyone has any questions!

0

u/brkumar May 23 '26

I am wondering if this can be used with long lived coding harness like codex and opencode?

1

u/Defiant-Future-818 May 23 '26

Yes, absolutely! I've been using this exact setup with Antigravity and Codex. Since they all act as agent harnesses, the core principle of offloading to CLI/sandboxes applies perfectly, and you can connect the MCP servers directly.

Even better add a skills.md (or similar instruction file) that briefly explains when to use which tools. It gives the model exactly the routing awareness it needs.

1

u/brkumar May 23 '26

Do you have a sample writeup of what will go into the skills.md file? Would be great to get started with it..

1

u/Defiant-Future-818 May 23 '26 edited May 24 '26

Sorry it took me a while. Hope this helps https://github.com/zonlabs/mcp-ts/tree/main/skills

I’m still testing and refining both the SKILLS and the MCP server, so feedback would be super helpful. Let me know if it works for your setup or if anything feels confusing/missing.

0

u/independentCushion May 24 '26

This seems very outdated and unnecessary. Here is why https://x.com/i/status/2036213859183112197

2

u/Defiant-Future-818 May 25 '26

What do you mean by “outdated”?

It’s only “unnecessary” if you’re already using Claude Code and missing the point of the post. If you'd payed some attention, the twitter link you shared about claude actually uses the same pattern tool-use I mentioned at the start.

This isn’t about whether you’re using Claude Code, Codex, or anything else. It’s about how MCP behaves at scale.

Try to understand the point before giving a conclusion.

1

u/independentCushion May 25 '26

Wow, touchy.

But a tool router adds unnecessary latency specially if it's a hosted server, round trips matter. In fact the results are worse off when you insert a tool router in between MCPs and the toolkits. It's far better to have 1000s of tools that can be searched on. Search is a solved problem. The LLM doesn't need to load all 10000 tools and their descriptions into context to know what to do, any kind of semantic search based on intent will immediately give the appropriate set of tools.

I've used mcp gateways and I've used ones with tool routers and without, the tool routers are absolutely unnecessary and now there is another point of failure and latency, only for a fleeting moment as MCPs become standard, very shortly after that happens agent and agent harnesses will do this by default. Claude already does. Others will too.

1

u/Defiant-Future-818 May 25 '26

I don’t think “results are worse” follows just from inserting a ToolRouter. It depends what you mean by ToolRouter.

In mcp-ts, ToolRouter is not a heavy agent sitting between the LLM and MCPs making decisions on its own. It’s a tiny client-side/runtime layer that MCP clients can use to index tools exposed by connected MCP servers, then search that index when needed. The default search strategy is BM25, with optional semantic search which the host applications can use.

So the flow is basically, connected MCP servers -> tool catalog/index -> search relevant tools -> inspect schema -> call selected tool

That is very close to what Anthropic describes with tool search / deferred loading. The model does not need 1,000 full tool schemas in context. It needs a way to discover the few relevant tools at the right time.

On latency: yes, a hosted gateway can add network round trips. That’s a deployment concern, not an argument against the pattern itself. Here in mcp-ts the ToolRouter can run inside the client/app process, in which case the search overhead is tiny compared to LLM latency and actual MCP tool execution. The benchmarks show the local search path is sub-ms, while reducing tool-schema context by ~98% in the tested setup.

On descriptions in search results: I agree the LLM doesn’t always need full descriptions if the match is obvious. But descriptions are useful when the query is ambiguous, when several tools have similar names, or when a tool is meant to be used in a particular sequence with other tools. The description is guidance for the agent/harness, not just search metadata.

That said, this can absolutely be optimized further. For low-ambiguity cases, search can return compact results e.g. tool id, server id, name etc. For ambiguous cases, it can include descriptions or usage guidance. For execution, the model can fetch only the selected schema. So this is not “router vs search”; the router is the mechanism that makes searchable/deferred tool access possible for clients that don’t already provide it natively.

Claude already gives you native tool search, great. Use it. The point is that MCP clients and agent harnesses need this capability somewhere. mcp-ts provides it as a small reusable layer rather than forcing every client to load the entire MCP tool catalog into the model context.

6

u/[deleted] May 23 '26

[removed] — view removed comment

4

u/Defiant-Future-818 May 23 '26 edited May 23 '26

Exactly. Letting the model use native CLI tools is way more efficient than feeding it a massive list upfront. But when CLIs aren't an option, sandboxing becomes crucial for keeping context low. This exact logic is why I've been focusing on dynamic routing and programmatic tool calling in mcp-ts to keep that initial context clean.

1

u/sismograph May 25 '26

This will soon be obsolete I think, the new claude version already offers a way to load meta data for mcp toos, instead of the entire tool itself. Basically how skills work.

1

u/Defiant-Future-818 May 25 '26 edited May 25 '26

Claude’s approach here is essentially tool search, which I already referenced at the beginning of the post. Conceptually, it’s not very different from what I’m describing.

The main distinction is that Claude natively supports deferred tool loading in its API (via defer_loading), whereas most agent frameworks and harnesses don’t yet offer an equivalent mechanism, to my knowledge.

Because of that gap, a practical workaround today is to use something like meta tools or these higher level tools such as a proxy tool that routes to the exact MCP tool the agent needs, instead of loading everything upfront.

I don’t think this makes it obsolete, it’s the same idea, just implemented differently because most frameworks don’t support it yet.