### Install Dependencies Source: https://github.com/firebase/firebase-tools/blob/main/firebase-vscode/CONTRIBUTING.md Run npm install in the parent and current directories to set up project dependencies. ```sh cd .. npm i cd firebase-vscode npm i ``` -------------------------------- ### Complete Firebase Workflow Example Source: https://github.com/firebase/firebase-tools/blob/main/prompts/FIREBASE.md This example demonstrates a typical workflow from cloning a project to deploying to production, including initialization, local development, and staged deployments. ```bash git clone https://github.com/example/my-app cd my-app firebase init firebase emulators:start firebase use staging firebase deploy firebase use production firebase deploy --only hosting,firestore ``` -------------------------------- ### Start Firebase Emulators Source: https://github.com/firebase/firebase-tools/blob/main/prompts/FIREBASE.md Start local emulators for Firebase services. You can start all emulators or specify which ones to run. ```bash firebase emulators:start firebase emulators:start --only functions,firestore ``` -------------------------------- ### Install Firebase CLI using npm Source: https://github.com/firebase/firebase-tools/blob/main/README.md Installs the Firebase CLI globally using npm. Requires Node.js and npm to be installed. ```bash npm install -g firebase-tools ``` -------------------------------- ### Start Firebase Emulators for Local Development Source: https://github.com/firebase/firebase-tools/blob/main/prompts/FIREBASE_FUNCTIONS.md Start the Firebase emulator suite, specifically targeting the Functions emulator for local development. ```bash firebase emulators:start --only functions ``` -------------------------------- ### Install Firebase CLI using standalone binary Source: https://github.com/firebase/firebase-tools/blob/main/README.md Downloads and installs the Firebase CLI as a standalone binary without external dependencies. ```bash curl -sL firebase.tools | bash ``` -------------------------------- ### Run Development Server Source: https://github.com/firebase/firebase-tools/blob/main/scripts/agent-evals/templates/next-app-hello-world/README.md Use these commands to start the Next.js development server. Open http://localhost:3000 in your browser to view the application. ```bash npm run dev # or yarn dev # or pnpm dev # or bun dev ``` -------------------------------- ### Start Firebase Emulators Source: https://github.com/firebase/firebase-tools/blob/main/README.md Use `emulators:start` to launch the Cloud Functions emulator and other Firebase emulators. Emulated functions run in separate node processes with their own credential discovery. ```bash firebase emulators:start ``` -------------------------------- ### Build the update-single-file Script Source: https://github.com/firebase/firebase-tools/blob/main/scripts/examples/hosting/update-single-file/README.md Clone the repository, navigate to the script's directory, and install dependencies to build the tool. ```bash cd firebase-tools/scripts/examples/hosting/update-single-file/ npm install npm run build npm link ``` -------------------------------- ### MCP Inspector Configuration Example Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/CONTRIBUTING.md Example configuration for the MCP inspector, specifying the transport type and command arguments. ```text Transport Type: STDIO Command: firebase Arguments: mcp ``` -------------------------------- ### Firebase Functions Deferred Initialization Source: https://github.com/firebase/firebase-tools/blob/main/prompts/FIREBASE_FUNCTIONS.md Implement deferred initialization for expensive client SDKs to improve cold start times. The `onInit` hook allows you to load and initialize resources asynchronously before the first function execution. This example initializes a `HeavySDK` client and then uses it in an HTTPS function. ```typescript import {onInit} from 'firebase-functions'; import {onRequest} from 'firebase-functions/https'; let heavyClient: HeavySDK; onInit(async () => { const {HeavySDK} = await import('./lib/heavy-sdk'); heavyClient = new HeavySDK({ // Expensive initialization... }); }); export const useHeavyClient = onRequest(async (req, res) => { const result = await heavyClient.process(req.body); res.json(result); }); ``` -------------------------------- ### Install Firebase Extension for Gemini CLI Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/README.md Installs the Firebase extension for the Gemini CLI. Ensure you have the Gemini CLI installed. ```bash gemini extensions install https://github.com/firebase/agent-skills ``` -------------------------------- ### Install Local Extension Source: https://github.com/firebase/firebase-tools/blob/main/templates/extensions/javascript/WELCOME.md Install your local extension into a Firebase project. Ensure you provide the correct path to your extension directory and your project ID. ```bash firebase ext:install ./path/to/extension/directory --project= ``` -------------------------------- ### Write a New Agent Evaluation Test Source: https://github.com/firebase/firebase-tools/blob/main/scripts/agent-evals/README.md Example of a new test file structure using mocha and AgentTestRunner. Includes setup, test case definition, and interaction simulation with assertions. ```typescript import { startAgentTest } from "../runner/index.js"; import { AgentTestRunner } from "../runner/index.js"; // Ensure you import hooks which instruments an afterEach block that cleans up // the agent and the pseudo terminal. import "../helpers/hooks.js"; describe("", function (this: Mocha.Suite) { // Recommend setting retries > 0 because LLMs are nondeterministic this.retries(2); it("", async function (this: Mocha.Context) { // Start the AgentTestRunner, which will start up the coding agent in a // pseudo-terminal, and wait for it to load the Firebase MCP server, and // start accepting keystrokes const run: AgentTestRunner = await startAgentTest(this, { // Name of the template to run in. You can find the list of templates in // src/template/index.ts (these will auto-complete) templateName: "next-app-hello-world", // List of tool mocks to apply for this test. You can find the list of // available mocks in src/mock/tool-mocks.ts (these will auto-complete). // See the instructions below on how to add your own mocks toolMocks: ["nextJsWithProjectMock"], }); // Simulate typing in the terminal. This will await until the "turn" is over // so any assertions on what happened will happen on the current "turn" await run.type("/firebase:init"); // Assert that the agent outputted "Backend Services" await run.expectText("Backend Services"); await run.type("Use Firebase Project `project-id-1000`"); // Assert that a tool was called with the given arguments, and that it was // successful await run.expectToolCalls([ "firebase_update_environment", argumentContains: "project-id-1000", isSuccess: true, ]); // Important: Expectations apply to the last "turn". Each time you type, it // creates a new turn. This ensures you are only asserting against the most // recent actions of the agent await run.type("Hello world"); // This will fail, because "Hello World" doesn't trigger a tool call await run.expectToolCalls([ "firebase_update_environment", argumentContains: "project-id-1000", isSuccess: true, ]); }); }); ``` -------------------------------- ### Start Firebase Emulators Source: https://github.com/firebase/firebase-tools/blob/main/templates/extensions/javascript/WELCOME.md Run the Firebase Emulator suite to test your extension locally. Replace `` with your Firebase project ID or use 'demo-test' for a fake project. ```bash firebase emulators:start --project= ``` -------------------------------- ### Install Dependencies for Trigger Tests Source: https://github.com/firebase/firebase-tools/blob/main/scripts/triggers-end-to-end-tests/README.md Installs npm dependencies required for running the end-to-end trigger tests. Run this command from the firebase-tools directory. ```bash $ (cd scripts/triggers-end-to-end-tests && npm install) ``` -------------------------------- ### Basic GraphQL Schema for Users and Posts Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt This example shows a basic schema for a GraphQL database with 'users' and 'posts' tables, including a reference from 'posts' to 'users'. ```graphql type User @table { name: String! } type Post @table { body: String! author: User } ``` -------------------------------- ### Verify Claude Plugin Installation Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/README.md Verifies that the Firebase plugin has been successfully installed in Claude Code. ```bash claude plugin ``` -------------------------------- ### Deploy Extension Source: https://github.com/firebase/firebase-tools/blob/main/templates/extensions/javascript/WELCOME.md Deploy your extension to a real Firebase project after installation. This command pushes your extension configuration and code. ```bash firebase deploy --only extensions ``` -------------------------------- ### Example package.json for Express.js build scripts Source: https://github.com/firebase/firebase-tools/blob/main/src/frameworks/docs/express.md Define build, static content copy, and prerender scripts in your package.json. The Firebase CLI executes the 'build' script. ```json { "name": "express-app", "version": "0.0.0", "scripts": { "build": "spack", "static": "cp static/* dist", "prerender": "ts-node prerender.ts" }, … } ``` -------------------------------- ### Basic Query Structure Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt A fundamental example of a Firebase Data Connect GraphQL query, demonstrating the basic syntax for querying data with an @auth directive. ```APIDOC ## Basic Query Example ### Description This example shows the basic structure of a GraphQL query in Firebase Data Connect, including the `query` keyword, a query name, and the `@auth` directive. ### Method GraphQL Query ### Endpoint N/A (GraphQL endpoint) ### Parameters N/A (Parameters are defined within the query itself) ### Request Example ```graphql query someQueryName @auth(level: USER) { typenameplural(where: {fieldName: { eq: "somevalue"}}) { nestedType { fieldName } } } ``` ### Response N/A (Response structure depends on the query and schema. ``` -------------------------------- ### Scriptable Command Example Source: https://github.com/firebase/firebase-tools/blob/main/CONTRIBUTING.md Demonstrates how to use the Firebase CLI as a Node module for scriptability. Ensure your command's action returns a useful value, such as an array of objects for list commands. ```typescript import * as cli from "firebase-tools"; cli.projects.list(); cli.functions.log(); ``` -------------------------------- ### String Comparison Queries Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt Provides examples of using various string comparison operators like `startsWith`, `endsWith`, `in`, `contains`, and `pattern` for filtering data. ```APIDOC ## String Comparison Queries ### Description This example demonstrates various ways to filter string fields using operators such as `startsWith`, `endsWith`, `in` (for lists), `contains`, and `pattern` (for regex matching). ### Method GraphQL Query ### Endpoint N/A (GraphQL endpoint) ### Parameters N/A (Parameters are defined within the query itself) ### Request Example ```graphql query comparisonQueries @auth(level: USER) { prefixed: typenameplural(where: {title: {startsWith: %prefix%}}) {...} suffixed: typenameplural(where: {title: {endsWith: %suffix%}}) {...} contained: typenameplural(where: {title: {in: %listOfTitles%}}) {...} contained: typenameplural(where: {title: {contains: %oneTitle%}}) {...} matchRegex: typenameplural(where: {title: {pattern: {regex: %regex%}}}) {...} } ``` ### Response N/A (Response structure depends on the query and schema. ``` -------------------------------- ### Install Claude Plugin for Firebase Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/README.md Installs the official Firebase plugin for Claude Code. This allows Claude Code to interact with the Firebase MCP server. ```bash claude plugin install firebase@firebase ``` -------------------------------- ### Run MCP Inspector Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/CONTRIBUTING.md Start the MCP inspector to test tools locally without using tokens. This provides a UI for configuring and executing tools. ```bash npx -y @modelcontextprotocol/inspector ``` -------------------------------- ### Public Access Query Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt An example of a query that is accessible to anyone, using the `@auth(level: PUBLIC)` directive. ```APIDOC ## Public Access Query ### Description This example shows a query that is accessible to all users, regardless of authentication status, by using the `@auth(level: PUBLIC)` directive. ### Method GraphQL Query ### Endpoint N/A (GraphQL endpoint) ### Parameters N/A (Parameters are defined within the query itself) ### Request Example ```graphql query ListProducts @auth(level: PUBLIC) { # ... query fields } ``` ### Response N/A (Response structure depends on the query and schema. ``` -------------------------------- ### Example: Update a Specific HTML File Source: https://github.com/firebase/firebase-tools/blob/main/scripts/examples/hosting/update-single-file/README.md Demonstrates how to update a single HTML file, `/team/about.html`, on your Firebase Hosting site by providing the file path relative to the public directory. ```bash cd my-app/public/ update-single-file --project my-app team/about.html ``` -------------------------------- ### Implement an Operation Handler in TypeScript Source: https://github.com/firebase/firebase-tools/blob/main/src/emulator/auth/README.md Example of an operation handler function for the 'signUp' operation. It includes type-hinting for request body and response based on API schemas. ```typescript function signUp( state: ProjectState, reqBody: Schemas["GoogleCloudIdentitytoolkitV1SignUpRequest"], ctx: ExegesisContext, ): Schemas["GoogleCloudIdentitytoolkitV1SignUpResponse"] { return { /* response JSON body */ }; } ``` -------------------------------- ### Firebase Functions Environment Configuration with Params Source: https://github.com/firebase/firebase-tools/blob/main/prompts/FIREBASE_FUNCTIONS.md Define and use environment parameters, including strings, integers, and secrets, for runtime configuration. This example shows how to access built-in parameters like `projectID` and define custom parameters with default values, as well as using secrets. It also demonstrates setting function instance limits based on an environment parameter. ```typescript import {defineString, defineInt, defineSecret} from 'firebase-functions/params'; import * as params from 'firebase-functions/params'; import {onRequest} from 'firebase-functions/https'; import {logger} from 'firebase-functions'; // Built-in params available automatically const projectId = params.projectID; const databaseUrl = params.databaseURL; const bucket = params.storageBucket; const gcpProject = params.gcloudProject; // Custom params const apiUrl = defineString('API_URL', { default: 'https://api.example.com' }); const environment = defineString('ENVIRONMENT', { default: 'dev' }); const apiKey = defineSecret('STRIPE_KEY'); // Using params directly in runtime configuration export const processPayment = onRequest({ secrets: [apiKey], memory: defineString('PAYMENT_MEMORY', { default: '1GiB' }), minInstances: environment.equals('production').thenElse(5, 0), maxInstances: environment.equals('production').thenElse(1000, 10) }, async (req, res) => { logger.info('Processing payment', { project: projectId.value(), bucket: bucket.value(), env: environment.value() }); const key = apiKey.value(); const url = apiUrl.value(); // Process payment... }); ``` -------------------------------- ### Enable TTL Policy while Keeping Default Indexing Source: https://github.com/firebase/firebase-tools/blob/main/src/firestore/README.md Example of enabling a TTL policy on a field while retaining its default indexing configuration. The 'indexes' array specifies the desired indexing modes. ```json { "fieldOverrides": [ { "collectionGroup": "yourCollectionGroup", "fieldPath": "yourFieldPath", "ttl": true, "indexes": [ { "order": "ASCENDING", "queryScope": "COLLECTION_GROUP" }, { "order": "DESCENDING", "queryScope": "COLLECTION_GROUP" }, { "arrayConfig": "CONTAINS", "queryScope": "COLLECTION_GROUP" } ] } ] } ``` -------------------------------- ### Initialize a new Firebase project Source: https://github.com/firebase/firebase-tools/blob/main/README.md Sets up a new Firebase project in the current directory and creates a `firebase.json` configuration file. ```bash firebase init ``` -------------------------------- ### Build and Link Project Source: https://github.com/firebase/firebase-tools/blob/main/GEMINI.md Commands to build the project and link it locally for testing changes. ```bash # Build the project npm run build # Link the package - once this is run, you can manually test changes in your terminal npm link ``` -------------------------------- ### Configure package.json for dynamic content deployment Source: https://github.com/firebase/firebase-tools/blob/main/src/frameworks/docs/express.md Ensure the 'files' directive includes all necessary server files and set the 'main' entry point correctly in package.json for dynamic content serving. ```json { "name": "express-app", "version": "0.0.0", "scripts": { "build": "spack && npm run static && npm run prerender", "static": "cp static/* dist", "prerender": "ts-node tools/prerender.ts" }, "directories": { "serve": "dist" }, "files": ["dist", "server.js"], "main": "server.js", ... } ``` -------------------------------- ### Run Tests and Linting Source: https://github.com/firebase/firebase-tools/blob/main/GEMINI.md Commands for running the full test suite, quick unit tests, and linting. ```bash npm test # Full test suite with linting and compilation npm run mocha:fast # Quick unit tests only npx mocha {testfile} # Quick unit test for a specific file # Linting and formatting npm run lint # Check all code npm run lint:changed-files # Lint changed files only (much faster) npm run format # Auto-fix formatting issues ``` -------------------------------- ### Initialize Nuxt Project Source: https://github.com/firebase/firebase-tools/blob/main/src/frameworks/docs/nuxt.md Create a new Nuxt 3+ project using npx. This is a prerequisite for deploying to Firebase. ```shell npx nuxi@latest init ``` -------------------------------- ### Set up Application Default Credentials Source: https://github.com/firebase/firebase-tools/blob/main/scripts/examples/hosting/update-single-file/README.md Configure your environment to use application default credentials for authentication with Google Cloud services. This is optional if running within a GCP environment. ```bash # Set up application default credentials using gcloud (optional if in GCP environment). gcloud auth application-default login # It may be required to set a quota project for the credentials - used to account for the API usage. gcloud auth application-default set-quota-project ``` -------------------------------- ### crashlytics_batch_get_events Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/antigravity/README.md Gets specific events by resource name for a Crashlytics issue. ```APIDOC ## crashlytics_batch_get_events ### Description Gets specific events by resource name. Can be used to fetch sample crashes and exceptions for an issue, which will include stack traces and other data useful for debugging. ### Method POST ### Endpoint /v1/projects/{projectId}/issues/{issueId}/events:batchGet ### Parameters #### Path Parameters - **projectId** (string) - Required - The Firebase project ID. - **issueId** (string) - Required - The ID of the Crashlytics issue. #### Request Body - **eventNames** (array) - Required - A list of event resource names to retrieve. ### Request Example ```json { "eventNames": [ "projects/12345/issues/a1b2c3d4/events/e1", "projects/12345/issues/a1b2c3d4/events/e2" ] } ``` ### Response #### Success Response (200) - **events** (array) - A list of Crashlytics events. ### Response Example ```json { "events": [ { "name": "projects/12345/issues/a1b2c3d4/events/e1", "timestamp": "2023-01-01T11:50:00Z", "type": "crash", "appInfo": { "packageName": "com.example.App", "version": "1.0.0" }, "stackTrace": { "threads": [ { "name": "main", "stackFrames": [ { "className": "com.example.App.MainActivity", "methodName": "onCreate", "lineNumber": 50, "file": "MainActivity.java" } ] } ] } } ] } ``` ``` -------------------------------- ### Display Firebase CLI help Source: https://github.com/firebase/firebase-tools/blob/main/README.md Shows a list of available commands for the Firebase CLI. Use ` --help` for specific command details. ```bash firebase --help ``` -------------------------------- ### Add New Template to Index Source: https://github.com/firebase/firebase-tools/blob/main/scripts/agent-evals/README.md Example of how to add a new template name to the `templates` constant in `scripts/agent-evals/src/template/index.ts`. ```typescript export const templates = [ { name: "", platform: TemplatePlatform.NODE, }, ... ] as const; ``` -------------------------------- ### Run Unit Tests Source: https://github.com/firebase/firebase-tools/blob/main/firebase-vscode/CONTRIBUTING.md Execute unit tests using the command npm run test:unit. ```sh npm run test:unit ``` -------------------------------- ### Secure Row Operations Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt Examples of securely querying, inserting, updating, and deleting rows using Data Connect. ```APIDOC ## Secure Row Operations ### Description Demonstrates how to perform secure CRUD operations on tables configured with Data Connect. ### Examples - **Query**: `query { user(key: {uid_expr: "auth.uid"}) { name } }` - **Insert**: `mutation { user_insert(data: {uid_expr: "auth.uid" name: "Fred"}) }` - **Update**: `mutation { user_update(key: {uid_expr: "auth.uid"}, data: {name: "New Name"}) }` - **Delete**: `mutation { user_delete(key: {uid_expr: "auth.uid"}) }` ``` -------------------------------- ### Data Connect CRUD Operations Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt Examples of GraphQL queries and mutations for performing CRUD operations on the generated table. ```graphql * You can lookup a row: `query ($id: UUID!) { tableName(id: $id) { myField } } ` * You can find rows using: `query tableNames(limit: 20) { myField }` * You can insert a row: `mutation { tableName_insert(data: {myField: "foo"}) }` * You can update a row: `mutation ($id: UUID!) { tableName_update(id: $id, data: {myField: "bar"}) }` * You can delete a row: `mutation ($id: UUID!) { tableName_delete(id: $id) }` ``` -------------------------------- ### User-Only Access Query Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt An example of a query that requires the user to be signed in, using the `@auth(level: USER)` directive. ```APIDOC ## User-Only Access Query ### Description This example shows a query that is only accessible to signed-in users, enforced by the `@auth(level: USER)` directive. ### Method GraphQL Query ### Endpoint N/A (GraphQL endpoint) ### Parameters N/A (Parameters are defined within the query itself) ### Request Example ```graphql query GetCart @auth(level: USER) { # ... query fields } ``` ### Response N/A (Response structure depends on the query and schema. ``` -------------------------------- ### Initialize and Use Firebase SDK Source: https://github.com/firebase/firebase-tools/blob/main/templates/init/hosting/index.html This code snippet demonstrates how to initialize the Firebase SDK and check which features are available. It runs after the DOM is loaded and logs the available features or an error to the console. ```javascript document.addEventListener('DOMContentLoaded', function() { const loadEl = document.querySelector('#load'); // // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥 // // The Firebase SDK is initialized and available here! // // firebase.auth().onAuthStateChanged(user => { }); // // firebase.database().ref('/path/to/ref').on('value', snapshot => { }); // // firebase.firestore().doc('/foo/bar').get().then(() => { }); // // firebase.functions().httpsCallable('yourFunction')().then(() => { }); // // firebase.messaging().requestPermission().then(() => { }); // // firebase.storage().ref('/path/to/ref').getDownloadURL().then(() => { }); // // firebase.analytics(); // call to activate // // firebase.analytics().logEvent('tutorial_completed'); // // firebase.performance(); // call to activate // // // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥 try { let app = firebase.app(); let features = [ 'auth', 'database', 'firestore', 'functions', 'messaging', 'storage', 'analytics', 'remoteConfig', 'performance', ].filter(feature => typeof app[feature] === 'function'); loadEl.textContent = `Firebase SDK loaded with ${features.join(', ')}`; } catch (e) { console.error(e); loadEl.textContent = 'Error loading the Firebase SDK, check the console.'; } }); ``` -------------------------------- ### Initialize Firebase Features Source: https://github.com/firebase/firebase-tools/blob/main/prompts/FIREBASE.md Use these commands to initialize specific Firebase features within your project. Ensure you are in your project's root directory. ```bash firebase init hosting firebase init functions firebase init firestore ``` -------------------------------- ### GraphQL Schema for Vector Column Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt This example demonstrates how to define a Vector column for storing embeddings, using the @col directive with a specified size. ```graphql type Post @table { content: String! @col(name: "post_content") contentEmbedding: Vector! @col(size:768) } ``` -------------------------------- ### Combine multiple build steps in package.json scripts Source: https://github.com/firebase/firebase-tools/blob/main/src/frameworks/docs/express.md Use '&&' to chain multiple commands in your npm build script for comprehensive application building. Consider using tools like npm-run-all for complex sequences. ```json { "name": "express-app", "version": "0.0.0", "scripts": { "build": "spack && npm run static && npm run prerender", "static": "cp static/* dist", "prerender": "ts-node prerender.ts" }, … } ``` -------------------------------- ### Run Storage Emulator Integration Tests Source: https://github.com/firebase/firebase-tools/blob/main/src/emulator/storage/README.md Execute integration tests for the Firebase Storage emulator. Ensure you are in the project's root directory. ```bash npm run test:storage-emulator-integration ``` -------------------------------- ### Add Firebase Marketplace for Claude Plugins Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/README.md Adds the Firebase marketplace to Claude plugins. This is the first step to installing the Firebase plugin for Claude Code. ```bash claude plugin marketplace add firebase/firebase-tools ``` -------------------------------- ### Perform Development Build Source: https://github.com/firebase/firebase-tools/blob/main/CONTRIBUTING.md Run this command to create a development build of the codebase. This process compiles TypeScript to JavaScript. ```bash npm run build ``` -------------------------------- ### Many-to-Many Relationship Schema Example Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt Illustrates a many-to-many relationship between 'Crew' and 'Chore' using an intermediate 'Assignment' table. Array reference fields are not supported. ```graphql type Crew @table { name: String! # assignedChores: [Chore!]! # No supported. Do not use } type Chore @table { name: String! description: String! # assignedCrews: [Crews!]! # No supported. Do not use } type Assignment @table { crew: Crew! chore: Chore! } ``` -------------------------------- ### GraphQL Schema for Auto-Increment Primary Key Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt This example shows how to define a serial primary key for a 'Post' table using the @col directive with a 'serial' dataType. ```graphql type Post @table { id: Int! @col(name: "post_id", dataType: "serial") } ``` -------------------------------- ### Generate MCP Tool List README Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/CONTRIBUTING.md This command-line instruction generates an updated list of available MCP tools for the README.md file. Run this after adding new tools to ensure documentation is up-to-date. ```bash node lib/bin/firebase.js mcp --generate-tool-list ``` -------------------------------- ### List Firebase Projects with Token Source: https://github.com/firebase/firebase-tools/blob/main/README.md Use the --token flag to authenticate with a user token for commands like listing projects. This method is deprecated; prefer service accounts. ```bash firebase --token="" projects:list ``` -------------------------------- ### Run WebFrameworks Deploy Integration Test Source: https://github.com/firebase/firebase-tools/blob/main/scripts/webframeworks-deploy-tests/README.md Execute the integration test for web frameworks deployment. Ensure GCLOUD_PROJECT is set to your project ID. ```bash $ GCLOUD_PROJECT=${PROJECT_ID} npm run test:webframeworks-deploy ``` -------------------------------- ### crashlytics_batch_get_events Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/README.md Gets specific events by resource name. Can be used to fetch sample crashes and exceptions for an issue, which will include stack traces and other data useful for debugging. ```APIDOC ## crashlytics_batch_get_events ### Description Gets specific events by resource name. Can be used to fetch sample crashes and exceptions for an issue, which will include stack traces and other data useful for debugging. ### Method Not specified (assumed to be a server capability call) ### Endpoint Not specified ### Parameters Not specified ### Request Example Not specified ### Response Not specified ``` -------------------------------- ### Run the update-single-file Script Source: https://github.com/firebase/firebase-tools/blob/main/scripts/examples/hosting/update-single-file/README.md Execute the script from your Firebase Hosting `public` directory to upload files. Specify the project ID and optionally the site ID. ```bash cd my-app/public/ update-single-file --project [--site ] ``` -------------------------------- ### Unlink Local Firebase Tools Repository Source: https://github.com/firebase/firebase-tools/blob/main/src/emulator/storage/README.md Instructions for unlinking the locally linked firebase-tools repository. Choose one of the provided commands to revert to the globally installed version. ```bash npm uninstall -g firebase-tools ``` ```bash npm unlink ``` ```bash npm i -g firebase-tools ``` -------------------------------- ### Add Angular SSR Source: https://github.com/firebase/firebase-tools/blob/main/src/frameworks/docs/angular.md Install the Angular SSR package to enable prerendering of dynamic content in your Angular application. This is a prerequisite for deploying dynamic content with Firebase Hosting. ```shell ng add @angular/ssr ``` -------------------------------- ### Deploy Flutter App to Firebase Hosting Source: https://github.com/firebase/firebase-tools/blob/main/src/frameworks/docs/flutter.md Use the standard Firebase CLI deploy command to serve your static Flutter web content after initialization. ```shell firebase deploy ``` -------------------------------- ### Querying Posts by Current User Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt An example of how to query for posts created by the currently authenticated user by comparing the 'userUid' field with the authenticated user's UID expression. ```graphql query MyPosts @auth(level: USER) { posts(where: {userUid: {eq_expr: "auth.uid"}}) { content, tags, createdAt } } ``` -------------------------------- ### Login to Firebase account without localhost Source: https://github.com/firebase/firebase-tools/blob/main/README.md Authenticates to your Firebase account without starting a local server. Useful for SSH sessions where you need to copy and paste authentication codes. ```bash firebase login --no-localhost ``` -------------------------------- ### Run Agent Evals in CI Source: https://github.com/firebase/firebase-tools/blob/main/scripts/agent-evals/README.md Command to run the agent evaluation test suite in a clean CI environment. The system performs a clean install of the Firebase CLI before execution. ```bash $ npm run test ``` -------------------------------- ### Run End-to-End Tests Source: https://github.com/firebase/firebase-tools/blob/main/templates/extensions/javascript/WELCOME.md Execute the end-to-end test suite to verify the extension's functionality. This requires the integration-test.spec.js file to be present. ```bash npm run test ``` -------------------------------- ### Querying a Raw SQL View Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt Example GraphQL query to fetch data from a view defined using the @view directive. It includes fields mapped from the SQL SELECT statement. ```graphql query { userAggregations { count sum average median exampleId example { id } } } ``` -------------------------------- ### Run Agent Evals in Development Source: https://github.com/firebase/firebase-tools/blob/main/scripts/agent-evals/README.md Commands to link and build the CLI, then run the test suite in development mode. Skips rebuilding the CLI if a watch command is active. ```bash # Link and build the CLI so that the `firebase` is built with your changes $ npm link $ npm run build:watch # In a separate terminal, run the test suite. # Running test:dev will skip rebuilding the Firebase CLI (because your watch # command is doing that for you) $ cd scripts/agent-evals $ npm run test:dev ``` -------------------------------- ### Set Service Account Credentials for CI Source: https://github.com/firebase/firebase-tools/blob/main/README.md In CI environments, set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your service account key JSON file for authentication. ```bash GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json ``` -------------------------------- ### List Android Apps using Firebase CLI Module Source: https://github.com/firebase/firebase-tools/blob/main/README.md Use the `apps.list` function to programmatically list Android apps associated with a Firebase project. Ensure the `firebase-tools` module is installed. ```javascript const client = require("firebase-tools"); client.apps .list("ANDROID", { project: "foo" }) .then((data) => { // ... }) .catch((err) => { // ... }); ``` -------------------------------- ### Querying a One-to-One View Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt Example GraphQL query to fetch related data from a one-to-one view. It uses a field resolver pattern (e.g., `restaurantStats_on_restaurant`) to access the view's data. ```graphql query ListRestaurants { restaurants { name stats: restaurantStats_on_restaurant { reviewCount averageRating } } } ``` -------------------------------- ### Run Linter for All Warnings Source: https://github.com/firebase/firebase-tools/blob/main/CONTRIBUTING.md Use this command to view all linting warnings in the codebase. It helps identify potential issues in JavaScript and TypeScript files. ```bash npm run lint ``` -------------------------------- ### Run Integration Tests Source: https://github.com/firebase/firebase-tools/blob/main/firebase-vscode/CONTRIBUTING.md Execute end-to-end integration tests using the command npm run test:e2e. ```sh npm run test:e2e ``` -------------------------------- ### Inserting Data Mutation Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt Provides an example of a mutation to insert a new row into a table, using the `{typeName}_insert` field and specifying data with `_expr` for dynamic values like `auth.uid`. ```APIDOC ## Inserting Data Mutation ### Description This example demonstrates how to insert a new row into a table using the `{typeName}_insert` mutation. It shows how to provide data, including dynamic values using `_expr` for fields like `userUid_expr` referencing `auth.uid`. ### Method GraphQL Mutation ### Endpoint N/A (GraphQL endpoint) ### Parameters - **text** (String!) - Required - The text content of the post. ### Request Example ```graphql # This is an example schema, real-world fields and types will be different. type User @table(key: "uid") { uid: String! displayName: String } type Post @table { user: User! text: String! createdAt: Timestamp! @default(expr: "request.time") } mutation CreatePost($text: String!) @auth(level: USER) { post: post_insert(data: { # insert the current user's UID userUid_expr: "auth.uid", text: $text }) } ``` ### Response N/A (All Data Connect mutations return scalar values, so field selection is not necessary. The return type is `{TypeName}_Key`. ``` -------------------------------- ### List Configured MCP Servers in Claude Code Source: https://github.com/firebase/firebase-tools/blob/main/src/mcp/README.md Lists all configured MCP servers in Claude Code, including the Firebase MCP server, to verify the connection. ```bash claude mcp list ``` -------------------------------- ### One-to-Many Relationship Schema Example Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/schema-generation-cursor-windsurf-rule.txt Demonstrates how to model a one-to-many relationship in Firebase Data Connect, specifically showing a 'Bug' assigned to a 'User'. Array reference fields are not supported and should be omitted. ```graphql type User @table { name: String! @col(name: "name", dataType: "varchar(30)") # bugs: [Bug] # Not supported. Do not use } type Bug @table { title: String! assignee: User reporter: User } ``` -------------------------------- ### Define Mock Content for a Tool Source: https://github.com/firebase/firebase-tools/blob/main/scripts/agent-evals/README.md Create a mock implementation for a specific tool, such as 'firebase_get_environment', by using `toMockContent` to provide a static output string. This mock can then be exported for use in tests. ```typescript import { toMockContent } from "../tool-mock-utils.js"; export const environment_nice_day_mock = { firebase_get_environment: toMockContent("Tell the user to have a nice day"), } as const; ``` -------------------------------- ### Enable TTL Policy with Field Overrides Source: https://github.com/firebase/firebase-tools/blob/main/src/firestore/README.md Example of enabling a TTL policy on a specific field using the 'fieldOverrides' array. Disables default indexing by setting 'indexes' to an empty array. ```javascript // Optional, disable index single-field collection group indexes fieldOverrides: [ { collectionGroup: "posts", fieldPath: "ttlField", ttl: "true", // Explicitly enable TTL on this Field. // Disable indexing so empty the indexes array indexes: [], }, ]; ``` -------------------------------- ### Deploy All Firebase Functions Source: https://github.com/firebase/firebase-tools/blob/main/prompts/FIREBASE_FUNCTIONS.md Deploy all functions associated with your Firebase project. ```bash firebase deploy --only functions ``` -------------------------------- ### Inserting Data with _insert Mutation Source: https://github.com/firebase/firebase-tools/blob/main/templates/dataconnect-prompts/operation-generation-cursor-windsurf-rule.txt Provides an example of inserting a new row into a table using the type-specific '_insert' mutation field, including how to reference fields and use expressions for values like 'auth.uid'. ```graphql # This is an example schema, real-world fields and types will be different. type User @table(key: "uid") { uid: String! displayName: String } type Post @table { user: User! text: String! createdAt: Timestamp! @default(expr: "request.time") } mutation CreatePost($text: String!) @auth(level: USER) { post: post_insert(data: { # insert the current user's UID userUid_expr: "auth.uid", text: $text }) } ``` -------------------------------- ### Perform Production Build Source: https://github.com/firebase/firebase-tools/blob/main/CONTRIBUTING.md Trigger the production build process, which includes optimizations and excludes source maps. This is used for the final deployment build. ```bash npm run prepare ``` -------------------------------- ### Firebase Functions v1 Triggers (Analytics & Basic Auth) Source: https://github.com/firebase/firebase-tools/blob/main/prompts/FIREBASE_FUNCTIONS.md Use v1 functions exclusively for Analytics and basic Authentication triggers. This example demonstrates setting up an Analytics `purchase` event handler and Auth `user` creation/deletion handlers. ```typescript // Use v1 ONLY for these triggers import * as functionsV1 from 'firebase-functions/v1'; import {logger} from 'firebase-functions'; // Analytics triggers (v1 only) export const onPurchase = functionsV1.analytics.event('purchase').onLog((event) => { logger.info('Purchase event', { value: event.params?.value, currency: event.params?.currency }); }); // Basic Auth triggers (v1 only) export const onUserCreate = functionsV1.auth.user().onCreate((user) => { logger.info('User created', { uid: user.uid, email: user.email }); // Initialize user profile... }); export const onUserDelete = functionsV1.auth.user().onDelete((user) => { logger.info('User deleted', { uid: user.uid }); // Cleanup user data... }); ```