Skip to main content
Tool definitions are re-sent on every request. One MCP server can expose dozens of tools, so a naively connected agent pays for every schema on every call, for the whole run — and a model choosing among forty tools picks wrong more often than one choosing among four. Dynamic tool loading fixes both. The agent connects, puts every discovered tool into a searchable catalog, and sends only a tool_search tool up front. When the model needs something, it searches, the matching schemas are loaded, and they are included from the next request onwards.
This is the default for MCP agents — dynamic_tools=True unless you say otherwise. This page shows how to see it working and when to turn it off.

Build it

1

Install and set your key

2

Create the agent

max_loops="auto" lets the agent decide when it is done — a good fit here, because searching for a tool and then using it takes an unknown number of turns.
3

Force the connection and inspect the catalog

Building the LLM is what pulls the server’s tools into the catalog, so do it explicitly when you want to look:
The catalog holds the server’s tools; the request carries tool_search and nothing else. That gap is the saving, repeated on every call of the run.
4

Run a task and watch what gets loaded

After the run, loaded_names shows the handful of tools the task actually needed — everything else stayed out of the context window.

The complete script

Two things are added when deferral is on:
  1. A tool_search tool, which takes a keyword query and loads the matching schemas.
  2. A system prompt notice telling the model that most of its tools are not loaded, that any tool list it has seen describes what exists rather than what it can call, and that it should load everything it expects to need for a subtask in one search.
Loading changes the tool list, so the underlying LLM client is rebuilt at that point — otherwise the model could not call what it had just found.

When to turn it off

Troubleshooting

It has tool_search and needs to use it. Check that the system prompt notice survived — if you passed your own system_prompt, swarms appends the notice, but a prompt that insists “you have exactly these tools” fights it.
The server was unreachable and the agent carried on without those tools by design. Check the URL and any credential; run with verbose=True to see the fetch error.
mcp 2.x renamed it. Pin the 1.x line: pip install 'mcp>=1.28.1,<2.0.0'.
Raise mcp_timeout on the agent. The default of 30 seconds is short for tools like read_wiki_contents.

Next