callTool method

Future<CallToolResult> callTool(
  1. String name,
  2. Map<String, dynamic> arguments
)

Call a tool through its registered handler, in-process. The handler may return any value with the protocol's JSON form (toJson()), as on the wire, so a result built with another package's generated types arrives as this package's CallToolResult.

Implementation

Future<CallToolResult> callTool(
  String name,
  Map<String, dynamic> arguments,
) async {
  final tool = _tools[name];
  if (tool == null) {
    throw McpError('Tool not found: $name', code: ErrorCode.invalidParams);
  }

  final handler = _toolHandlers[name];
  if (handler == null) {
    throw McpError('No handler registered for tool: $name');
  }

  return _asResult(await handler(arguments), CallToolResult.fromJson);
}