googleapis/mcp-toolbox · error

VM %q not found in project %q

Error message

VM %q not found in project %q

What it means

FindVM in internal/util/cloudsqlconnect/gce.go pages through the GCE AggregatedList API looking for a Compute Engine VM by name within a project. When paging finishes and no instance with the requested name was found, it returns this error. It is a user-input/result mismatch, not an API failure — the search itself succeeded but returned zero matches.

Source

Thrown at internal/util/cloudsqlconnect/gce.go:188

				if instance.Name != vmName {
					continue
				}
				foundInstances = append(foundInstances, instance)
				foundZones = append(foundZones, ExtractNetworkName(zone))
				if len(foundInstances) > 1 {
					return stopPaging
				}
			}
		}
		return nil
	})
	if err != nil && err != stopPaging {
		return nil, "", fmt.Errorf("failed to search for VM: %w", err)
	}

	switch len(foundInstances) {
	case 0:
		return nil, "", fmt.Errorf("VM %q not found in project %q", vmName, project)
	case 1:
		return foundInstances[0], foundZones[0], nil
	default:
		return nil, "", fmt.Errorf("multiple VMs named %q found in zones: %v - please specify vm_zone parameter", vmName, foundZones)
	}
}

// stringErr signals early termination from Pages without conflating with
// real API errors. Unexported: only FindVM's Pages callback uses it.
type stringErr string

func (e stringErr) Error() string { return string(e) }

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify the VM name with `gcloud compute instances list --project=<project>` and correct the vm_name parameter
  2. Confirm the project parameter matches the project that actually contains the VM
  3. If the VM was deleted, recreate it or point the tool at an existing instance

Example fix

// before
FindVM(ctx, "my-Prod-VM", "my-project", "")
// after
FindVM(ctx, "my-prod-vm", "my-project", "") // GCE names are lowercase; verify with gcloud compute instances list
Defensive patterns

Strategy: validation

Validate before calling

vmName := params["vm_name"]
if vmName == "" || !regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`).MatchString(vmName) {
    return fmt.Errorf("vm_name %q is not a valid GCE instance name", vmName)
}

Type guard

func isValidGCEName(name string) bool {
    return regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`).MatchString(name)
}

Try / catch

inst, zone, err := FindVM(ctx, vmName, project, zoneParam)
if err != nil {
    if strings.Contains(err.Error(), "not found in project") {
        // surface a helpful hint: list matching instances
        return fmt.Errorf("VM %q not found; run 'gcloud compute instances list --filter=name=%s' to see available names", vmName, vmName)
    }
    return err
}

Prevention

When it happens

Trigger: Calling FindVM (via a tool's Invoke) with a vm_name that does not exist in the given GCP project, a typo'd VM name, a name from a different project, or a deleted VM.

Common situations: Developer pasted an instance name from another project or environment (staging vs prod); the VM was decommissioned; the name was copied with extra whitespace or wrong casing (GCE names are lowercase).

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/2437c07365fe8198. Report an issue: GitHub.