runToolInIsolate function

Future<Map<String, Object?>> runToolInIsolate(
  1. String toolName,
  2. Map<String, Object?> args,
  3. McpLimits limits,
  4. Duration timeout,
)

Runs computeTool for toolName in-process, bounding it with a cooperative timeout (Future.timeout).

This platform has no dart:isolate, so — unlike the native executor — the timeout cannot forcibly kill CPU-bound code that never yields to the event loop; it only stops awaiting the result. Same signature and error-result shape as the native runToolInIsolate so callers are platform-agnostic.

Implementation

Future<Map<String, Object?>> runToolInIsolate(
  String toolName,
  Map<String, Object?> args,
  McpLimits limits,
  Duration timeout,
) async {
  try {
    return await computeTool(toolName, args, limits).timeout(
      timeout,
      onTimeout: () =>
          _errorResult('Execution timed out after ${timeout.inMilliseconds}ms'),
    );
  } catch (e) {
    return _errorResult('$e');
  }
}