Skip to content

[BUG] SDK MCP server tool calls fail with "Stream closed" after ~70s - Python SDK v0.1.47 #676

@waigitNV

Description

@waigitNV

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

  1. Register custom MCP tools via create_sdk_mcp_server
  2. Send a query that triggers many sequential MCP tool calls over 60+ seconds (e.g., log analysis workflow with find_errorsReadGrep → custom tool calls)
  3. After ~70s from session start, custom MCP tool calls return:
    {"type": "tool_result", "content": "Stream closed", "is_error": true}
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions