Environment
- Python SDK:
claude-agent-sdk==0.1.47
- Python: 3.11
- OS: Linux (Docker, amd64)
- Bundled CLI version: 2.1.70 (from JSONL
"version":"2.1.70")
- MCP setup:
create_sdk_mcp_server with custom tools
Problem
SDK MCP server tool calls start failing with "Stream closed" after approximately 60-70 seconds of operation, even when tools are actively executing and returning results successfully. Built-in tools (Read, Grep) continue working fine during the same session.
Reproduction
- Register custom MCP tools via
create_sdk_mcp_server
- Send a query that triggers many sequential MCP tool calls over 60+ seconds (e.g., log analysis workflow with
find_errors → Read → Grep → custom tool calls)
- After ~70s from session start, custom MCP tool calls return:
{"type": "tool_result", "content": "Stream closed", "is_error": true}
- Built-in tools (Read, Grep) called in the same session at the same time continue working normally
Evidence from JSONL session logs
Tool call and "Stream closed" timestamps differ by only 1-5ms — the tool never gets a chance to execute:
03:41:24.887 tool_call: mcp__my-server__git_get_commits_diff
03:41:24.892 tool_result: "Stream closed" (is_error=true) ← 5ms, tool didn't run
03:41:27.619 tool_call: mcp__my-server__git_get_commits_diff
03:41:27.620 tool_result: "Stream closed" (is_error=true) ← 1ms
03:41:30.747 tool_call: mcp__my-server__git_get_commits_diff
03:41:30.755 tool_result: "Stream closed" (is_error=true) ← 8ms
Built-in Grep and Read tools called between these failures succeed normally. Only custom MCP tools are affected.
Root Cause
This is the same issue as anthropics/claude-agent-sdk-typescript#114:
The bundled CLI does not reset lastActivityTime when MCP server responses arrive. After the inactivity timer exceeds the stream close threshold (~15s default), subsequent MCP tool calls are immediately rejected with "Stream closed", while built-in tools (which don't go through MCP) are unaffected.
Request
Apply the resetLastActivityTime() fix from #114 to the bundled CLI binary shipped in the Python SDK
Related Issues
Environment
claude-agent-sdk==0.1.47"version":"2.1.70")create_sdk_mcp_serverwith custom toolsProblem
SDK MCP server tool calls start failing with
"Stream closed"after approximately 60-70 seconds of operation, even when tools are actively executing and returning results successfully. Built-in tools (Read, Grep) continue working fine during the same session.Reproduction
create_sdk_mcp_serverfind_errors→Read→Grep→ custom tool calls){"type": "tool_result", "content": "Stream closed", "is_error": true}Evidence from JSONL session logs
Tool call and "Stream closed" timestamps differ by only 1-5ms — the tool never gets a chance to execute:
Built-in Grep and Read tools called between these failures succeed normally. Only custom MCP tools are affected.
Root Cause
This is the same issue as anthropics/claude-agent-sdk-typescript#114:
The bundled CLI does not reset
lastActivityTimewhen MCP server responses arrive. After the inactivity timer exceeds the stream close threshold (~15s default), subsequent MCP tool calls are immediately rejected with "Stream closed", while built-in tools (which don't go through MCP) are unaffected.Request
Apply the
resetLastActivityTime()fix from #114 to the bundled CLI binary shipped in the Python SDKRelated Issues