Topic 3 of 5 · 6 min read
Managing many servers without flooding the context
Goal: Design a client configuration that namespaces, filters and defers tools from several servers to keep the model's context small.
Every tool you connect costs context on every turn, so a client that serves several servers must namespace names, filter by task, and load only what the model needs.
Check yourself · 1 of 3
Two connected servers both expose a tool called search. What is the standard fix on the client side?
Why it matters
Each tool definition (name, description and schema) is sent to the model with each request. Connect five servers with 30 tools each and the model reads 150 definitions before it reads your question. Choice gets worse as well: with near-duplicate tools, the model picks wrongly more often. Two servers may also expose a tool with the same name, such as search, and one would silently replace the other.
How to do it
- Namespace. Prefix each tool with its server name:
github__search,docs__search. Strip the prefix again before you sendtools/callto the right server. - Filter per task. Keep an allowlist per agent or per task. A support agent gets
tickets__*anddocs__search. It does not getgithub__delete_branch. - Defer. Instead of sending all definitions, send a small search tool. The model describes what it needs, the client returns the 3 to 5 best matching definitions and adds only those for the next turn. Claude's API offers a tool search feature for this, and you can build the same with a keyword or embedding index over your tool list.
- Consider code. For heavy workflows, expose servers as functions the model calls from code it writes. Intermediate results stay in the code runtime and never enter the context. Anthropic reports a sample workflow dropping from 150,000 to 2,000 tokens.
- Ask before risky calls. Mark which tools are read-only and require user approval for the rest. Show the server, the tool and the real arguments in the prompt.
Before and after
{
"servers": { "github": {}, "jira": {}, "docs": {} },
"toolsForModel": "all"
}
{
"servers": { "github": {}, "jira": {}, "docs": {} },
"namespace": "serverName__toolName",
"allow": ["jira__*", "docs__search", "github__get_issue"],
"deferred": true,
"approval": { "required": ["jira__transition_issue"] }
}
What goes wrong
- Name collisions. Two
searchtools, and the second registered wins. - All tools, always. Cost and latency rise, and accuracy falls.
- Approvals that hide the arguments. "Allow Jira?" teaches users to click yes.
Examples
Collision fixed with prefixes
Servers github and docs both expose search. The client registers github__search and docs__search. The model calls docs__search, and the client splits on the first __, finds the docs connection and sends tools/call with the name search.
A deferred lookup
The client sends the model only find_tools(query). The model calls it with "create a calendar event". The client searches 140 stored definitions and returns calendar__create_event and calendar__list_calendars. Only those two are added to the next request.
Key points
- Each tool definition is paid for in context on every request, so the count matters.
- Namespace tool names by server and strip the prefix before routing the call.
- Use per-task allowlists so an agent sees only the tools its job needs.
- Deferred search sends a few matching definitions on demand instead of the whole catalogue.
- Approval prompts must show the tool and its real arguments, not just the server name.
Common mistakes
- Registering every tool from every server on every turn.
- Letting two servers register the same tool name without a prefix.
- Using one broad allowlist for every agent in the product.
- Asking for approval with a generic message that omits the arguments.
Check yourself · 2 of 3
Why does connecting many servers hurt a model even before the user asks anything?
Check yourself · 3 of 3
An agent only answers support tickets. Which setup keeps its context small?
Practice items, not counted towards your mastery.
Start here
- Build an MCP client (official tutorial) (opens in a new tab)DocsFree
A working client that connects, lists tools and runs the tool-call loop with a model.
- MCP connector (Claude API docs) (opens in a new tab)DocsFree
How the Claude API connects to remote MCP servers for you, and the limits of that mode.
- Connectors and MCP servers (OpenAI API docs) (opens in a new tab)DocsFree
The OpenAI side of hosted MCP: server config, approvals and tool filtering.
More for this topic
- Code execution with MCP (Anthropic) (opens in a new tab)ArticleFree
Why many tool definitions cost context and how calling servers from code reduces it.