callTool method
Call a tool on the server
Implementation
Future<CallToolResult> callTool(
String name,
Map<String, dynamic> toolArguments,
) async {
if (!_initialized) {
throw McpError('Client is not initialized');
}
if (!_statelessMode && _serverCapabilities?.tools != true) {
throw McpError('Server does not support tools');
}
// Create a clean params map with properly typed values
final Map<String, dynamic> params = {
'name': name,
'arguments': Map<String, dynamic>.from(toolArguments),
};
// 2026-07-28 (SEP-2577): a stateless `tools/call` may return
// `input_required`; the MRTR driver fulfills the server's input requests and
// re-issues until a terminal result. Legacy path = a single request.
final response = _statelessMode
? await _sendRequestWithMrtr('tools/call', params)
: await _sendRequest('tools/call', params);
return CallToolResult.fromJson(response);
}