Skip to content
11 changes: 5 additions & 6 deletions kiro/POWER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions skills/firebase-ai-logic-basics/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)



152 changes: 152 additions & 0 deletions skills/firebase-ai-logic-basics/references/usage_patterns_android.md
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent can find the latest BoM version here: https://firebase.google.com/support/release-notes/android

Same comment for throughout.

implementation(platform("com.google.firebase:firebase-bom:<latest_bom_version>"))

// 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it need any information about suspend functions here?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using lifecycleScopy adds enough context

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
}
}
```
5 changes: 4 additions & 1 deletion skills/firebase-auth-basics/SKILL.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
163 changes: 163 additions & 0 deletions skills/firebase-auth-basics/references/client_sdk_android.md
Original file line number Diff line number Diff line change
@@ -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).
Comment on lines +15 to +19
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm... The agent should use the Firebase CLI to do this, right? The dev / agent shouldn't need to touch the Firebase console (except to set up non-CLI-supported auth providers).


### 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:<latest_bom_version>"))

// 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
```
8 changes: 5 additions & 3 deletions skills/firebase-basics/SKILL.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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`.
Expand Down Expand Up @@ -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

Expand Down
Loading