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
taha-yassine commentedon Mar 15, 2025
I'm experiencing the same issue.
When stepping into
session.call_tool()with a debugger and going throughBaseSession.send_request()line by line, it seems to work, but I have no idea why.IraCyoee commentedon Apr 3, 2025
Hey, I’m running into the same problem here! I’m on WSL (Ubuntu 24.04 on Windows) and can’t get any server replies when using the MCP client. Super annoying. But here’s the weird thing—it works totally fine on native Windows. I’m using the same
uvsetup for both environments, with this config:For example, when I try building a tool with this code:
And then test the
tool_callresult like this:It just hangs on WSL—no response, nothing. Anyone else seeing this? Or maybe have a workaround? Works like a charm on Windows, though!
WikiHkz commentedon Apr 9, 2025
I'm experiencing the same issue. Did you solve it?
IraCyoee commentedon Apr 10, 2025
You just need to add websocket support to the client to make it work.
anticomputer commentedon Apr 21, 2025
There does appear to be some sort of race condition in the handling of stdio tool call results at the jsonrpc transport layer. Similar to other bug reports in this issue, I can trace my call results back to actually returning a result, yet at the client session await level this result is never surfaced, resulting in a dead lock. This happens non-deterministically, and things like timing do seem to impact when it happens, which smells like a race condition somewhere in the jsonrpc event handling missing the actual output coming from the tool call. For me this mostly happens when I have longer running tool calls in sequence, and on the third or fourth result the jsonrpc stdio wrapper no longer surfaces results that are returned from the FastMCP tool call method itself.
loadingvx commentedon Apr 29, 2025
I encountered the same issue. To facilitate problem identification, I extracted the code into a separate file and found that the client could return normally. However, within the project architecture, it was strange—call_tools could send requests but failed to receive results. Eventually, I used a separate loop to handle the await process of call_tools, and then it worked properly. Although the exact reason remains unclear, the issue was resolved.
maybe it's python's async related issue, when using llm streaming and calling-tools in the same thread. maybe ...
sagardspeed2 commentedon May 8, 2025
I am getting the same issue, when I try to use
call_toolin the python's main thread, it work fine. but when I created new thread throughThreadingand when I try to call thecall_toolfrom that thread, it stuck.taaresh7 commentedon May 11, 2025
@anticomputer @WikiHkz @herrrX Did you solve it? For me I can see on the server side that the tool call has executed successfully but on the client side the await session.call_tool() never returns anything. The server side works perfectly on the MCP inspector and claude desktop
LiaMukaidaisi commentedon May 20, 2025
Do we have any fix for this? Experiencing the same issue....
wfeng007 commentedon May 21, 2025
是不是事件循环导致的? 就是你那个self.loop 给的正好了 之前,启动server的那个loop。而你本身这个方法在另一个loop中进行的。 就是那个asyncio.run()会使用新的事件循环。
wfeng007 commentedon May 21, 2025
@loadingvx
ochafik commentedon Sep 5, 2025
Wondering if this could be related to our use of shell=True (cf. #1257). @felixweinberger wdyt?
felixweinberger commentedon Sep 5, 2025
People seem to be consistently mentioning Windows / WSL on this - to isolate potential RCs is everyone experiencing this issue using that environment?
anticomputer commentedon Sep 10, 2025
This is still an issue for us with stdio MCP servers specifically, and long running tool tasks (but well within the configured client timeout window). Verified the MCP server tool completes, response is sent, but client never receives the response. It seems to be an issue at the jsonrpc over stdio layer where the server response is simply missed. This may be due locking issues related to os i/o buffer filling (i.e. asyncio.wait() locking on pending full stdout pipes) ... but definitely a head scratcher.
This happens on MacOS and Linux in our testing, but only with longer running tool calls (i.e. in the 60 second+ area), but again, no observable timeouts occur before the actual client session timeout hits while the client is pending the response.
This is an example debug log of the lockup occurring, the MCP server in this case is a stdio FastMCP 2.0 server, the client an mcp sdk connection. On Linux this locks up way more frequently than on MacOS, but essentially the response on the last tool call which takes ~40 seconds is missed entirely by the client. The client then eventually times out at its configured client session timeout.
EDIT: note that when using the streamable transport, everything works as expected, which seems to indicate there is something specific to the stdio polling that's causing this Heisenbug.
7 remaining items
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…