{"record":{"id":"0dee83b8a8470b5f","repo":"googleapis/mcp-toolbox","slug":"get-schema-api-error-status-d-s","errorCode":null,"errorMessage":"get_schema API error (status %d): %s","messagePattern":"get_schema API error \\(status (.+?)\\): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/firestore/firestore.go","lineNumber":736,"sourceCode":"\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"User-Agent\", userAgent)\n\treq.Header.Set(\"x-goog-request-params\", fmt.Sprintf(\"project_id=%s&database_id=%s\", s.GetProjectId(), s.GetDatabaseId()))\n\treq.Header.Set(\"x-goog-firestore-api-requester\", \"querydata\")\n\n\tresp, err := httpClient.Do(req)\n\tif err != nil {\n\t\treturn CollectionSchema{}, err\n\t}\n\tdefer resp.Body.Close()\n\n\trespBody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn CollectionSchema{}, err\n\t}\n\n\tif resp.StatusCode < 200 || resp.StatusCode >= 300 {\n\t\treturn CollectionSchema{}, fmt.Errorf(\"get_schema API error (status %d): %s\", resp.StatusCode, string(respBody))\n\t}\n\n\tvar rawResult any\n\tif err := json.Unmarshal(respBody, &rawResult); err != nil {\n\t\treturn CollectionSchema{}, err\n\t}\n\n\tfields := parseFieldsFromPipelineResponse(rawResult)\n\treturn CollectionSchema{\n\t\tCollection: collection,\n\t\tFields:     fields,\n\t}, nil\n}\n\nfunc parseFieldsFromPipelineResponse(raw any) []FieldSchema {\n\tvar fields []FieldSchema\n\tswitch data := raw.(type) {\n\tcase []any:","sourceCodeStart":718,"sourceCodeEnd":754,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/firestore/firestore.go#L718-L754","documentation":"After POSTing the get_schema pipeline request to the Firestore executePipeline REST endpoint, getSchemaFromPipeline checks the HTTP status code. Any non-2xx response causes this error, embedding the status code and the raw response body so the server-side reason (auth failure, bad request, unsupported stage) is visible.","triggerScenarios":"The Firestore executePipeline API returns 4xx/5xx: invalid or missing OAuth token (401/403), malformed structuredPipeline payload (400), get_schema stage not enabled for the database (400/501), project/database not found (404), or server errors (5xx).","commonSituations":"Running against a Firestore database (especially Firestore in Native mode on older versions or emulator) that doesn't support pipeline get_schema stages; wrong project ID or database ID in the source config; expired/insufficient credentials; regional restrictions.","solutions":["Read the response body in the error message — it contains Google's API error reason (e.g. 'get_schema stage is not supported').","Verify project ID and database ID in the source config match an existing Firestore database.","Confirm the credential has datastore access; re-authenticate with gcloud auth application-default login.","If the API/stage is unsupported, fall back to document sampling (GetSchema's fallback path) or upgrade the Firestore database/runtime."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check the API endpoint reachability and auth token before schema discovery\n_, err := google.DefaultClient(ctx, \"https://www.googleapis.com/auth/datastore\")\nif err != nil {\n    return fmt.Errorf(\"ADC not available, get_schema call would 401/403: %w\", err)\n}","typeGuard":"func isGetSchemaHTTPError(err error) (statusCode int, body string, ok bool) {\n    if err == nil || !strings.Contains(err.Error(), \"get_schema API error\") {\n        return 0, \"\", false\n    }\n    var n int\n    if _, scanErr := fmt.Sscanf(err.Error(), \"get_schema API error (status %d):\", &n); scanErr != nil {\n        return 0, err.Error(), true\n    }\n    return n, err.Error(), true\n}","tryCatchPattern":"schema, err := getSchemaFromPipeline(ctx, coll)\nif err != nil {\n    var gsErr statusCodeError\n    if errors.As(err, &gsErr) {\n        switch {\n        case gsErr.code == 401 || gsErr.code == 403:\n            // refresh credentials / fix IAM and retry\n        case gsErr.code == 400 || gsErr.code == 501:\n            // get_schema stage unsupported: fall back to document sampling\n        case gsErr.code >= 500:\n            // retry with exponential backoff\n        }\n    }\n    return err\n}","preventionTips":["Confirm the target Firestore database supports pipeline get_schema stages before relying on it.","Validate project ID and database ID in config against gcloud firestore databases list.","Keep credentials fresh; use short-lived ADC in long-running processes with token refresh.","Always surface the response body — Google's error message names the exact problem."],"tags":["firestore","http","api-error","schema-discovery","rest"],"backgroundTag":"http-api-error-response","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}