Fix streaming mode for CLI, MCP, TCP protocols and add SSE reconnection
Summary
call_tool_streaming failed for several protocols instead of emitting the full result as a single chunk the way the HTTP protocol does. This PR fixes those and implements the SSE reconnection that the call template already advertised.
Streaming fixes
- CLI: raised
NotImplementedErroron every streaming call. Now runs the command and yields the result once. - MCP: yielded the un-awaited coroutine instead of the result.
- TCP: was a plain coroutine returning a generator, so the client's
async forfailed with a TypeError. UDP gets the same shape and return annotation.
SSE
reconnect/retry_timeoutwere accepted but never acted on. When an established stream drops, the client now waitsretry_timeoutms (overridden by anyretry:field from the server), reconnects with theLast-Event-IDheader, and gives up afterMAX_RECONNECT_ATTEMPTS(5) per call so a tool call can never hang forever. A clean end of stream completes the call and never reconnects. Connection or HTTP errors on the initial request still fail immediately, so a wrong URL does not trigger retries. The redirect refusal from the security hardening applies to every attempt.- The parser handles CRLF line endings and a trailing event without a terminating blank line.
Already correct and untouched: file, text, gql, http, streamable_http, websocket.
Test plan
- New tests: single-chunk streaming for CLI, MCP, TCP, UDP
- New tests: SSE reconnect resumes with
Last-Event-ID;reconnect=Falseraises after partial events; attempt cap is honored -
pytestover the cli, socket, mcp and http plugin test suites on top of currentdev: 288 passed, 9 skipped
Companion PR: universal-tool-calling-protocol/typescript-utcp#41 brings the TypeScript implementation to parity.
🤖 Generated with Claude Code
Summary by cubic
Fixes streaming tool calls for CLI, MCP, TCP, and UDP, which previously failed or yielded the wrong object instead of emitting the full result as one chunk. Also implements and hardens SSE reconnection, which the call template advertised but never performed, and pins the MCP plugin to mcp 1.x.
Bug Fixes
- CLI now runs the command and yields the result once instead of raising
NotImplementedError. - MCP now awaits the tool call before yielding it.
- TCP streaming is now an async generator; UDP gets the same shape and
AsyncGeneratorreturn annotation. - Pins
mcpto<2; version 2.x removedFastMCPandMcpError, which broke test collection in CI.
New Features
- When an established SSE stream drops, the client waits
retry_timeoutms (or the server'sretry:value), reconnects withLast-Event-ID, and stops after 5 attempts. - A clean end of stream completes the call without reconnecting; initial connection and HTTP errors still fail immediately, and redirects remain refused.
- Reconnect handshake failures are retried (only the initial handshake fails fast), and the reconnect delay is capped at 60 s.
- The handshake is bounded by a 30-second timeout so a silent server cannot hang the call.
- The parser handles CRLF splits across chunks, multi-byte UTF-8, and trailing unterminated events; events over 16 MiB without a delimiter raise
SseProtocolError, which is never retried.