runToolInIsolate function
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');
}
}