Skip to content

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

@manjunathshiva

Description

@manjunathshiva

Environment

  • agent-framework-core: 1.0.0rc5
  • mcp (Python SDK): latest
  • MCP server: mongodb-mcp-server@1.9.0 (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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions