Introduction

In my last post, Trimming MCP Tool Context Bloat, I provided a number of techniques for reducing context usage when adding MCP servers to your local environment. One of those techniques was what I called Lazy Tool Search, which is when you lean on the model to search for tools it needs rather than give it an explicit list of tools up front. The way that this is implemented in Open WebUI is based on the length of each tool’s definition - in my case, I configured it to only proactively advertise tools if their definitions were less than 400 characters.

While that exercise was wildly successful in reducing initial prompt size, over the past few weeks I began to feel that something was just “off” with my local LLM performance. It didn’t seem as…intelligent or efficient as before. And I noticed an increase in confusion around tool use. For example, my model would often proclaim that it was going to retrieve a page from my BookStack instance, only to call get_chapter instead. And things just seemed to be getting much slower overall.

In most cases, the LLM would eventually figure out the right path, but this got annoying enough that I decided to do some investigation today. With some AI-assisted troubleshooting, I began capturing and examining the traffic between Open WebUI and my AI server. I made a fascinating discovery - the LLM was trying really hard to find the right tools, but often failing to do so. In one extreme case, it made 58 tool discovery calls, adding 80k tokens to context! My context “optimization” was having the opposite effect!

Finding the Right Balance

In that prior blog post, I had hinted at the risk associated with lazy tool search:

Although this can lead to enormous start-of-chat context savings, it also carries a lot of risk - now that you’re not explicitly telling the LLM what tools are available, you’re relying on the LLM to proactively search for and find them, which is a much bigger ask. Make sure your LLM is strong with tool calling, and maybe give it some initial hints in the system prompt to give it a head’s up.

Unfortunately, that risk materialized, and now I had to figure out how to balance context trimming with preservation of function.

Make Sure the LLM Knows the Most Critical Tools

The single most helpful setting that I changed was to exclude my most foundational MCP services from the lazy tool search function. This ensured that the model would always be well-educated about the most critical tools while still saving some context by not automatically injecting definitions for lesser-used tools into every session.

Open WebUI provides an Always Loaded Tools regex which will exclude any tool definitions that match the pattern from the tool search feature. In my case, I set it to memory-mcp_*, bookstack-mcp-server_*. I could optimize this further by listing only the most critical tools in each service.

Use Tool Loading Deferral For Everything Else

I kept Open WebUI’s Tool Search enabled for less-used services like Joplin Notes, Gitea, and Home Assistant. I use these tools less frequently, so it was still a reasonable tradeoff to get some context win at the expense of potential difficulty using these tools. To compensate, when I do want to use these tools now, I give my LLM a hint, like “use the Joplin note creation tool to start a new note on the topic of…” to help prompt it to search for the appropriate tool.

This preserved a good chunk of my context savings while removing a ton of frustration using my most common tools.

Prevent the LLM from Spiraling

Another stop-gap setting that was helpful was to limit the number of tool iterations that the LLM could do before giving up. This prevented minutes of churning only to learn it was stuck in a loop or using the completely wrong tools. For Open WebUI, this is handled in the form of an environment variable. I set CHAT_RESPONSE_MAX_TOOL_CALL_ITERATIONS=15 in my docker-compose.yml and restarted the service.

This prevented the worst of the runaway tool spirals.

Conclusion: Outcomes are More Important than Size

While I was initially excited at the amount of tokens I was able to strip from my session startup, I ended up paying a steep price in efficiency and response quality. I learned I needed to do more troubleshooting to land on the right balance, and while my startup time might be a bit longer and my context a little bit more crowded than my aggressively optimized version, I tend to get the job done right the first time more often now, which is a net win. It was a good reminder to stay focused on outcomes and LLM response quality while tweaking my local AI environment!