Stale MCP tools are persisted in agents (Infinite reconnect) #9809
Unanswered
AaronPowell96
asked this question in
Troubleshooting
Replies: 3 comments
|
The code examples and relevant PR do not reference the latest code-base changes. Please try reproducing the behavior on latest head of main branch. If there's still an issue, feel free to re-submit and issue and relevant PR. |
0 replies
|
Also, this should be considered for the tool list changing: #7117 |
0 replies
|
Does this still happen on your current build? The part I would isolate is whether removing the tool in the UI also removes its persisted agent reference. A stub tool renamed between two deployments should show that without involving a real backend. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
What happened?
When you connect an MCP to an agent and select tools, these tools are stored against the agent.
If you modify tool names or remove tools and redeploy the MCP, the agent will still reference these stale tools even when they no longer exist and they have correctly been removed from the Agent MCP Tools UI so you can no longer deselect them to prevent this issue.
When MCP servers are redeployed with different tool sets (tools added/removed), LibreChat agents experience infinite reconnection loops and never complete tool execution. The agent shows "establishing connection..." repeatedly without resolving.
The issue stems from stale tool references being passed to agents from the cached tool definitions:
loadAgentTools()retrieves cached tools and adds all MCP tools matching the requested server names to the agent's tool listcreateMCPTool()can't find the tool definition and triggersreconnectServer()The problem occurs in
loadAgentTools()where tools are filtered from cached definitions:Solution? Filter Out Stale MCP Tools During Agent Loading
Added validation in
loadAgentTools()to check if MCP tools actually exist in the current cached tools before including them in the agent's tool list:This focused solution prevents stale tool references from reaching the agent execution layer, eliminating the reconnection loops while preserving tool persistence and requiring no breaking changes.
However, note that this change does not remove the tools from the agents tool list in the DB which means if the tool is added back to the MCP it will be available again in the agent.
Version Information
b85950a
Steps to Reproduce
What browsers are you seeing the problem on?
No response
Relevant log output
Screenshots
No response
Code of Conduct
All reactions