Skip to content

Claude code hangs after successful MCP tool execution #145

@jkellyfenton

Description

@jkellyfenton

We are encountering an issue where claude code hangs indefinitely after MCP tool calls that involve long-running commands, such as expensive rebuild and retest commands that we run inside our monorepo (could last 10+ minutes). Our application never receives a message from Claude Code after the MCP tool execution.

Symptom: Claude Code executes MCP tool call, but then hangs indefinitely. The MCP server invocation runs to completion (we see the tool output in the CLI).

Example scenario:
Claude calls MCP tool
MCP tool executes lint, build, test commands using pythons subprocess.run()
One of these commands may be long running (e.g. testing a large package)

Suspected causes:

  • Possibly something times out between claude and the fastmcp server? We are using the streamable_http transport
  • Possibly something times out between claude-code-sdk-python and claude?
  • Resource-intensive calls within the MCP tool causing unexpected behavior causing claude code to crash or disconnect from the MCP server

Example logs -- the SessionMessage is the final output from our MCP tool after it succeeds:

2025-08-07T09:16:45.892123441Z	Sending message via SSE: SessionMessage(message=JSONRPCMessage(root=JSONRPCResponse(jsonrpc='2.0', id=4, result={'content': [{'type': 'text', 'text':".... blah blah MCP tool response ..."}, 'isError': False})), metadata=None)
2025-08-07T09:16:45.893093471Z	ping: b': ping - 2025-08-07 09:16:45.892830+00:00\r\n\r\n'
2025-08-07T09:16:45.893593681Z	Got event: http.disconnect. Stop streaming.
2025-08-07T09:16:45.895422390Z	chunk: b'event: message\r\ndata: {"jsonrpc":"2.0","id":4,"result":{"content":[{"type":"text","text":".... blah blah MCP tool response ..."},"isError":false}}\r\n\r\n'
2025-08-07T09:16:45.895484180Z	Setting up SSE connection
2025-08-07T09:16:45.895500800Z	Created new session with ID: 6f8a527f-b848-4ca0-a900-c24dbaf81559
2025-08-07T09:16:45.896095610Z	Starting SSE response task
2025-08-07T09:16:45.896124020Z	Yielding read and write streams
2025-08-07T09:16:45.899242010Z	Setting up SSE connection
2025-08-07T09:16:45.899306710Z	Created new session with ID: 895f53dc-3315-41fa-9b00-5eb4aa7add2e
2025-08-07T09:16:45.899314110Z	Starting SSE response task
2025-08-07T09:16:45.899338070Z	Yielding read and write streams
2025-08-07T09:16:45.901517679Z	Setting up SSE connection
2025-08-07T09:16:45.901554159Z	Created new session with ID: 0023c7c1-aaa9-4836-8e0a-37cc43419888
2025-08-07T09:16:45.901807790Z	Starting SSE response task
2025-08-07T09:16:45.902166460Z	Yielding read and write streams
2025-08-07T09:16:45.905046299Z	Client session disconnected 3e48dc8d-e9f6-485c-b8b6-d1459c45e474
2025-08-07T09:16:45.905484029Z	Starting SSE writer
2025-08-07T09:16:45.905560449Z	Got event: http.disconnect. Stop streaming.
2025-08-07T09:16:45.905568269Z	Starting SSE writer
2025-08-07T09:16:45.905572479Z	Got event: http.disconnect. Stop streaming.
2025-08-07T09:16:45.905660299Z	Starting SSE writer
2025-08-07T09:16:45.906029109Z	Sent endpoint event: /messages/?session_id=0023c7c1aaa948368e0a37cc43419888
2025-08-07T09:16:45.906397129Z	chunk: b'event: endpoint\r\ndata: /messages/?session_id=0023c7c1aaa948368e0a37cc43419888\r\n\r\n'
2025-08-07T09:16:45.906638559Z	Client session disconnected 6f8a527f-b848-4ca0-a900-c24dbaf81559
2025-08-07T09:16:45.906664979Z	Client session disconnected 895f53dc-3315-41fa-9b00-5eb4aa7add2e
2025-08-07T09:17:00.906090709Z	ping: b': ping - 2025-08-07 09:17:00.905752+00:00\r\n\r\n'
2025-08-07T09:17:15.907052317Z	ping: b': ping - 2025-08-07 09:17:15.906568+00:00\r\n\r\n'
2025-08-07T09:17:30.908281226Z	ping: b': ping - 2025-08-07 09:17:30.907905+00:00\r\n\r\n'
2025-08-07T09:17:45.909603535Z	ping: b': ping - 2025-08-07 09:17:45.909193+00:00\r\n\r\n'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions