[Bug]: No matching MCP agent found for tool name: tavily_tavily-search
Is there an existing issue for the same bug? (If one exists, thumbs up or comment on the issue instead).
- [x] I have checked the existing issues.
Describe the bug and reproduction steps
In the online app, I got this error:
Unexpected error while running action: ValueError: No matching MCP agent found for tool name: tavily_tavily-search
It was on conversation e9c5077da269444493f5eec589677907 after many tavily searches.
I wonder if the many searches caused an issue?
OpenHands Installation
app.all-hands.dev
OpenHands Version
0.41.0
Operating System
None
Logs, Errors, Screenshots, and Additional Context
No response
Hmm this may be because every MCP tool call creates a new connection to the MCP server. If the MCP server fails to respond, then we throw an error. We should implement a retry mechanism for the MCP client
This is reproducible, I got it in this conversation too 36c4b4f3087a4cb8a096ef8481668d59.
I'm not sure if a retry mechanism is the right approach though. Wouldn't the issue be that connections were not being properly closed or something? Since each connection would be done after the previous one supposedly finished.
@openhands Do an RCA and try to create a reproduction script for this. I think it is likely because either the MCP client or tavily server is not closing connections appropriately, but I might be wrong and there may be some other reason. Do NOT attempt to fix the problem, just reproduce it -- I just want to figure out the root cause of the problem.
I'm on it! neubig can track my progress at all-hands.dev
I've completed a Root Cause Analysis (RCA) for issue #9030 regarding the "No matching MCP agent found for tool name: tavily_tavily-search" error.
Summary of Work
I created three reproduction scripts to help identify the root cause of the issue:
-
Basic Reproduction Script (
reproduce_mcp_tavily_issue.py): Performs multiple consecutive Tavily searches using a single MCP client instance. -
Connection Management Script (
reproduce_mcp_connection_issue.py): Creates a new MCP client for each search, simulating how the actual code behaves, to identify issues with connection creation and management. -
Resource Monitoring Script (
reproduce_mcp_connection_pooling.py): Reuses a single MCP client but adds detailed resource monitoring to track memory usage, file descriptors, and other resources to identify potential leaks.
I also created a detailed README (mcp_tavily_issue_reproduction.md) that explains:
- The issue background
- How to use the reproduction scripts
- Key areas to investigate
- Code analysis of the likely causes
- Potential solutions
Root Cause Analysis
Based on code analysis, the most likely cause of the issue is in how connections are managed in MCPClient.call_tool(). Each call to this method creates a new connection with async with self.client:, but if these connections are not properly closed, it could lead to resource exhaustion.
After many Tavily searches, the system may run out of available connections or resources, causing the "No matching MCP agent found" error when it tries to find a client for the tool.
PR Created
I've successfully created a pull request (#9031) with these reproduction scripts. The PR has been pushed to the remote branch openhands/reproduce-mcp-tavily-issue and is linked to issue #9030.
The PR includes all the necessary files and a detailed explanation of the likely root cause, without attempting to fix the issue as requested.
Hmm perhaps - I improved closing client connections previously in this PR #8931
We're still awaiting release for it
Also here is the relevant code if it helps
The error path No matching MCP agent found for tool name: tavily_tavily-search is hit when we failed to create MCP clients before executing the tool call
(we create new MCP clients every time to verify that the MCP server is alive)
Ah so maybe it's just not released yet
Thanks!
Based on the comments this should be released now