News for hackers. Stuff that matters.

Ask HN: How do you prevent MCP agents from looping in production?

I'm building with MCP and starting to run agents with more autonomy — multiple tools, longer sessions, less human oversight. The failure modes I keep hitting aren't the model being wrong, they're the agent making too many calls, retrying things that won't work, or calling tools it shouldn't need for the task. Right now I'm just setting hard iteration limits in my agent code, which feels like a blunt instrument. What are other people doing here — especially anyone running MCP agents in anything close to production?
( 4 comments | 3 points | on HN )
Re:Ask HN: How do you prevent MCP agents from looping in pro... by dexwiz on Tuesday March 10, 2026 @11:33PM (#47331488)
What is wrong with a blunt tool? Almost every other system ends up with a hard cap of retries.
Re:Ask HN: How do you prevent MCP agents from looping in pro... by verdverm on Wednesday March 11, 2026 @02:09AM (#47332194)
It's all about context management
Re:Ask HN: How do you prevent MCP agents from looping in pro... by algis-hn on Wednesday March 11, 2026 @12:31PM (#47337751)
Hard caps treat the symptom. If agents call tools they shouldn't need, the root cause is tool set visibility - 80 tools in context means the model tries irrelevant ones, fails, and retries. Pre-filtering to a semantically relevant subset per request (BM25 on the incoming query works well) eliminates most retry loops before they start; the cap stays as backstop for genuinely pathological cases.
Re:Ask HN: How do you prevent MCP agents from looping in pro... by shubhamintech on Wednesday March 11, 2026 @02:22PM (#47339226)
Hard limits are a good first layer but they don't tell you why the agent is looping. Retrying because it's confused, retrying because a dependency is flaky, and genuine planning loops are three different problems with different fixes. What helped us was logging the agent's intent at each step, and if it's asking the same underlying question three times in different syntax, that's the signal to bail early rather than burning through your iteration budget.