callTool method

Future<McpJsonMap> callTool(
  1. String name, {
  2. Object? id,
  3. McpJsonMap arguments = const <String, Object?>{},
  4. bool streamable = true,
  5. String? protocolVersion,
  6. Map<String, String> headers = const <String, String>{},
})

Calls an MCP tool through the active session.

Implementation

Future<McpJsonMap> callTool(
  String name, {
  Object? id,
  McpJsonMap arguments = const <String, Object?>{},
  bool streamable = true,
  String? protocolVersion,
  Map<String, String> headers = const <String, String>{},
}) async {
  final toolName = _validatedMcpToolName(name, 'name');
  final response = await request(
    'tools/call',
    id: id,
    params: <String, Object?>{'name': toolName, 'arguments': arguments},
    streamable: streamable,
    protocolVersion: protocolVersion,
    headers: _headersWithToolParameterHeaders(toolName, arguments, headers),
  );
  return _validatedToolCallResult(
    _jsonRpcResultFrom(response, method: 'tools/call'),
    label: 'tools/call result',
  );
}