{"record":{"id":"75369ac6dafb877e","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-firestore-client-for-project-q-a","errorCode":null,"errorMessage":"failed to create Firestore client for project %q and database %q: %w","messagePattern":"failed to create Firestore client for project %q and database %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/sources/firestore/firestore.go","lineNumber":970,"sourceCode":"\tdatabase string,\n) (*firestore.Client, error) {\n\tctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)\n\tdefer span.End()\n\n\tuserAgent, err := util.UserAgentFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// If database is not specified, use the default database\n\tif database == \"\" {\n\t\tdatabase = \"(default)\"\n\t}\n\n\t// Create the Firestore client\n\tclient, err := firestore.NewClientWithDatabase(ctx, project, database, option.WithUserAgent(userAgent))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create Firestore client for project %q and database %q: %w\", project, database, err)\n\t}\n\n\treturn client, nil\n}\n\nfunc initFirebaseRulesConnection(\n\tctx context.Context,\n\tproject string,\n) (*firebaserules.Service, error) {\n\t// Create the Firebase Rules client\n\trulesClient, err := firebaserules.NewService(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create Firebase Rules client for project %q: %w\", project, err)\n\t}\n\n\treturn rulesClient, nil\n}\n","sourceCodeStart":952,"sourceCodeEnd":988,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/firestore/firestore.go#L952-L988","documentation":"This error is returned by initFirestoreConnection when firestore.NewClientWithDatabase fails to build a Firestore client for the configured project and database. It means the SDK could not establish the client — most often credential resolution failed (no Application Default Credentials), the project ID is invalid, or default scopes/quota project settings are wrong. No queries can run until this succeeds.","triggerScenarios":"firestore.NewClientWithDatabase(ctx, project, database, option.WithUserAgent(userAgent)) returns non-nil err during source Initialize: missing/invalid GOOGLE_APPLICATION_CREDENTIALS, malformed project ID, nonexistent database ID, or network failure reaching the metadata/token endpoints.","commonSituations":"Running locally without GOOGLE_APPLICATION_CREDENTIALS pointing at a service-account key; typos in the project or database id in the toolbox config (including a database other than '(default)' that was never created); workload identity/metadata server unreachable on GKE/Cloud Run; ADC找不到 valid quotas.","solutions":["Set GOOGLE_APPLICATION_CREDENTIALS to a valid service-account JSON key, or run `gcloud auth application-default login` locally","Verify the project ID and database ID in the source config exist in Google Cloud (database must be created in advance; '(default)' is used when omitted)","Ensure the Firestore Admin/API is enabled and the host can reach Google's OAuth/metadata endpoints"],"exampleFix":"// before\n# config uses project: \"my-prjoject\" (typo), no credentials in env\n// after\nexport GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa.json\n# project: \"my-project\", database: \"(default)\"","handlingStrategy":"validation","validationCode":"// run before initializing the source\nif os.Getenv(\"GOOGLE_APPLICATION_CREDENTIALS\") == \"\" {\n    if _, err := google.FindDefaultCredentials(ctx); err != nil {\n        log.Fatal(\"no Application Default Credentials available\")\n    }\n}\n// also verify project/database exist:\n// gcloud firestore databases describe --project=MY_PROJECT","typeGuard":null,"tryCatchPattern":"src, err := cfg.Initialize(ctx, tracer)\nif err != nil && strings.Contains(err.Error(), \"failed to create Firestore client\") {\n    log.Fatalf(\"Firestore init failed — check credentials/project/database: %v\", err)\n}","preventionTips":["Set GOOGLE_APPLICATION_CREDENTIALS or rely on workload identity in GCP runtimes","Verify project ID spelling and that the database ID exists (create non-default DBs first)","Enable the Cloud Firestore API on the project before startup"],"tags":["firestore","authentication","initialization","gcp"],"backgroundTag":"missing-credentials","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"}