Bug Description
When using Spring AI with Anthropic Claude and MCP tools in streaming mode, a ClassCastException occurs preventing tool execution.
Stack Trace
java.lang.ClassCastException: class org.springframework.ai.anthropic.api.AnthropicApi$MessageDeltaEvent cannot be cast to class org.springframework.ai.anthropic.api.AnthropicApi$ToolUseAggregationEvent
at org.springframework.ai.anthropic.api.StreamHelper.mergeToolUseEvents(StreamHelper.java:86)
at reactor.core.publisher.MonoReduceSeed$ReduceSeedSubscriber.onNext(MonoReduceSeed.java:116)
...
Environment
- Spring AI: 1.0.2, 1.1.0-M1 (both affected)
- Spring Boot: 3.5.6
- MCP SDK: 0.13.0
- Tools: MCP Gmail integration
Reproduction
- Configure Anthropic ChatClient with MCP tools
- Call .stream() on ChatClient with tool-enabled prompt
- ClassCastException occurs when tool execution is attempted
Expected Behavior
Tools should execute without ClassCastException during streaming
Actual Behavior
ClassCastException prevents all tool execution in streaming mode
Workaround
None found. Switching to .call() (non-streaming) might work but defeats the purpose.