Skip to content

#4896 : Fix deadlock in MCPTool.message_handler when server sends tool/prompt…#4898

Closed
manjunathshiva wants to merge 2 commits intomicrosoft:mainfrom
manjunathshiva:fix/mcp-message-handler-deadlock
Closed

#4896 : Fix deadlock in MCPTool.message_handler when server sends tool/prompt…#4898
manjunathshiva wants to merge 2 commits intomicrosoft:mainfrom
manjunathshiva:fix/mcp-message-handler-deadlock

Conversation

@manjunathshiva
Copy link

Summary

  • Bug: message_handler awaits load_tools()/load_prompts() inline when notifications/tools/list_changed
    arrives. load_tools() calls _ensure_connected()send_ping(), but the session can't process the ping while
    blocked on an in-flight call_tool response — deadlock.
  • Fix: Replace inline reloads with debug logging. Tools/prompts refresh on the next connect(reset=True) or
    explicit load_tools() call.
  • Repro: Any MCP server that sends tools/list_changed during tool execution (e.g. mongodb-mcp-server) causes
    MCPStdioTool.call_tool to hang indefinitely.

Fixes #4896

Test plan

  • Run MCPStdioTool with mongodb-mcp-servercall_tool should return without hanging
  • Verify tools are still loaded correctly on initial connect()
  • Verify connect(reset=True) still refreshes tools

… list_changed notifications

  message_handler was awaiting load_tools()/load_prompts() inline on
  notifications/tools/list_changed. load_tools() calls _ensure_connected()
  which sends a ping, but the session cannot process it while blocked
  waiting for an in-flight call_tool response — causing a deadlock.

  Replace inline reloads with debug logging. Tools/prompts will be
  refreshed on the next connect(reset=True) or explicit load_tools() call.

  Fixes microsoft#4896
@giles17
Copy link
Contributor

giles17 commented Mar 25, 2026

This is being worked on here: #4866

@giles17 giles17 closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: MCPStdioTool.call_tool hangs when MCP server sends resource notifications during tool execution

2 participants