diff --git a/kiro/POWER.md b/kiro/POWER.md index 44332ce..cd32ad5 100644 --- a/kiro/POWER.md +++ b/kiro/POWER.md @@ -17,17 +17,16 @@ Before using the Firebase MCP server, ensure Node.js and the Firebase CLI are in - Install if needed: Download from [nodejs.org](https://nodejs.org/) (LTS version recommended) - **Firebase CLI**: Required for managing Firebase projects and services - - Check installation: `firebase --version` - - Install if needed: `npm install -g firebase-tools` + - Check installation: `npx -y firebase-tools@latest --version` - **CRITICAL**: If the Firebase CLI is not installed, DO NOT proceed with Firebase setup. - **Authentication**: Sign in to Firebase - - Check current user: `firebase login:list` - - If not signed in, run: `firebase login` (this will open a browser for Google Account authentication) + - Check current user: `npx -y firebase-tools@latest login:list` + - If not signed in, run: `npx -y firebase-tools@latest login` (this will open a browser for Google Account authentication) - **Check Projects**: Verify project access and connectivity - - Run `firebase projects:list` to check for available Firebase projects - - Use this to verify that the CLI is correctly authenticated and can reach the Firebase API; if this fails, try to reconnect using `firebase login` + - Run `npx -y firebase-tools@latest projects:list` to check for available Firebase projects + - Use this to verify that the CLI is correctly authenticated and can reach the Firebase API; if this fails, try to reconnect using `npx -y firebase-tools@latest login` - **Verify MCP Connection**: Ensure the MCP server is connected after authentication - Use the `firebase_get_environment` tool to check connection status diff --git a/skills/firebase-ai-logic-basics/SKILL.md b/skills/firebase-ai-logic-basics/SKILL.md index f7ec367..d5f4c5f 100644 --- a/skills/firebase-ai-logic-basics/SKILL.md +++ b/skills/firebase-ai-logic-basics/SKILL.md @@ -105,5 +105,7 @@ Consider that you do not need to hardcode model names (e.g., `gemini-flash-lite- [Web SDK code examples and usage patterns](references/usage_patterns_web.md) +[Android (Kotlin) SDK usage patterns](references/usage_patterns_android.md) + diff --git a/skills/firebase-ai-logic-basics/references/usage_patterns_android.md b/skills/firebase-ai-logic-basics/references/usage_patterns_android.md new file mode 100644 index 0000000..5787c37 --- /dev/null +++ b/skills/firebase-ai-logic-basics/references/usage_patterns_android.md @@ -0,0 +1,152 @@ +# Firebase AI Logic on Android (Kotlin) + +First, ensure you have initialized the Firebase App (see `firebase-basics` skill). Then, initialize +the AI Logic service as below +### 0. Enable Firebase AI Logic via CLI + +Before adding dependencies in your app, make sure you enable the AI Logic service in your Firebase Project using the Firebase CLI: + +```bash +npx -y firebase-tools@latest init +# When prompted, select 'AI logic' to enable the Gemini API in your project. +``` + + --- + +### 1. Add Dependencies + +In your module-level `build.gradle.kts` (usually `app/build.gradle.kts`), add the dependency for Firebase AI: + +```kotlin +dependencies { + // [AGENT] Fetch the latest available BoM version from Maven Central / Web before adding this + implementation(platform("com.google.firebase:firebase-bom:")) + + // Add the dependency for the Firebase AI library + implementation("com.google.firebase:firebase-ai") +} +``` + +--- + +### 2. Initialize and Generate Content + +In your Activity or Fragment, initialize the `FirebaseAI` service and generate content using a Gemini model: + +```kotlin +import com.google.firebase.ai.FirebaseAI +import com.google.firebase.ai.ktx.ai +import com.google.firebase.ktx.Firebase + +class MainActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + // Initialize Firebase AI + val ai = Firebase.ai + + // Use a model (e.g., gemini-2.5-flash-lite) + val model = ai.generativeModel("gemini-2.5-flash-lite") + + // Generate content + lifecycleScope.launch { + try { + val response = model.generateContent("Write a story about a magic backpack.") + Log.d(TAG, "Response: ${response.text}") + } catch (e: Exception) { + Log.e(TAG, "Error generating content", e) + } + } + } +} +``` + +#### Jetpack Compose (Modern) + +Initialize inside a `ComponentActivity` and use `setContent`: + +```kotlin +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.lifecycle.lifecycleScope +import com.google.firebase.Firebase +import com.google.firebase.ai.ai +import kotlinx.coroutines.launch + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val ai = Firebase.ai + val model = ai.generativeModel("gemini-2.5-flash-lite") + + lifecycleScope.launch { + val response = model.generateContent("Hello Gemini!") + setContent { + MaterialTheme { + Text("AI Response: ${response.text}") + } + } + } + } +} +``` + +--- + +### 3. Multimodal Input (Text and Images) + +Pass bitmap data along with text prompts: + +```kotlin +val image1: Bitmap = ... // Load your bitmap +val image2: Bitmap = ... + +val response = model.generateContent( + content("Analyze these images for me") { + image(image1) + image(image2) + text("Compare these two items.") + } +) +Log.d(TAG, response.text) +``` + +--- + +### 4. Chat Session (Multi-turn) + +Maintain chat history automatically: + +```kotlin +val chat = model.startChat( + history = listOf( + content("user") { text("Hello, I am a software engineer.") }, + content("model") { text("Hello! How can I help you today?") } + ) +) + +lifecycleScope.launch { + val response = chat.sendMessage("What should I learn next?") + Log.d(TAG, response.text) +} +``` + +--- + +### 5. Streaming Responses + +For faster display, stream the response: + +```kotlin +lifecycleScope.launch { + model.generateContentStream("Tell me a long story.") + .collect { chunk -> + print(chunk.text) // Update UI incrementally + } +} +``` diff --git a/skills/firebase-auth-basics/SKILL.md b/skills/firebase-auth-basics/SKILL.md index 6a73957..20e9871 100644 --- a/skills/firebase-auth-basics/SKILL.md +++ b/skills/firebase-auth-basics/SKILL.md @@ -1,7 +1,7 @@ --- name: firebase-auth-basics description: Guide for setting up and using Firebase Authentication. Use this skill when the user's app requires user sign-in, user management, or secure data access using auth rules. -compatibility: This skill is best used with the Firebase CLI, but does not require it. Install it by running `npm install -g firebase-tools`. +compatibility: This skill is best used with the Firebase CLI, but does not require it. Firebase CLI can be accessed through `npx -y firebase-tools@latest`. --- ## Prerequisites @@ -79,6 +79,9 @@ Enable other providers in the Firebase Console. **Web** See [references/client_sdk_web.md](references/client_sdk_web.md). +**Android (Kotlin)** +See [references/client_sdk_android.md](references/client_sdk_android.md). + ### 3. Security Rules Secure your data using `request.auth` in Firestore/Storage rules. diff --git a/skills/firebase-auth-basics/references/client_sdk_android.md b/skills/firebase-auth-basics/references/client_sdk_android.md new file mode 100644 index 0000000..696e7eb --- /dev/null +++ b/skills/firebase-auth-basics/references/client_sdk_android.md @@ -0,0 +1,163 @@ +# Firebase Authentication on Android (Kotlin) + +This guide walks you through using Firebase Authentication in your Android app using Kotlin DSL (`build.gradle.kts`) and Kotlin code. + +### Enable Authentication via CLI + +Before adding dependencies in your app, make sure you enable the Auth service in your Firebase Project using the Firebase CLI: + +```bash +npx -y firebase-tools@latest init auth +``` + + --- + +### 1. Enable Authentication in the Firebase Console + +Before you begin, make sure you have enabled the sign-in providers you want to use in the Firebase Console: +1. Go to **Build > Authentication > Sign-in method**. +2. Enable **Email/Password** or **Google** (or any other provider you plan to use). + +### 2. Add Dependencies + +In your module-level `build.gradle.kts` (usually `app/build.gradle.kts`), add the dependency for Firebase Authentication: + +```kotlin +dependencies { + // [AGENT] Fetch the latest available BoM version from Maven Central / Web before adding this + implementation(platform("com.google.firebase:firebase-bom:")) + + // Add the dependency for the Firebase Authentication library + // When using the BoM, you don't specify versions in Firebase library dependencies + implementation("com.google.firebase:firebase-auth") +} +``` + +--- + +### 3. Initialize FirebaseAuth + +In your Activity or Fragment, initialize the `FirebaseAuth` instance: + +```kotlin +import com.google.firebase.auth.FirebaseAuth +import com.google.firebase.auth.ktx.auth +import com.google.firebase.ktx.Firebase + +class MainActivity : AppCompatActivity() { + + private lateinit var auth: FirebaseAuth + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val auth = Firebase.auth + + setContent { + MaterialTheme { + Text("Auth initialized!") + } + } + } +} +``` + +#### Jetpack Compose (Modern) + +Initialize inside a `ComponentActivity` using `setContent`: + +```kotlin +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import com.google.firebase.Firebase +import com.google.firebase.auth.auth + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val auth = Firebase.auth + + setContent { + MaterialTheme { + Text("Auth initialized!") + } + } + } +} +``` + +--- + +### 4. Check Current Auth State + +You should check if a user is already signed in when your activity starts: + +```kotlin +public override fun onStart() { + super.onStart() + // Check if user is signed in (non-null) and update UI accordingly. + val currentUser = auth.currentUser + if (currentUser != null) { + // User is signed in, navigate to main screen or update UI + } else { + // No user is signed in, prompt for login + } +} +``` + +--- + +### 5. Sign Up New Users (Email/Password) + +Use `createUserWithEmailAndPassword` to register new users: + +```kotlin +fun signUpUser(email: String, password: String) { + auth.createUserWithEmailAndPassword(email, password) + .addOnCompleteListener(this) { task -> + if (task.isSuccessful) { + // Sign up success, update UI with the signed-in user's information + val user = auth.currentUser + // Navigate to main screen + } else { + // If sign up fails, display a message to the user. + Toast.makeText(baseContext, "Authentication failed.", Toast.LENGTH_SHORT).show() + } + } +} +``` + +--- + +### 6. Sign In Existing Users (Email/Password) + +Use `signInWithEmailAndPassword` to log in existing users: + +```kotlin +fun signInUser(email: String, password: String) { + auth.signInWithEmailAndPassword(email, password) + .addOnCompleteListener(this) { task -> + if (task.isSuccessful) { + // Sign in success, update UI with the signed-in user's information + val user = auth.currentUser + // Navigate to main screen + } else { + // If sign in fails, display a message to the user. + Toast.makeText(baseContext, "Authentication failed.", Toast.LENGTH_SHORT).show() + } + } +} +``` + +--- + +### 7. Sign Out + +To sign out a user, call `signOut()` on the `FirebaseAuth` instance: + +```kotlin +auth.signOut() +// Navigate to login screen +``` diff --git a/skills/firebase-basics/SKILL.md b/skills/firebase-basics/SKILL.md index b192ad6..46a17b8 100644 --- a/skills/firebase-basics/SKILL.md +++ b/skills/firebase-basics/SKILL.md @@ -1,6 +1,6 @@ --- name: firebase-basics -description: Core principles, workflow, and maintenance for using Firebase. Use this for all Firebase CLI tasks, building, service setup, and REFRESHING or UPDATING an existing environment. Make sure to ALWAYS use this skill whenever you are trying to use Firebase, even if not explicitly asked. +description: The definitive, foundational skill for ANY Firebase task. Make sure to ALWAYS use this skill whenever the user mentions or interacts with Firebase, even if they do not explicitly ask for it. This skill covers everything from the bare minimum INITIAL setup (Node.js setup, Firebase CLI installation, first-time login) to ongoing operations (core principles, workflows, building, service setup, executing Firebase CLI commands, troubleshooting, refreshing, or updating an existing environment). --- # Prerequisites @@ -9,7 +9,7 @@ Please complete these setup steps before proceeding, and remember your progress 1. **Local Environment Setup:** Verify the environment is properly set up so we can use Firebase tools: - Run `npx -y firebase-tools@latest --version` to check if the Firebase CLI is installed. - Verify if the Firebase MCP server is installed using your existing tools. - - If either of these checks fails, please use the `firebase-local-env-setup` skill to get the environment ready. + - If either of these checks fails, please review [references/local-env-setup.md](references/local-env-setup.md) to get the environment ready. 2. **Authentication:** Ensure you are logged in to Firebase so that commands have the correct permissions. Run `npx -y firebase-tools@latest login`. For environments without a browser (e.g., remote shells), use `npx -y firebase-tools@latest login --no-localhost`. @@ -45,7 +45,9 @@ Please adhere to these principles when working with Firebase, as they ensure rel - **Initialize Firebase:** See [references/firebase-service-init.md](references/firebase-service-init.md) when you need to initialize new Firebase services using the CLI. - **Exploring Commands:** See [references/firebase-cli-guide.md](references/firebase-cli-guide.md) to discover and understand CLI functionality. -- **SDK Setup:** For detailed guides on adding Firebase to a web app, see [references/web_setup.md](references/web_setup.md). +- **SDK Setup:** For detailed guides on adding Firebase to your app: + - **Web**: See [references/web_setup.md](references/web_setup.md) + - **Android**: See [references/android_setup.md](references/android_setup.md) # Common Issues diff --git a/skills/firebase-basics/references/android_setup.md b/skills/firebase-basics/references/android_setup.md new file mode 100644 index 0000000..045381c --- /dev/null +++ b/skills/firebase-basics/references/android_setup.md @@ -0,0 +1,47 @@ +# 🛠️ Firebase Android Setup Guide + +--- +## 📋 Prerequisites +Before running these commands, ensure you are authenticated: +` firebase login` (or `firebase login --no-localhost` on remote servers) +--- + +## 1. Create a Firebase Project +If you haven't already created a project, create a new cloud project with a unique ID: +` firebase projects:create --display-name ''` +*Example:* +` firebase projects:create my-cool-app-vguthal-20260330 --display-name 'MyCoolApp'` +### 2. Register Your Android App +Link your Android app module (package name) to your project. Notice that the display name is passed as a positional argument at the end: +` firebase apps:create ANDROID '' --package-name '' --project ` +*Example:* +` firebase apps:create ANDROID 'MyApplication' --package-name 'com.example.myapplication' --project my-cool-app-vguthal-2b` +### 3. Download `google-services.json` +Fetch the configuration file using the App ID (which is printed in the output of the previous command): +` firebase apps:sdkconfig ANDROID --project ` +*Example output extraction to file:* +` # (Output must be saved as app/google-services.json)` +--- +## ✅ Verification Plan +### Manual Verification +Validate that the project was created and registered successfully: +` firebase projects:list` +` firebase apps:list --project ` + +--- +## 🤖 AI Automation Workflow + +If you are working with an AI agent (like Antigravity), you can ask it to automate these steps for you! + +**Usage:** Ask the agent to create the app and pass the display name. + +**Example Prompt:** +"Create a Firebase app for this project. Use your own unique project ID and ask me for the display name." + +The agent will: +1. Generate a unique project ID. +2. Ask you for the app display name. +3. Automatically run the CLI commands to: + - Create the project. + - Register the app. + - Download `google-services.json` to the correct location. \ No newline at end of file diff --git a/skills/firebase-basics/references/local-env-setup.md b/skills/firebase-basics/references/local-env-setup.md new file mode 100644 index 0000000..99e6019 --- /dev/null +++ b/skills/firebase-basics/references/local-env-setup.md @@ -0,0 +1,65 @@ +# Firebase Local Environment Setup + +This skill documents the bare minimum setup required for a full Firebase experience for the agent. Before starting to use any Firebase features, you MUST verify that each of the following steps has been completed. + +## 1. Verify Node.js +- **Action**: Run `node --version`. +- **Handling**: Ensure Node.js is installed and the version is `>= 20`. If Node.js is missing or `< v20`, install it based on the operating system: + + **Recommended: Use a Node Version Manager** + This avoids permission issues when installing global packages. + + **For macOS or Linux:** + 1. Guide the user to the [official nvm repository](https://github.com/nvm-sh/nvm#installing-and-updating). + 2. Request the user to manually install `nvm` and reply when finished. **Stop and wait** for the user's confirmation. + 3. Make `nvm` available in the current terminal session by sourcing the appropriate profile: + ```bash + # For Bash + source ~/.bash_profile + source ~/.bashrc + + # For Zsh + source ~/.zprofile + source ~/.zshrc + ``` + 4. Install Node.js: + ```bash + nvm install 24 + nvm use 24 + ``` + + **For Windows:** + 1. Guide the user to download and install [nvm-windows](https://github.com/coreybutler/nvm-windows/releases). + 2. Request the user to manually install `nvm-windows` and Node.js, and reply when finished. **Stop and wait** for the user's confirmation. + 3. After the user confirms, verify Node.js is available: + ```bash + node --version + ``` + + **Alternative: Official Installer** + 1. Guide the user to download and install the LTS version from [nodejs.org](https://nodejs.org/en/download). + 2. Request the user to manually install Node.js and reply when finished. **Stop and wait** for the user's confirmation. + +## 2. Verify Firebase CLI +The Firebase CLI is the primary tool for interacting with Firebase services. +- **Action**: Run `npx -y firebase-tools@latest --version`. +- **Handling**: Ensure this command runs successfully and outputs a version number. + +## 3. Verify Firebase Authentication +You must be authenticated to manage Firebase projects. +- **Action**: Run `npx -y firebase-tools@latest login`. +- **Handling**: If the environment is remote or restricted (no browser access), run `npx -y firebase-tools@latest login --no-localhost` instead. + +## 4. Install Agent Skills and MCP Server +To fully manage Firebase, the agent needs specific skills and the Firebase MCP server installed. Identify the agent environment you are currently running in and follow the corresponding setup document strictly. + +**Read the setup document for your current agent:** +- **Gemini CLI**: Review [setup-gemini_cli.md](setup-gemini_cli.md) +- **Antigravity**: Review [setup-antigravity.md](setup-antigravity.md) +- **Claude Code**: Review [setup-claude_code.md](setup-claude_code.md) +- **Cursor**: Review [setup-cursor.md](setup-cursor.md) +- **GitHub Copilot**: Review [setup-github_copilot.md](setup-github_copilot.md) +- **Other Agents** (Windsurf, Cline, etc.): Review [setup-other_agents.md](setup-other_agents.md) + +--- +**CRITICAL AGENT RULE:** Do NOT proceed with any other Firebase tasks until EVERY step above has been successfully verified and completed. diff --git a/skills/firebase-basics/references/setup-antigravity.md b/skills/firebase-basics/references/setup-antigravity.md new file mode 100644 index 0000000..7817673 --- /dev/null +++ b/skills/firebase-basics/references/setup-antigravity.md @@ -0,0 +1,63 @@ +# Antigravity Setup + +To get the most out of Firebase in Antigravity, follow these steps to install the agent skills and the MCP server. + +### 1. Install and Verify Firebase Skills +Check if the skills are already installed before proceeding: + +1. **Check Local skills**: Run `ls -d .agent/skills/firebase-basics` or `ls -d .agents/skills/firebase-basics`. If the directory exists, the skills are already installed locally. +2. **Check Global skills**: If not found locally, check the global installation by running: + ```bash + npx skills list --global --agent antigravity + ``` + If the output includes `firebase-basics`, the skills are already installed globally. +3. **Install Skills**: If both checks fail, run the following command to install the Firebase agent skills: + ```bash + npx skills add firebase/agent-skills --agent antigravity --skill "*" + ``` + *Note: Omit `--yes` and `--global` to choose the installation location manually. If prompted interactively in the terminal, ensure you send the appropriate user choices via standard input to complete the installation.* +4. **Verify Installation**: Re-run the checks in steps 1 or 2 to confirm that `firebase-basics` is now available. + +### 2. Configure and Verify Firebase MCP Server +The MCP server allows Antigravity to interact directly with Firebase projects. + +1. **Locate `mcp_config.json`**: Find the configuration file for your operating system: + - macOS / Linux: `~/.gemini/antigravity/mcp_config.json` + - Windows: `%USERPROFILE%\\.gemini\\antigravity\\mcp_config.json` + + *Note: If the `.gemini/antigravity/` directory or `mcp_config.json` file does not exist, create them and initialize the file with `{ "mcpServers": {} }` before proceeding.* +2. **Check Existing Configuration**: Open `mcp_config.json` and check the `mcpServers` section for a `firebase` entry. + - It is already configured if the `command` is `"firebase"` OR if the `command` is `"npx"` with `"firebase-tools"` and `"mcp"` in the `args`. + - **Important**: If a valid `firebase` entry is found, the MCP server is already configured. **Skip step 3** and proceed directly to step 4. + + **Example valid configurations**: + ```json + "firebase": { + "command": "npx", + "args": ["-y", "firebase-tools@latest", "mcp"] + } + ``` + OR + ```json + "firebase": { + "command": "firebase", + "args": ["mcp"] + } + ``` +3. **Add or Update Configuration**: If the `firebase` block is missing or incorrect, add it to the `mcpServers` object: + ```json + "firebase": { + "command": "npx", + "args": [ + "-y", + "firebase-tools@latest", + "mcp" + ] + } + ``` + *CRITICAL: Merge this configuration into the existing `mcp_config.json` file. You MUST preserve any other existing servers inside the `mcpServers` object.* +4. **Verify Configuration**: Save the file and confirm the `firebase` block is present and properly formatted JSON. + +### 3. Restart and Verify Connection +1. **Restart Antigravity**: Instruct the user to restart the Antigravity application. **Stop and wait** for their confirmation before proceeding. +2. **Confirm Connection**: Check the MCP server list in the Antigravity UI to confirm that the Firebase MCP server is connected. diff --git a/skills/firebase-basics/references/setup-claude_code.md b/skills/firebase-basics/references/setup-claude_code.md new file mode 100644 index 0000000..fe8eba6 --- /dev/null +++ b/skills/firebase-basics/references/setup-claude_code.md @@ -0,0 +1,30 @@ +# Claude Code Setup + +To get the most out of Firebase in Claude Code, follow these steps to install the agent skills and the MCP server. + +## Recommended Method: Using Plugins + +The recommended method is using the plugin marketplace to install both the agent skills and the MCP functionality. + +### 1. Install and Verify Plugins + +Check if the plugins are already installed before proceeding: + +1. **Check Existing Skills**: Run `npx skills list --agent claude-code` to check for local skills. Run `npx skills list --global --agent claude-code` to check for global skills. Note whether the output includes `firebase-basics`. +2. **Check Existing MCP Configuration**: Run `claude mcp list -s user` and `claude mcp list -s project`. Note whether the output of either command includes `firebase`. +3. **Determine Installation Path**: + - If **both** skills and MCP configuration are found, the plugin is fully installed. **Stop here and skip all remaining setup steps in this document.** + - If **neither** are found, proceed to step 4. + - If **only one** is found (e.g., skills are installed but MCP is missing, or vice versa), **stop and prompt the user**. Explain the mixed state and ask if they want to proceed with installing the Firebase plugin before continuing to step 4. +4. **Add Marketplace**: Run the following command to add the marketplace (this uses the default User scope): + ```bash + claude plugin marketplace add firebase/agent-skills + ``` +5. **Install Plugins**: Run the following command to install the plugin: + ```bash + claude plugin install firebase@firebase + ``` +6. **Verify Installation**: Re-run the checks in steps 1 and 2 to confirm the skills and the MCP server are now available. + +### 2. Restart and Verify Connection +1. **Restart Claude Code**: Instruct the user to restart Claude Code. **Stop and wait** for their confirmation before proceeding. diff --git a/skills/firebase-basics/references/setup-cursor.md b/skills/firebase-basics/references/setup-cursor.md new file mode 100644 index 0000000..c74360e --- /dev/null +++ b/skills/firebase-basics/references/setup-cursor.md @@ -0,0 +1,63 @@ +# Cursor Setup + +To get the most out of Firebase in Cursor, follow these steps to install the agent skills and the MCP server. + +### 1. Install and Verify Firebase Skills +Check if the skills are already installed before proceeding: + +1. **Check Local skills**: Run `npx skills list --agent cursor`. If the output includes `firebase-basics`, the skills are already installed locally. +2. **Check Global skills**: If not found locally, check the global installation by running: + ```bash + npx skills list --global --agent cursor + ``` + If the output includes `firebase-basics`, the skills are already installed globally. +3. **Install Skills**: If both checks fail, run the following command to install the Firebase agent skills: + ```bash + npx skills add firebase/agent-skills --agent cursor --skill "*" + ``` + *Note: Omit `--yes` and `--global` to choose the installation location manually. If prompted interactively in the terminal, ensure you send the appropriate user choices via standard input to complete the installation.* +4. **Verify Installation**: Re-run the checks in steps 1 or 2 to confirm that `firebase-basics` is now available. + +### 2. Configure and Verify Firebase MCP Server +The MCP server allows Cursor to interact directly with Firebase projects. + +1. **Locate `mcp.json`**: Find the configuration file for your operating system: + - Global: `~/.cursor/mcp.json` + - Project: `.cursor/mcp.json` + + *Note: If the directory or `mcp.json` file does not exist, create them and initialize the file with `{ "mcpServers": {} }` before proceeding.* +2. **Check Existing Configuration**: Open `mcp.json` and check the `mcpServers` section for a `firebase` entry. + - It is already configured if the `command` is `"firebase"` OR if the `command` is `"npx"` with `"firebase-tools"` and `"mcp"` in the `args`. + - **Important**: If a valid `firebase` entry is found, the MCP server is already configured. **Skip step 3** and proceed directly to step 4. + + **Example valid configurations**: + ```json + "firebase": { + "command": "npx", + "args": ["-y", "firebase-tools@latest", "mcp"] + } + ``` + OR + ```json + "firebase": { + "command": "firebase", + "args": ["mcp"] + } + ``` +3. **Add or Update Configuration**: If the `firebase` block is missing or incorrect, add it to the `mcpServers` object: + ```json + "firebase": { + "command": "npx", + "args": [ + "-y", + "firebase-tools@latest", + "mcp" + ] + } + ``` + *CRITICAL: Merge this configuration into the existing `mcp.json` file. You MUST preserve any other existing servers inside the `mcpServers` object.* +4. **Verify Configuration**: Save the file and confirm the `firebase` block is present and properly formatted JSON. + +### 3. Restart and Verify Connection +1. **Restart Cursor**: Instruct the user to restart the Cursor application. **Stop and wait** for their confirmation before proceeding. +2. **Confirm Connection**: Check the MCP server list in the Cursor UI to confirm that the Firebase MCP server is connected. diff --git a/skills/firebase-basics/references/setup-gemini_cli.md b/skills/firebase-basics/references/setup-gemini_cli.md new file mode 100644 index 0000000..ebadeaa --- /dev/null +++ b/skills/firebase-basics/references/setup-gemini_cli.md @@ -0,0 +1,39 @@ +# Gemini CLI Setup + +To get the most out of Firebase in the Gemini CLI, follow these steps to install the agent extension and the MCP server. + +## Recommended: Installing Extensions + +The best way to get both the agent skills and the MCP server is via the Gemini extension. + +### 1. Install and Verify Firebase Extension +Check if the extension is already installed before proceeding: + +1. **Check Existing Extensions**: Run `gemini extensions list`. If the output includes `firebase`, the extension is already installed. +2. **Install Extension**: If not found, run the following command to install the Firebase agent skills and MCP server: + ```bash + gemini extensions install https://github.com/firebase/agent-skills + ``` +3. **Verify Installation**: Run the following checks to confirm installation: + - `gemini mcp list` -> Output should include `firebase-tools`. + - `gemini skills list` -> Output should include `firebase-basic`. + +### 2. Restart and Verify Connection +1. **Restart Gemini CLI**: Instruct the user to restart the Gemini CLI if any new installation occurred. **Stop and wait** for their confirmation before proceeding. + +--- + +## Alternative: Manual MCP Configuration (Project Scope) + +If the user only wants to use the MCP server for the current project: + +### 1. Configure and Verify Firebase MCP Server +1. **Check Existing Configuration**: Run `gemini mcp list`. If the output includes `firebase-tools`, the MCP server is already configured. +2. **Add the MCP Server**: If not found, run the following command to configure the Firebase MCP Server: + ```bash + gemini mcp add -e IS_GEMINI_CLI_EXTENSION=true firebase npx -y firebase-tools@latest mcp + ``` +3. **Verify Configuration**: Re-run `gemini mcp list` to confirm `firebase-tools` is connected. + +### 2. Restart and Verify Connection +1. **Restart Gemini CLI**: Instruct the user to restart the Gemini CLI. **Stop and wait** for their confirmation before proceeding. diff --git a/skills/firebase-basics/references/setup-github_copilot.md b/skills/firebase-basics/references/setup-github_copilot.md new file mode 100644 index 0000000..1704cb5 --- /dev/null +++ b/skills/firebase-basics/references/setup-github_copilot.md @@ -0,0 +1,70 @@ +# GitHub Copilot Setup + +To get the most out of Firebase with GitHub Copilot in VS Code, follow these steps to install the agent skills and the MCP server. + +## Recommended: Global Setup + +The agent skills and MCP server should be installed globally for consistent access across projects. + +### 1. Install and Verify Firebase Skills +Check if the skills are already installed before proceeding: + +1. **Check Local skills**: Run `npx skills list --agent github-copilot`. If the output includes `firebase-basics`, the skills are already installed locally. +2. **Check Global skills**: If not found locally, check the global installation by running: + ```bash + npx skills list --global --agent github-copilot + ``` + If the output includes `firebase-basics`, the skills are already installed globally. +3. **Install Skills**: If both checks fail, run the following command to install the Firebase agent skills: + ```bash + npx skills add firebase/agent-skills --agent github-copilot --skill "*" + ``` + *Note: Omit `--yes` and `--global` to choose the installation location manually. If prompted interactively in the terminal, ensure you send the appropriate user choices via standard input to complete the installation.* +4. **Verify Installation**: Re-run the checks in steps 1 or 2 to confirm that `firebase-basics` is now available. + +### 2. Configure and Verify Firebase MCP Server +The MCP server allows GitHub Copilot to interact directly with Firebase projects. + +1. **Locate `mcp.json`**: Find the configuration file for your environment: + - Workspace: `.vscode/mcp.json` + - Global: User Settings `mcp.json` file. + + *Note: If the `.vscode/` directory or `mcp.json` file does not exist, create them and initialize the file with `{ "mcp": { "servers": {} } }` before proceeding.* +2. **Check Existing Configuration**: Open the `mcp.json` file and check the `mcp.servers` object for a `firebase` entry. + - It is already configured if the `command` is `"firebase"` OR if the `command` is `"npx"` with `"firebase-tools"` and `"mcp"` in the `args`. + - **Important**: If a valid `firebase` entry is found, the MCP server is already configured. **Skip step 3** and proceed directly to step 4. + + **Example valid configurations**: + ```json + "firebase": { + "type": "stdio", + "command": "npx", + "args": ["-y", "firebase-tools@latest", "mcp"] + } + ``` + OR + ```json + "firebase": { + "type": "stdio", + "command": "firebase", + "args": ["mcp"] + } + ``` +3. **Add or Update Configuration**: If the `firebase` block is missing or incorrect, add it to the `mcp.servers` object: + ```json + "firebase": { + "type": "stdio", + "command": "npx", + "args": [ + "-y", + "firebase-tools@latest", + "mcp" + ] + } + ``` + *CRITICAL: Merge this configuration into the existing `mcp.json` file under the `mcp.servers` object. You MUST preserve any other existing servers inside `mcp.servers`.* +4. **Verify Configuration**: Save the file and confirm the `firebase` block is present and properly formatted JSON. + +### 3. Restart and Verify Connection +1. **Restart VS Code**: Instruct the user to restart VS Code. **Stop and wait** for their confirmation before proceeding. +2. **Confirm Connection**: Check the MCP server list in the VS Code Copilot UI to confirm that the Firebase MCP server is connected. diff --git a/skills/firebase-basics/references/setup-other_agents.md b/skills/firebase-basics/references/setup-other_agents.md new file mode 100644 index 0000000..d45a608 --- /dev/null +++ b/skills/firebase-basics/references/setup-other_agents.md @@ -0,0 +1,65 @@ +# Other Agents Setup + +If you use another agent (like Windsurf, Cline, or Claude Desktop), follow these steps to install the agent skills and the MCP server. + +## Recommended: Global Setup + +The agent skills and MCP server should be installed globally for consistent access across projects. + +### 1. Install and Verify Firebase Skills +Check if the skills are already installed before proceeding: + +1. **Check Local skills**: Run `npx skills list --agent `. If the output includes `firebase-basics`, the skills are already installed locally. Replace `` with the actual agent name, which can be found [here](https://github.com/vercel-labs/skills/blob/main/README.md). +2. **Check Global skills**: If not found locally, check the global installation by running: + ```bash + npx skills list --global --agent + ``` + If the output includes `firebase-basics`, the skills are already installed globally. +3. **Install Skills**: If both checks fail, run the following command to install the Firebase agent skills: + ```bash + npx skills add firebase/agent-skills --agent --skill "*" + ``` + *Note: Omit `--yes` and `--global` to choose the installation location manually. If prompted interactively in the terminal, ensure you send the appropriate user choices via standard input to complete the installation.* +4. **Verify Installation**: Re-run the checks in steps 1 or 2 to confirm that `firebase-basics` is now available. + +### 2. Configure and Verify Firebase MCP Server +The MCP server allows the agent to interact directly with Firebase projects. + +1. **Locate MCP Configuration**: Find the configuration file for your agent (e.g., `~/.codeium/windsurf/mcp_config.json`, `cline_mcp_settings.json`, or `claude_desktop_config.json`). + + *Note: If the document or its containing directory does not exist, create them and initialize the file with `{ "mcpServers": {} }` before proceeding.* +2. **Check Existing Configuration**: Open the configuration file and check the `mcpServers` section for a `firebase` entry. + - It is already configured if the `command` is `"firebase"` OR if the `command` is `"npx"` with `"firebase-tools"` and `"mcp"` in the `args`. + - **Important**: If a valid `firebase` entry is found, the MCP server is already configured. **Skip step 3** and proceed directly to step 4. + + **Example valid configurations**: + ```json + "firebase": { + "command": "npx", + "args": ["-y", "firebase-tools@latest", "mcp"] + } + ``` + OR + ```json + "firebase": { + "command": "firebase", + "args": ["mcp"] + } + ``` +3. **Add or Update Configuration**: If the `firebase` block is missing or incorrect, add it to the `mcpServers` object: + ```json + "firebase": { + "command": "npx", + "args": [ + "-y", + "firebase-tools@latest", + "mcp" + ] + } + ``` + *CRITICAL: Merge this configuration into the existing file. You MUST preserve any other existing servers inside the `mcpServers` object.* +4. **Verify Configuration**: Save the file and confirm the `firebase` block is present and properly formatted JSON. + +### 3. Restart and Verify Connection +1. **Restart Agent**: Instruct the user to restart the agent application. **Stop and wait** for their confirmation before proceeding. +2. **Confirm Connection**: Check the MCP server list in the agent's UI to confirm that the Firebase MCP server is connected. diff --git a/skills/firebase-data-connect-basics/reference/sdks.md b/skills/firebase-data-connect-basics/reference/sdks.md index 9885056..358ea57 100644 --- a/skills/firebase-data-connect-basics/reference/sdks.md +++ b/skills/firebase-data-connect-basics/reference/sdks.md @@ -121,7 +121,8 @@ const myReviews = await myReviews(); // @auth(level: USER) query from examples.m ```kotlin dependencies { - implementation(platform("com.google.firebase:firebase-bom:33.0.0")) + // [AGENT] Fetch the latest available BoM version from Maven Central / Web before adding this + implementation(platform("com.google.firebase:firebase-bom:")) implementation("com.google.firebase:firebase-dataconnect") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3") implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.6.0") diff --git a/skills/firebase-firestore-enterprise-native-mode/SKILL.md b/skills/firebase-firestore-enterprise-native-mode/SKILL.md index 19410f4..2f22638 100644 --- a/skills/firebase-firestore-enterprise-native-mode/SKILL.md +++ b/skills/firebase-firestore-enterprise-native-mode/SKILL.md @@ -1,7 +1,7 @@ --- name: firebase-firestore-enterprise-native-mode description: Comprehensive guide for Firestore enterprise native including provisioning, data model, security rules, and SDK usage. Use this skill when the user needs help setting up Firestore Enterprise with the Native mode, writing security rules, or using the Firestore SDK in their application. -compatibility: This skill is best used with the Firebase CLI, but does not require it. Install it by running `npm install -g firebase-tools`. +compatibility: This skill is best used with the Firebase CLI, but does not require it. Firebase CLI can be accessed through `npx -y firebase-tools@latest`. --- # Firestore Enterprise Native Mode @@ -24,6 +24,7 @@ For guidance on writing and deploying Firestore Security Rules to protect your d To learn how to use Firestore Enterprise Native Mode in your application code, see: - [Web SDK Usage](references/web_sdk_usage.md) +- [Android (Kotlin) SDK Usage](references/android_sdk_usage.md) - [Python SDK Usage](references/python_sdk_usage.md) ## Indexes diff --git a/skills/firebase-firestore-enterprise-native-mode/references/android_sdk_usage.md b/skills/firebase-firestore-enterprise-native-mode/references/android_sdk_usage.md new file mode 100644 index 0000000..823e0eb --- /dev/null +++ b/skills/firebase-firestore-enterprise-native-mode/references/android_sdk_usage.md @@ -0,0 +1,142 @@ +# Firestore Enterprise Native Mode on Android (Kotlin) + +This guide walks you through using the Cloud Firestore SDK in your Android app using Kotlin. The SDK for Firestore Enterprise Native Mode is the same as the standard Cloud Firestore SDK. + +### Enable Firestore via CLI + +Before adding dependencies in your app, make sure you enable the Firestore service in your Firebase Project using the Firebase CLI: + +```bash +npx -y firebase-tools@latest init firestore +``` + + --- + +### 1. Add Dependencies + +In your module-level `build.gradle.kts` (usually `app/build.gradle.kts`), add the dependency for Cloud Firestore: + +```kotlin +dependencies { + // [AGENT] Fetch the latest available BoM version from Maven Central / Web before adding this + implementation(platform("com.google.firebase:firebase-bom:")) + + // Add the dependency for the Cloud Firestore library + implementation("com.google.firebase:firebase-firestore") +} +``` + +--- + +### 2. Initialize Firestore + +In your Activity or Fragment, initialize the `FirebaseFirestore` instance: + +```kotlin +import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.firestore.ktx.firestore +import com.google.firebase.ktx.Firebase + +class MainActivity : AppCompatActivity() { + + private lateinit var db: FirebaseFirestore + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val db = Firebase.firestore + + setContent { + MaterialTheme { + Text("Firestore initialized!") + } + } + } +} +``` + +#### Jetpack Compose (Modern) + +Initialize inside a `ComponentActivity` using `setContent`: + +```kotlin +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import com.google.firebase.Firebase +import com.google.firebase.firestore.firestore + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val db = Firebase.firestore + + setContent { + MaterialTheme { + Text("Firestore initialized!") + } + } + } +} +``` + +--- + +### 3. Basic CRUD Operations + +The operations are identical to standard Firestore. + +#### Add Data + +```kotlin +val user = hashMapOf( + "first" to "Alan", + "last" to "Turing", + "born" to 1912 +) + +db.collection("users") + .add(user) + .addOnSuccessListener { documentReference -> + Log.d(TAG, "DocumentSnapshot added with ID: ${documentReference.id}") + } + .addOnFailureListener { e -> + Log.w(TAG, "Error adding document", e) + } +``` + +#### Read Data + +```kotlin +db.collection("users") + .get() + .addOnSuccessListener { result -> + for (document in result) { + Log.d(TAG, "${document.id} => ${document.data}") + } + } + .addOnFailureListener { exception -> + Log.w(TAG, "Error getting documents.", exception) + } +``` + +#### Update Data + +```kotlin +val userRef = db.collection("users").document("your-document-id") + +userRef + .update("born", 1913) + .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully updated!") } + .addOnFailureListener { e -> Log.w(TAG, "Error updating document", e) } +``` + +#### Delete Data + +```kotlin +db.collection("users").document("your-document-id") + .delete() + .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully deleted!") } + .addOnFailureListener { e -> Log.w(TAG, "Error deleting document", e) } +``` diff --git a/skills/firebase-firestore-enterprise-native-mode/references/provisioning.md b/skills/firebase-firestore-enterprise-native-mode/references/provisioning.md index 0152335..02a97e3 100644 --- a/skills/firebase-firestore-enterprise-native-mode/references/provisioning.md +++ b/skills/firebase-firestore-enterprise-native-mode/references/provisioning.md @@ -2,7 +2,7 @@ ## Manual Initialization -Initialize the following firebase configuration files manually. Do not use `firebase init`, as it expects interactive inputs. +Initialize the following firebase configuration files manually. Do not use `npx -y firebase-tools@latest init`, as it expects interactive inputs. 1. **Create a Firestore Enterprise Database**: Create a Firestore Enterprise database using the Firebase CLI. 2. **Create `firebase.json`**: This file contains database configuration for the Firebase CLI. @@ -34,8 +34,6 @@ firebase firestore:databases:create my-database-id \ ### 2. Create `firebase.json` -Run `firebase init firestore` to create `firebase.json` with firestore configuration you defined in step 1. - Create a file named `firebase.json` in your project root with the following content. If this file already exists, instead append to the existing JSON: ```json diff --git a/skills/firebase-firestore-standard/SKILL.md b/skills/firebase-firestore-standard/SKILL.md index 55742d3..50aefa3 100644 --- a/skills/firebase-firestore-standard/SKILL.md +++ b/skills/firebase-firestore-standard/SKILL.md @@ -1,7 +1,7 @@ --- name: firebase-firestore-standard description: Comprehensive guide for Firestore Standard Edition, including provisioning, security rules, and SDK usage. Use this skill when the user needs help setting up Firestore, writing security rules, or using the Firestore SDK in their application. -compatibility: This skill is best used with the Firebase CLI, but does not require it. Install it by running `npm install -g firebase-tools`. +compatibility: This skill is best used with the Firebase CLI, but does not require it. Firebase CLI can be accessed through `npx -y firebase-tools@latest`. --- # Firestore Standard Edition @@ -21,6 +21,7 @@ For guidance on writing and deploying Firestore Security Rules to protect your d To learn how to use Cloud Firestore in your application code, choose your platform: * **Web (Modular SDK)**: [web_sdk_usage.md](references/web_sdk_usage.md) +* **Android (Kotlin)**: [android_sdk_usage.md](references/android_sdk_usage.md) ## Indexes diff --git a/skills/firebase-firestore-standard/references/android_sdk_usage.md b/skills/firebase-firestore-standard/references/android_sdk_usage.md new file mode 100644 index 0000000..bcf7676 --- /dev/null +++ b/skills/firebase-firestore-standard/references/android_sdk_usage.md @@ -0,0 +1,189 @@ +# Cloud Firestore on Android (Kotlin) + +This guide walks you through using Cloud Firestore in your Android app using Kotlin. + +### Enable Firestore via CLI + +Before adding dependencies in your app, make sure you enable the Firestore service in your Firebase Project using the Firebase CLI: + +```bash +npx -y firebase-tools@latest init firestore +``` + + --- + +### 1. Add Dependencies + +In your module-level `build.gradle.kts` (usually `app/build.gradle.kts`), add the dependency for Cloud Firestore: + +```kotlin +dependencies { + // [AGENT] Fetch the latest available BoM version from Maven Central / Web before adding this + implementation(platform("com.google.firebase:firebase-bom:")) + + // Add the dependency for the Cloud Firestore library + // When using the BoM, you don't specify versions in Firebase library dependencies + implementation("com.google.firebase:firebase-firestore") +} +``` + +--- + +### 2. Initialize Firestore + +In your Activity or Fragment, initialize the `FirebaseFirestore` instance: + +```kotlin +import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.firestore.ktx.firestore +import com.google.firebase.ktx.Firebase + +class MainActivity : AppCompatActivity() { + + private lateinit var db: FirebaseFirestore + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val db = Firebase.firestore + + setContent { + MaterialTheme { + Text("Firestore initialized!") + } + } + } +} +``` + +#### Jetpack Compose (Modern) + +Initialize inside a `ComponentActivity` using `setContent`: + +```kotlin +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import com.google.firebase.Firebase +import com.google.firebase.firestore.firestore + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val db = Firebase.firestore + + setContent { + MaterialTheme { + Text("Firestore initialized!") + } + } + } +} +``` + +--- + +### 3. Add Data + +Add a new document with a generated ID using `add()`: + +```kotlin +// Create a new user with a first and last name +val user = hashMapOf( + "first" to "Ada", + "last" to "Lovelace", + "born" to 1815 +) + +// Add a new document with a generated ID +db.collection("users") + .add(user) + .addOnSuccessListener { documentReference -> + Log.d(TAG, "DocumentSnapshot added with ID: ${documentReference.id}") + } + .addOnFailureListener { e -> + Log.w(TAG, "Error adding document", e) + } +``` + +Or set a document with a specific ID using `set()`: + +```kotlin +val city = hashMapOf( + "name" to "Los Angeles", + "state" to "CA", + "country" to "USA" +) + +db.collection("cities").document("LA") + .set(city) + .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully written!") } + .addOnFailureListener { e -> Log.w(TAG, "Error writing document", e) } +``` + +--- + +### 4. Read Data + +Read a single document using `get()`: + +```kotlin +val docRef = db.collection("cities").document("SF") +docRef.get() + .addOnSuccessListener { document -> + if (document != null && document.exists()) { + Log.d(TAG, "DocumentSnapshot data: ${document.data}") + } else { + Log.d(TAG, "No such document") + } + } + .addOnFailureListener { exception -> + Log.d(TAG, "get failed with ", exception) + } +``` + +Read multiple documents using a query: + +```kotlin +db.collection("cities") + .whereEqualTo("capital", true) + .get() + .addOnSuccessListener { documents -> + for (document in documents) { + Log.d(TAG, "${document.id} => ${document.data}") + } + } + .addOnFailureListener { exception -> + Log.w(TAG, "Error getting documents: ", exception) + } +``` + +--- + +### 5. Update Data + +Update some fields of a document using `update()` without overwriting the entire document: + +```kotlin +val washingtonRef = db.collection("cities").document("DC") + +// Set the "isCapital" field to true +washingtonRef + .update("capital", true) + .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully updated!") } + .addOnFailureListener { e -> Log.w(TAG, "Error updating document", e) } +``` + +--- + +### 6. Delete Data + +Delete a document using `delete()`: + +```kotlin +db.collection("cities").document("DC") + .delete() + .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully deleted!") } + .addOnFailureListener { e -> Log.w(TAG, "Error deleting document", e) } +```