feat(mcp): refresh tools for active conversations - #4402
Conversation
Co-authored-by: openhands <openhands@all-hands.dev>
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
1 similar comment
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
|
Hi @neubig and @VascoSch92 — thank you both for the work and review around #4367 and #4369. This PR follows the same line of work. #4367 handles add/update/remove reconciliation while an MCP connection remains alive, and #4369 hardens that path. This PR covers a separate deployment boundary: when the MCP server process is replaced, an existing conversation can explicitly reconnect and refresh its tool snapshot. It reuses the reconciliation path introduced in #4367 and preserves the conversation rather than forking or recreating it. CI is green now. When you have a chance, I’d really appreciate your thoughts on whether this is the right lifecycle and API boundary. Thank you! |
HUMAN:
We expose backend-owned MCP tools to OpenHands App Server running in E2B. As these tools may change between releases, existing conversations need a lightweight way to refresh their tool definitions without being forked or recreated.
AGENT:
Why
notifications/tools/list_changedcan reconcile a live MCP connection, but it cannot cross an MCP server deployment that terminates the old process. An active conversation therefore needs an explicit way to reconnect and replace its MCP tool snapshot without rebuilding the conversation or losing its history and workspace.Other agent runtimes expose an explicit lifecycle action for the same operational need, although their APIs differ:
config/mcpServer/reload, which reloads MCP configuration and queues a refresh for every loaded thread on its next active turn; its implementation preserves the loaded threads while refreshing their MCP runtime.tools/list_changednotifications also replace its cached tool definitions.This PR adds the narrow equivalent OpenHands is missing: refresh the MCP runtime owned by an existing conversation while preserving the conversation itself.
Summary
Conversation.refresh_mcp_tools()for local and remote conversations, with an Agent Server REST action.Issue Number
N/A
How to Test
The real deployment test runs in both stateful and stateless HTTP modes. It starts FastMCP in a separate process with
old_toolandchanging(old: str), terminates it, starts a new process on the same URL withnew_toolandchanging(new: int), then refreshes the sameLocalConversation. It verifies:old_toolis removed andnew_toolis added.changingreceives the new description and input schema.changingandnew_tool.Commands and results:
Video/Screenshots
N/A — SDK and Agent Server API change with no visual surface.
Type
Notes
mainand does not depend on open PR fix(mcp): close reconciliation gaps left by #4367 #4369; it only reuses reconciliation already merged in fix(mcp): reconcile live agent tool snapshots #4367.