googleapis/mcp-toolbox · error

invalid FHIR URL path structure: path too short

Error message

invalid FHIR URL path structure: path too short

What it means

After host checks, the URL path is cleaned and split; a genuine Healthcare API FHIR page URL must have at least 10 slash-separated segments (version, projects, project, locations, location, datasets, dataset, fhirStores, store, fhir/...). This error means the path is structurally too short to be a valid FHIR resource page URL, so the library refuses to follow it.

Source

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

	parsed.Host = strings.ToLower(parsed.Host)
	host := parsed.Host
	if h, _, err := net.SplitHostPort(host); err == nil {
		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())
	}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Copy the full links.next URL from the previous FHIR response verbatim, including query string
  2. Confirm the URL targets a FHIR store path .../datasets/<ds>/fhirStores/<store>/fhir/<Resource> with a pageToken/pageOffset query
  3. Do not truncate the URL at '&'; keep all query parameters
  4. If paginating manually, build the URL with the full 10-segment path

Example fix

// before (too short)
page := "https://healthcare.googleapis.com/v1/projects/p/locations/l/datasets/d/fhirStores/f"
// after (full page URL from links.next)
page := "https://healthcare.googleapis.com/v1/projects/p/locations/l/datasets/d/fhirStores/f/fhir/Patient?pageToken=CAs"
Defensive patterns

Strategy: validation

Validate before calling

function looksLikeFHIRPageURL(u) {
  const parts = new URL(u).pathname.split('/').filter(Boolean);
  return parts.length >= 10 && parts[1] === 'projects' && parts[3] === 'locations' && parts[5] === 'datasets' && parts[7] === 'fhirStores';
}

Prevention

When it happens

Trigger: A short URL like https://healthcare.googleapis.com/v1/projects/p/locations/l/datasets/d/fhirStores/f or a bare search endpoint without the resource segment is passed as a page URL to FHIRFetchPage.

Common situations: An LLM reconstructing the next-page URL from memory instead of copying links.next; confusing a FHIR store's base URL with a page URL; passing a non-FHIR (DICOM/HL7v2) store URL into the FHIR pagination path.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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