Skip to content

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

Closed

Description

Environment

  • agent-framework-core: 1.0.0rc5
  • mcp (Python SDK): latest
  • MCP server: [email protected] (via npx -y mongodb-mcp-server)
  • Python: 3.14
  • OS: Windows 11

Description

MCPStdioTool.call_tool hangs indefinitely when the MCP server sends a resources/updated notification alongside the
tool result. The underlying mcp Python SDK (ClientSession.call_tool) completes successfully with the same server and
arguments.

Steps to Reproduce

import asyncio
import os
from agent_framework import MCPStdioTool
from dotenv import load_dotenv

load_dotenv(override=False)

async def main():
env = dict(os.environ)
env["MDB_MCP_CONNECTION_STRING"] = os.getenv("MDB_MCP_CONNECTION_STRING")

  mcp = MCPStdioTool(
      name="MongoDB",
      command="npx",
      args=["-y", "mongodb-mcp-server"],
      env=env,
      load_prompts=False,
      request_timeout=30,
  )

  async with mcp:
      print(f"Connected, {len(mcp.functions)} tools available")
      tool = {fn.name: fn for fn in mcp.functions}["list-collections"]
      # This hangs indefinitely:
      result = await tool.invoke(arguments={"database": "sample_mflix"})
      print(result)

asyncio.run(main())

Expected Behavior

list-collections returns the result within the request_timeout window.

Actual Behavior

The call hangs indefinitely. Logs show the server responds and sends a resource notification, but the framework never
returns:

INFO:agent_framework._mcp:[server]: Detected a MongoDB connection string in the configuration, trying to connect...
INFO:agent_framework._mcp:[server]: Server with version 1.9.0 started with transport StdioServerTransport
INFO:agent_framework:Function name: list-collections
INFO:agent_framework._mcp:[resources]: Resource updated: debug://mongodb

Workaround

Using the mcp SDK directly (which agent-framework depends on) works without issue:

from mcp.client.session import ClientSession
from mcp.client.stdio import StdioServerParameters, stdio_client

async with stdio_client(server=StdioServerParameters(...)) as transport:
async with ClientSession(read_stream=transport[0], write_stream=transport[1]) as session:
await session.initialize()
result = await session.call_tool("list-collections", {"database": "sample_mflix"})
# Returns immediately with correct result

Analysis

The mongodb-mcp-server sends a resources/updated notification (debug://mongodb) during tool execution. The framework's
call_tool method (_mcp.py:1031) or the result parsing pipeline appears to not complete when these interleaved
notifications arrive, even though the underlying ClientSession handles them correctly.

Activity

  1. changed the title [-]Title: MCPStdioTool.call_tool hangs when MCP server sends resource notifications during tool execution[/-] [+]Python: Title: MCPStdioTool.call_tool hangs when MCP server sends resource notifications during tool execution[/+] on Mar 25, 2026
  2. changed the title [-]Python: Title: MCPStdioTool.call_tool hangs when MCP server sends resource notifications during tool execution[/-] [+]MCPStdioTool.call_tool hangs when MCP server sends resource notifications during tool execution[/+] on Mar 25, 2026
  3. changed the title [-]MCPStdioTool.call_tool hangs when MCP server sends resource notifications during tool execution[/-] [+]Python: MCPStdioTool.call_tool hangs when MCP server sends resource notifications during tool execution[/+] on Mar 25, 2026
  4. manjunathshiva commented on Mar 25, 2026

    @manjunathshiva
    ContributorAuthor

    Raised a fix for this: #4898

  5. removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Mar 25, 2026
  6. moved this from Planned to In Progress in Agent Frameworkon Mar 25, 2026
  7. moved this from In Progress to In Review in Agent Frameworkon Mar 30, 2026
  8. moved this from In Review to Done in Agent Frameworkon May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

pythonUsage: [Issues, PRs], Target: Python

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions