feat(mcp): expose virtual machine suspend and resume
This commit is contained in:
1 parent
1b9e2ad1ec
commit
6b6a7ff81b
3 files changed
+29
-3
No files matched your search
@@ -6,7 +6,7 @@ Configure an MCP client to launch `reims-go.exe plugin connect reims.agent mcp`
|
||||
|
||||
## Current MCP tools
|
||||
|
||||
- `vm_list`, `vm_get`, `vm_start`, `vm_shutdown`, and `vm_unlock`
|
||||
- `vm_list`, `vm_get`, `vm_start`, `vm_shutdown`, `vm_suspend`, `vm_resume`, and `vm_unlock`
|
||||
- `computer` for screenshots, zoom, pointer, keyboard, and text input
|
||||
- `wait_for_screen` for changed or stable frames
|
||||
- `guest_public_key`, `guest_wait_ready`, and `guest_trust_host` for explicit SSH setup and host-key pinning
|
||||
|
||||
@@ -318,7 +318,7 @@ func (s *Server) invoke(ctx context.Context, name string, raw json.RawMessage) (
|
||||
return textResult(out), nil
|
||||
case "vm_start":
|
||||
return s.vmStart(ctx, raw)
|
||||
case "vm_shutdown":
|
||||
case "vm_shutdown", "vm_suspend", "vm_resume":
|
||||
var args struct {
|
||||
VM string `json:"vm"`
|
||||
}
|
||||
@@ -326,7 +326,8 @@ func (s *Server) invoke(ctx context.Context, name string, raw json.RawMessage) (
|
||||
return nil, err
|
||||
}
|
||||
var out hostReply
|
||||
if err := s.host.Call(ctx, "host/vm.shutdown", args, &out); err != nil {
|
||||
method := "host/vm." + strings.TrimPrefix(name, "vm_")
|
||||
if err := s.host.Call(ctx, method, args, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return textResult(map[string]any{"ok": true}), nil
|
||||
@@ -1056,6 +1057,8 @@ var toolCatalog = []map[string]any{
|
||||
{"name": "snapshot_restore", "description": "Restore a restore point on an MCP-owned temporary VM.", "inputSchema": objectSchema(map[string]any{"vm": map[string]any{"type": "string"}, "name": map[string]any{"type": "string"}}, []string{"vm", "name"})},
|
||||
{"name": "session_create", "description": "Create an isolated CoW VM session for a test run. Restore-point bases are unavailable on the current host.", "inputSchema": objectSchema(map[string]any{"vm": map[string]any{"type": "string"}, "isolation": map[string]any{"type": "string", "enum": []string{"clone", "live"}}}, []string{"vm"})},
|
||||
{"name": "session_dispose", "description": "Dispose an MCP-owned temporary VM session.", "inputSchema": objectSchema(map[string]any{"session_id": map[string]any{"type": "string"}}, []string{"session_id"})},
|
||||
{"name": "vm_suspend", "description": "Save a running VM state and stop its process.", "inputSchema": objectSchema(map[string]any{"vm": map[string]any{"type": "string", "description": "VM reference."}}, []string{"vm"})},
|
||||
{"name": "vm_resume", "description": "Restore a suspended VM from its saved state.", "inputSchema": objectSchema(map[string]any{"vm": map[string]any{"type": "string", "description": "VM reference."}}, []string{"vm"})},
|
||||
{"name": "vm_unlock", "description": "Enter the host-stored macOS login password, wait for the desktop to settle (skipping transitional blank frames), and return the screen.", "inputSchema": objectSchema(map[string]any{
|
||||
"vm": map[string]any{"type": "string", "description": "VM reference."},
|
||||
"timeout_ms": map[string]any{"type": "integer", "minimum": 1, "maximum": 60000, "description": "Max milliseconds to wait for the unlocked screen to settle (default 20000)."},
|
||||
|
||||
@@ -163,6 +163,29 @@ func TestReadResourceReportsUnavailableHost(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSuspendAndResumeUseLifecycleHostMethods(t *testing.T) {
|
||||
for tool, method := range map[string]string{"vm_suspend": "host/vm.suspend", "vm_resume": "host/vm.resume"} {
|
||||
t.Run(tool, func(t *testing.T) {
|
||||
server := New()
|
||||
host := &testHost{}
|
||||
server.BindHost(host)
|
||||
request := `{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"` + tool + `","arguments":{"vm":"driver:macos1"}}}`
|
||||
response := parseResponse(t, sendRequest(t, server, request))
|
||||
result, ok := response["result"].(map[string]any)
|
||||
if !ok || result["isError"] == true {
|
||||
t.Fatalf("tool response = %v", response)
|
||||
}
|
||||
if len(host.calls) != 1 || host.calls[0].method != method {
|
||||
t.Fatalf("host calls = %v, want %s", host.calls, method)
|
||||
}
|
||||
args, err := json.Marshal(host.calls[0].params)
|
||||
if err != nil || string(args) != `{"vm":"driver:macos1"}` {
|
||||
t.Fatalf("host arguments = %s, err = %v", args, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGuestToolsAreAdvertisedAndPublicKeyIsAvailable(t *testing.T) {
|
||||
server := New()
|
||||
server.guest = guest.NewSSH(t.TempDir())
|
||||
|
||||
Reference in new issue
Block a user