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.
Dynamic tool loading is off by default: dynamic_tools defaults to False, so every schema is sent on every request until you turn it on. This page shows how to turn it on, see it working, and when to leave 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

Inspect the catalog

Building the LLM is what pulls the server’s tools into the catalog. The agent already did that when it was constructed; rebuilding it is harmless and makes the step explicit:
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 leave 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.
Your swarms predates mcp 2.x support, which renamed that function. Upgrade with pip install -U swarms; 15.0.1 and later work with both mcp 1.x and 2.x.
A single tool call may run for tool_timeout seconds, 120 by default. Raise it with mcp_config=MCPConnection(url=MCP_SERVER, tool_timeout=300). mcp_timeout only bounds connecting and sending requests.

Next