googleapis/mcp-toolbox · error

invalid API version prefix: %q

Error message

invalid API version prefix: %q

What it means

The first path segment of a FHIR page URL must be a valid Google Healthcare API version, checked by isValidAPIVersion (starts with 'v' followed by digits, e.g. v1, v1beta1). This error means the URL does not begin with a recognized version segment, so the library cannot trust the URL shape and rejects it.

Source

Thrown at internal/sources/cloudhealthcare/cloud_healthcare.go:355

		host = h
	}
	if _, ok := allowedFHIRHosts[host]; !ok {
		return "", fmt.Errorf("URL host must be an allowed FHIR host, got %q", host)
	}

	// Clean and split path
	cleanPath := path.Clean(parsed.Path)
	// Truncate leading and trailing slashes for easier splitting
	trimmed := strings.Trim(cleanPath, "/")
	parts := strings.Split(trimmed, "/")

	// Page URL format Reference: https://docs.cloud.google.com/healthcare-api/docs/how-tos/fhir-search#using_the_search_method_with_get
	if len(parts) < 10 {
		return "", fmt.Errorf("invalid FHIR URL path structure: path too short")
	}

	if !isValidAPIVersion(parts[0]) {
		return "", fmt.Errorf("invalid API version prefix: %q", parts[0])
	}

	if parts[1] != "projects" {
		return "", fmt.Errorf("invalid path: expected 'projects', got %q", parts[1])
	}
	if parts[2] != s.Project() {
		return "", fmt.Errorf("invalid project %q: must match source project %q", parts[2], s.Project())
	}
	if parts[3] != "locations" {
		return "", fmt.Errorf("invalid path: expected 'locations', got %q", parts[3])
	}
	if parts[4] != s.Region() {
		return "", fmt.Errorf("invalid location/region %q: must match source region %q", parts[4], s.Region())
	}
	if parts[5] != "datasets" {
		return "", fmt.Errorf("invalid path: expected 'datasets', got %q", parts[5])
	}
	if parts[6] != s.DatasetID() {

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Ensure the page URL starts with the API version segment, e.g. https://healthcare.googleapis.com/v1/projects/...
  2. Use only v1 (GA) or v1beta1 paths as documented for the FHIR store
  3. Copy links.next verbatim rather than rebuilding the URL
  4. Check the FHIR store's configured version; beta stores use /v1beta1/ paths

Example fix

// before (missing version)
page := "https://healthcare.googleapis.com/projects/p/locations/l/datasets/d/fhirStores/f/fhir/Patient?pageToken=x"
// after
page := "https://healthcare.googleapis.com/v1/projects/p/locations/l/datasets/d/fhirStores/f/fhir/Patient?pageToken=x"
Defensive patterns

Strategy: validation

Validate before calling

function hasAPIVersion(u) { const first = new URL(u).pathname.split('/').filter(Boolean)[0]; return /^v\d+([a-z]+\d*)?$/.test(first); }

Prevention

When it happens

Trigger: A page URL whose first path segment is something like "healthcare", "fhir", a full domain repeated, or "v" with no numeric version (isValidAPIVersion requires len>=2 and v[0]=='v' followed by digits) is passed to FHIRFetchPage.

Common situations: Passing a generic https://healthcare.googleapis.com/fhir/... URL that skips the version; a proxy-prepended path segment; hand-built URLs that omit /v1/.

Related errors


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