# Firebase MCP控制台
## 基本信息
- Slug: `gannonh-firebase-mcp`
- Source: modelscope
- Publisher: @gannonh/firebase-mcp
- Categories: databases / cloud-storage
- Hosted: No
- License: MIT License
- Source URL: https://www.modelscope.cn/mcp/servers/@gannonh/firebase-mcp
## 简介
Firebase MCP服务器提供了一个标准化的接口来与Firebase服务进行交互，包括Firebase身份验证、Firestore和Firebase存储。
## 安装提示

```bash
#### 配置以本地安装 ```json { "firebase-mcp": { "command": "node", "args": [ "/absolute/path/to/firebase-mcp/dist/index.js" ], "env": { "SERVICE_ACCOUNT_KEY_PATH": "/absolute/path/to/serviceAccountKey.json", "FIREBASE_STORAGE_BUCKET": "your-project-id.firebasestorage.app" } } }
```

## MCP Server 详情

# Firebase MCP 服务器

![项目标志](./assets/logo.png)

<a href="https://glama.ai/mcp/servers/x4i8z2xmrq">
  <img width="380" height="200" src="https://glama.ai/mcp/servers/x4i8z2xmrq/badge" alt="Firebase MCP 服务器" />
</a>

[![Firebase 测试 CI](https://github.com/gannonh/firebase-mcp/actions/workflows/firebase-tests.yml/badge.svg)](https://github.com/gannonh/firebase-mcp/actions/workflows/firebase-tests.yml)

## 概览

[模型上下文协议 (MCP)](https://github.com/modelcontextprotocol) 是一个开放协议，使 LLM 客户端应用程序能够使用工具并访问外部数据源。此 MCP 服务器允许任何支持 MCP 协议的 LLM 客户端与 Firebase 服务进行交互，包括：

- **认证**：用户管理和验证
- **Firestore**：文档数据库操作
- **存储**：文件存储和检索

该服务器通过 MCP 工具公开 Firebase 服务，使其可以被包括 [Claude Desktop](https://claude.ai/download)、[Cursor](https://www.cursor.com/)、[Roo Code](https://github.com/RooVetGit/Roo-Code) 和 [Cline](https://cline.bot/) 在内的 LLM 客户端访问，同时处理身份验证和连接管理。

## 🔥 v1.3.0 新功能：集合组查询

Firebase MCP 现在支持在 Firestore 中查询子集合（集合组）！这使您可以跨所有同名的子集合进行查询，无论其父文档如何——从而可以通过单个查询轻松搜索整个数据库层次结构。非常适合跨文档搜索、活动流和统一仪表板。

## 设置

> 最简单的安装 Firebase MCP 服务器的方法是将 [llms-install.md](./llms-install.md) 文件提供给您的 LLM 客户端（如 Cline）。

### 1. Firebase 配置

- 前往 [Firebase 控制台](https://console.firebase.google.com)
- 导航到项目设置 > 服务账户
- 点击“生成新的私钥”
- 安全保存 JSON 文件

### 2. 环境变量

服务器需要以下环境变量：

- `SERVICE_ACCOUNT_KEY_PATH`：Firebase 服务账户密钥 JSON 文件的路径（必需）
- `FIREBASE_STORAGE_BUCKET`：Firebase 存储桶名称（可选）
  - 如果未提供，默认为 `[projectId].appspot.com`

### 3. 安装 MCP 服务器

将服务器配置添加到您的 MCP 设置文件中：

- Claude Desktop: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Cursor: `[project root]/.cursor/mcp.json`
- Roo Code (VS Code 扩展): (`~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json`)
- Cline (VS Code 扩展): `~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`

MCP 服务器可以通过 npx（推荐）手动或在运行时安装。您选择的安装方式决定了您的配置方法：

#### 配置以使用 npx

   ```json
   {
     "firebase-mcp": {
       "command": "npx",
       "args": [
         "-y",
         "@gannonh/firebase-mcp"
       ],
       "env": {
         "SERVICE_ACCOUNT_KEY_PATH": "/absolute/path/to/serviceAccountKey.json",
         "FIREBASE_STORAGE_BUCKET": "your-project-id.firebasestorage.app"
       }
     }
   }
   ```


#### 配置以本地安装

   ```json
   {
     "firebase-mcp": {
       "command": "node",
       "args": [
         "/absolute/path/to/firebase-mcp/dist/index.js"
       ],
       "env": {
         "SERVICE_ACCOUNT_KEY_PATH": "/absolute/path/to/serviceAccountKey.json",
         "FIREBASE_STORAGE_BUCKET": "your-project-id.firebasestorage.app"
       }
     }
   }
   ```


#### 手动安装

##### 安装依赖项

   ```bash
   git clone https://github.com/gannonh/firebase-mcp
   cd firebase-mcp
   npm install
   ```


##### 构建项目

   ```bash
   npm run build
   ```


### 测试您的安装

为了确保一切正常，请提示您的客户：`请运行并测试所有的 Firebase MCP 工具。`

## 功能

### 身份验证工具

- `auth_get_user`: 通过 ID 或电子邮件获取用户详细信息

  ```typescript
  {
    identifier: string // 用户 ID 或电子邮件地址
  }
  ```

### Firestore 工具

- `firestore_add_document`: 向集合中添加文档

  ```typescript
  {
    collection: string,
    data: object
  }
  ```

- `firestore_list_collections`: 列出可用的集合

  ```typescript
  {
    documentPath?: string, // 可选的父文档路径
    limit?: number,        // 默认值：20
    pageToken?: string     // 用于分页
  }
  ```

- `firestore_list_documents`: 列出文档，可选过滤条件

  ```typescript
  {
    collection: string,
    filters?: Array<{
      field: string,
      operator: string,
      value: any
    }>,
    limit?: number,
    pageToken?: string
  }
  ```

- `firestore_get_document`: 获取特定文档

  ```typescript
  {
    collection: string,
    id: string
  }
  ```

- `firestore_update_document`: 更新现有文档

  ```typescript
  {
    collection: string,
    id: string,
    data: object
  }
  ```

- `firestore_delete_document`: 删除文档

  ```typescript
  {
    collection: string,
    id: string
  }
  ```

- `firestore_query_collection_group`: 查询所有子集合中的文档 🆕

  ```typescript
  {
    collectionId: string,       // 要查询的集合 ID
    filters?: Array<{           // 可选过滤条件
      field: string,
      operator: string,         // ==, !=, <, <=, >, >=, array-contains, array-contains-any, in, not-in
      value: any
    }>,
    orderBy?: Array<{           // 可选排序字段
      field: string,
      direction?: 'asc' | 'desc' // 默认值：'asc'
    }>,
    limit?: number,             // 返回的最大文档数（默认值：20，最大值：100）
    pageToken?: string          // 分页令牌
  }
  ```

### 存储工具

- `storage_list_files`: 列出目录中的文件

  ```typescript
  {
    directoryPath?: string, // 可选路径，默认为根目录
    pageSize?: number,      // 每页项目数，默认为 10
    pageToken?: string      // 分页令牌
  }
  ```

- `storage_get_file_info`: 获取文件元数据和下载 URL

  ```typescript
  {
    filePath: string // 存储中的文件路径
  }
  ```

## 开发

### 构建

```bash
npm run build
```


### 测试

该项目使用 Vitest 进行测试。可以针对 Firebase 模拟器运行测试，以避免影响生产数据。

1. **安装 Firebase 模拟器**

   ```bash
   npm install -g firebase-tools
   firebase init emulators
   ```

2. **启动模拟器**

   ```bash
   firebase emulators:start
   ```

3. **运行测试**

   ```bash
   npm run test:emulator
   ```

### 架构

服务器分为三个主要组件：

```
src/
├── index.ts              # Server entry point
└── lib/
    └── firebase/
        ├── authClient.ts       # Authentication operations
        ├── firebaseConfig.ts   # Firebase configuration
        ├── firestoreClient.ts  # Firestore operations
        └── storageClient.ts    # Storage operations
```

每个客户端模块实现了特定的 Firebase 服务操作，并将其作为 MCP 工具公开。

## 贡献

1. 叉分仓库
2. 创建功能分支
3. 实现变更并编写测试（通过 CI 工作流需要达到80%以上的覆盖率）
4. 提交拉取请求

## 许可证

MIT 许可证 - 详情请参阅 [LICENSE](LICENSE) 文件

## 相关资源

- [模型上下文协议](https://github.com/modelcontextprotocol)
- [Firebase 文档](https://firebase.google.com/docs)
- [Firebase Admin SDK](https://firebase.google.com/docs/admin/setup)

## 故障排除

### 常见问题

#### "指定的存储桶不存在" 错误

如果您在尝试访问 Firebase Storage 时遇到此错误：

1. 检查您的 Firebase 项目是否已启用 Storage
   - 转到 Firebase 控制台
   - 导航到 Storage
   - 如果尚未完成初始设置，请完成它

2. 验证正确的存储桶名称
   - 默认存储桶名称通常是 `[projectId].appspot.com`
   - 有些项目使用的是 `[projectId].firebasestorage.app`
   - 您可以在 Firebase 控制台的 Sto…

