toolCalls property
Get tool calls from the response
Implementation
@override
List<ToolCall>? get toolCalls {
final content = _rawResponse['content'] as List?;
if (content == null || content.isEmpty) return null;
final toolCalls = <ToolCall>[];
// Handle regular tool_use blocks
final toolUseBlocks =
content.where((block) => block['type'] == 'tool_use').toList();
for (final block in toolUseBlocks) {
toolCalls.add(ToolCall(
id: block['id'] as String,
callType: 'function',
function: FunctionCall(
name: block['name'] as String,
arguments: jsonEncode(block['input']),
),
));
}
// Handle MCP tool_use blocks (Anthropic MCP connector)
final mcpToolUseBlocks =
content.where((block) => block['type'] == 'mcp_tool_use').toList();
for (final block in mcpToolUseBlocks) {
toolCalls.add(ToolCall(
id: block['id'] as String,
callType: 'mcp_function',
function: FunctionCall(
name: block['name'] as String,
arguments: jsonEncode(block['input']),
),
));
}
return toolCalls.isEmpty ? null : toolCalls;
}