{"record":{"id":"bc5beb718c63eab4","repo":"lima-vm/lima","slug":"expected-status-of-instance-q-to-be-q-got-q","errorCode":null,"errorMessage":"expected status of instance %#q to be %#q, got %#q","messagePattern":"expected status of instance %#q to be %#q, got %#q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/mcp/toolset/toolset.go","lineNumber":72,"sourceCode":"\tr, err := cmd.StdoutPipe()\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\tif err = cmd.Start(); err != nil {\n\t\treturn nil, nil, err\n\t}\n\tclient, err := sftp.NewClientPipe(r, w)\n\tif err != nil {\n\t\tif cmd != nil && cmd.Process != nil {\n\t\t\t_ = cmd.Process.Kill()\n\t\t}\n\t}\n\treturn client, cmd, err\n}\n\nfunc (ts *ToolSet) RegisterInstance(ctx context.Context, inst *limatype.Instance) error {\n\tif inst.Status != limatype.StatusRunning {\n\t\treturn fmt.Errorf(\"expected status of instance %#q to be %#q, got %#q\",\n\t\t\tinst.Name, limatype.StatusRunning, inst.Status)\n\t}\n\tif len(inst.Config.Mounts) == 0 {\n\t\tlogrus.Warnf(\"instance %#q has no mount\", inst.Name)\n\t}\n\tts.inst = inst\n\tvar err error\n\tts.sftp, ts.sftpCmd, err = newSFTPClient(ctx, inst)\n\treturn err\n}\n\nfunc (ts *ToolSet) RegisterServer(server *mcp.Server) error {\n\tmcp.AddTool(server, msi.ListDirectory, ts.ListDirectory)\n\tmcp.AddTool(server, msi.ReadFile, ts.ReadFile)\n\tmcp.AddTool(server, msi.WriteFile, ts.WriteFile)\n\tmcp.AddTool(server, msi.Glob, ts.Glob)\n\tmcp.AddTool(server, msi.SearchFileContent, ts.SearchFileContent)\n\tmcp.AddTool(server, msi.RunShellCommand, ts.RunShellCommand)","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/mcp/toolset/toolset.go#L54-L90","documentation":"ToolSet.RegisterInstance only accepts instances whose Status is limatype.StatusRunning (validate at toolset.go:71-74). The MCP toolset needs a live VM to establish its SFTP client (newSFTPClient is called right after), so registering a stopped/exited/broken instance fails with this formatted error naming the expected and actual status.","triggerScenarios":"Calling RegisterInstance (from limactl mcp server startup or embedded code) with an *limatype.Instance whose Status is anything other than Running — e.g. \"Stopped\", \"Exited\", \"Broken\", or an instance that was never started.","commonSituations":"Running `limactl mcp myinstance` when the instance is stopped; scripting MCP setup right after `limactl create` without `limactl start`; the VM crashed so status dropped from Running; stale instance name typo hitting an unstarted instance.","solutions":["Start the instance first: limactl start <instance>, then retry registration.","Verify status with `limactl list` and pick an instance showing Running.","If the instance is Broken, inspect `limactl start --debug <instance>` logs to fix the underlying VM problem before using MCP tools."],"exampleFix":"// before\ninst, _ := store.Inspect(ctx, \"myvm\")\nts.RegisterInstance(ctx, inst) // fails if not Running\n// after\ninst, _ := store.Inspect(ctx, \"myvm\")\nif inst.Status != limatype.StatusRunning {\n    if err := instance.Start(ctx, stdout, stderr, instName, nil, ...); err != nil { return err }\n    inst, _ = store.Inspect(ctx, instName)\n}\nreturn ts.RegisterInstance(ctx, inst)","handlingStrategy":"validation","validationCode":"inst, err := store.Inspect(ctx, instName)\nif err != nil { return err }\nif inst.Status != limatype.StatusRunning {\n    return fmt.Errorf(\"start instance %q first (status: %s)\", instName, inst.Status)\n}\nif err := ts.RegisterInstance(ctx, inst); err != nil { return err }","typeGuard":"func registerable(inst *limatype.Instance) bool { return inst != nil && inst.Status == limatype.StatusRunning }","tryCatchPattern":"if err := ts.RegisterInstance(ctx, inst); err != nil {\n    if strings.Contains(err.Error(), \"expected status\") {\n        return fmt.Errorf(\"instance %s is %s; run limactl start %s\", inst.Name, inst.Status, inst.Name)\n    }\n    return err\n}","preventionTips":["Check `limactl list` for Running status before limactl mcp.","Automate start-then-register instead of assuming the VM is up.","Re-inspect the instance (store.Inspect) to refresh Status — don't cache stale values.","Treat Broken status as a VM failure to debug, not an MCP problem."],"tags":["lima","mcp","instance-lifecycle","status-check"],"backgroundTag":"instance-not-running","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}