Repository navigation
cannot get response from await session.call_tool() #262
Description
hello, I'm sorry to bother you. I've recently encountered a blocking issue with the MCP client.
I've set up an MCP server, and it runs in Claude successfully. However, when I use the client I set up, the call to the tool result = await session.call_tool() gets stuck and doesn't return a response. But when I use tools = await session.list_tools(), I can retrieve the list of tools.
Through logging within the client file, I'm able to confirm that the tool call has been initiated and executed successfully, and the result is obtained, but the client side can't receive the result. It seems there's an issue with the transmission layer of the protocol. I've been struggling with this for two days and have looked for solutions without success, even after upgrading the system version.
I removed the other logic and only kept the tool invocation. The code is as follows.
Looking forward to your reply.
from mcp import ClientSession, StdioServerParameters, types
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters( # Create server parameters for stdio connection
command="uvx",
args=[
"--from",
"git+ssh://xxxx.xx.xxx",
"server-name"
],
env=None
)
# Optional: create a sampling callback
async def handle_sampling_message(message: types.CreateMessageRequestParams) -> types.CreateMessageResult:
return types.CreateMessageResult(
role="assistant",
content=types.TextContent(
type="text",
text="Hello, world! from model",
),
model="gpt-3.5-turbo",
stopReason="endTurn",
)
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write, sampling_callback=handle_sampling_message) as session:
# Initialize the connection
await session.initialize()
# List available tools
tools = await session.list_tools()
# Call a tool
result = await session.call_tool("query-api-infos", arguments={"api_info_id": "8768555"})
print(result)
if __name__ == "__main__":
import asyncio
asyncio.run(run())
Activity
fix: Apply comprehensive cleanup and MCP STDIO blocking patch
feat(normalization): port STDIO buffering patches and reorganize tests
Add reproduction tests for issue #262: MCP Client Tool Call Hang
test: comprehensive test suite for issue #262 tool call hang
test: reproduce issue #262 race condition with minimal test
Add minimal standalone reproduction for issue #262
docs: comprehensive investigation of issue #262 race condition
feat: add debug delays to reproduce issue #262 race condition
fix: remove 'forever' cheat from race condition reproduction
docs: clarify race condition reproduction and explain WSL behavior
fix: remove dishonest hang simulation
challenger71498 commentedon Dec 26, 2025
Hi @herrrX and everyone who are interested in this issue,
I encountered the same issue as you did, and realised there are some issues related to this problem.
MCP SDK Issues
BaseSession cleanup is being cancelled on
__aexit__, leaving all remaining streams to be opened.ClientSession::call_toolnever responses.BaseSession::_receive_loopcleanup #1817 to fix this issue, you may look into it if you are interested in.Google ADK Issues
McpSessionManager does not follow AnyIO's structured concurrency; it may close the taskgroup with task differ to the one which started the taskgroup(especially when an error occured in TaskGroup).
There is no such timeout for tool call itself, MCP Session only relys on httpx timeout.
Concurrency problem on AgentTool: when you call Agent-as-a-tool in parallel with same agent, if one tool finishes the tool call early, corresponding every other tool calls are being failed, due to the early release of shared resource(McpSessionManager).
ResourceClosedError)feat: start and close ClientSession in a single task in McpSessionMan…
feat(normalization): port STDIO buffering patches and reorganize tests
fix: Apply comprehensive cleanup and MCP STDIO blocking patch
fix: Apply comprehensive cleanup and MCP STDIO blocking patch
IgnazioDS commentedon Jun 8, 2026
feat: start and close ClientSession in a single task in McpSessionMan…