Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(lume): make MCP server runVM non-blocking (#854)

Francesco Bonacci2bc09f87528d
diff --git a/libs/lume/src/Server/MCPServer.swift b/libs/lume/src/Server/MCPServer.swift
index cbe0dcf58e..c3ed30f95f 100644
--- a/libs/lume/src/Server/MCPServer.swift
+++ b/libs/lume/src/Server/MCPServer.swift
@@ -572,17 +572,33 @@ final class LumeMCPServer {
sharedDirectories.append(SharedDirectory(hostPath: expandedPath, tag: "shared", readOnly: false))
}
- try await controller.runVM(
- name: name,
- noDisplay: noDisplay,
- sharedDirectories: sharedDirectories,
- storage: storage
- )
+ // Run VM in detached task to avoid blocking (same pattern as HTTP API)
+ Task.detached { @MainActor @Sendable in
+ do {
+ let vmController = LumeController()
+ try await vmController.runVM(
+ name: name,
+ noDisplay: noDisplay,
+ sharedDirectories: sharedDirectories,
+ storage: storage
+ )
+ } catch {
+ Logger.error(
+ "Failed to start VM in background task",
+ metadata: [
+ "name": name,
+ "error": error.localizedDescription,
+ ])
+ }
+ }
+
+ // Wait briefly for VM to initialize and get IP
+ try await Task.sleep(nanoseconds: 2_000_000_000) // 2 seconds
// Get VM details after starting to return IP
- let vm = try controller.get(name: name, storage: storage)
+ let vmDetails = try controller.getDetails(name: name, storage: storage)
var response = "VM '\(name)' started successfully."
- if let ip = vm.details.ipAddress {
+ if let ip = vmDetails.ipAddress {
response += "\nIP Address: \(ip)"
response += "\nSSH: ssh lume@\(ip) (password: lume)"
}