Skip to main content
Glama

Firebase MCP

Firebase MCP

项目标志

概述

Firebase MCP使 AI 助手能够直接与 Firebase 服务协作,包括:

  • Firestore :文档数据库操作
  • 存储:具有强大上传功能的文件管理
  • 身份验证:用户管理和验证

该服务器与 MCP 客户端应用程序(例如Claude DesktopAugment CodeVS CodeCursor)配合使用。

⚠️已知问题firestore_list_collections工具可能会在客户端日志中返回 Zod 验证错误。这是 MCP SDK 中的错误验证错误,因为我们的调查确认响应中不存在布尔值。尽管出现该错误消息,查询仍然正常运行并返回正确的集合数据。这是一个日志级别的错误,不会影响功能。

⚡ 快速入门

先决条件

  • 具有服务帐户凭据的 Firebase 项目
  • Node.js 环境

1. 安装 MCP 服务器

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

  • Claude 桌面: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 增强: ~/Library/Application Support/Code/User/settings.json
  • 游标: [project root]/.cursor/mcp.json

MCP 服务器可以手动安装,也可以在运行时通过 npx 安装(推荐)。安装方式决定了您的配置:

配置 npx(推荐)
{ "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" } } }
配置本地安装
{ "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" } } }

2.测试安装

询问您的 AI 客户:“请测试所有 Firebase MCP 工具。”

🛠️ 设置和配置

1. Firebase 配置

  1. 前往Firebase 控制台→ 项目设置 → 服务帐户
  2. 点击“生成新的私钥”
  3. 安全保存 JSON 文件

2.环境变量

必需的
  • SERVICE_ACCOUNT_KEY_PATH :Firebase 服务帐户密钥 JSON 的路径(必需)
选修的
  • FIREBASE_STORAGE_BUCKET :Firebase 存储桶名称(默认为[projectId].appspot.com
  • MCP_TRANSPORT :要使用的传输类型( stdiohttp )(默认为stdio
  • MCP_HTTP_PORT :HTTP 传输端口(默认为3000
  • MCP_HTTP_HOST :HTTP 传输的主机(默认为localhost
  • MCP_HTTP_PATH :HTTP 传输路径(默认为/mcp
  • DEBUG_LOG_FILE :启用文件日志记录:
    • 设置为true以记录到~/.firebase-mcp/debug.log
    • 设置为文件路径以记录到自定义位置

3.客户端集成

克劳德桌面

编辑: ~/Library/Application Support/Claude/claude_desktop_config.json

VS Code/增强

编辑: ~/Library/Application Support/Code/User/settings.json

光标

编辑: [project root]/.cursor/mcp.json

📚 API 参考

Firestore 工具

工具描述必需参数
firestore_add_document将文档添加到集合collectiondata
firestore_list_documents使用筛选功能列出文档collection
firestore_get_document获取特定文档collectionid
firestore_update_document更新现有文档collectioniddata
firestore_delete_document删除文档collectionid
firestore_list_collections列出根集合没有任何
firestore_query_collection_group跨子集合查询collectionId

存储工具

工具描述必需参数
storage_list_files列出目录中的文件无(可选: directoryPath
storage_get_file_info获取文件元数据和 URLfilePath
storage_upload从内容上传文件filePathcontent
storage_upload_from_url从 URL 上传文件filePathurl

身份验证工具

工具描述必需参数
auth_get_user通过 ID 或电子邮件获取用户identifier

💻 开发者指南

安装与建造

git clone https://github.com/gannonh/firebase-mcp cd firebase-mcp npm install npm run build

运行测试

首先,安装并启动 Firebase 模拟器:

npm install -g firebase-tools firebase init emulators firebase emulators:start

然后运行测试:

# Run tests with emulator npm run test:emulator # Run tests with coverage npm run test:coverage:emulator

项目结构

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

🌐 HTTP 传输

Firebase MCP 现在除了默认的 stdio 传输之外,还支持 HTTP 传输。这允许您将服务器作为独立的 HTTP 服务运行,以供多个客户端访问。

使用 HTTP 传输运行

要使用 HTTP 传输运行服务器:

# Using environment variables MCP_TRANSPORT=http MCP_HTTP_PORT=3000 node dist/index.js # Or with npx MCP_TRANSPORT=http MCP_HTTP_PORT=3000 npx @gannonh/firebase-mcp

HTTP 的客户端配置

使用 HTTP 传输时,配置您的 MCP 客户端以连接到 HTTP 端点:

{ "firebase-mcp": { "url": "http://localhost:3000/mcp" } }

会话管理

HTTP 传输支持会话管理,允许多个客户端连接到同一个服务器实例。每个客户端都会收到一个唯一的会话 ID,用于维护请求之间的状态。

🔍 故障排除

常见问题

未找到存储桶

如果您看到“指定的存储桶不存在”错误:

  1. 在 Firebase 控制台 → 存储中验证您的存储桶名称
  2. FIREBASE_STORAGE_BUCKET环境变量中设置正确的存储桶名称
Firebase 初始化失败

如果您看到“Firebase 未初始化”错误:

  1. 检查您的服务帐户密钥路径是否正确且绝对
  2. 确保服务帐户具有 Firebase 服务的适当权限
需要综合指数

如果收到“此查询需要复合索引”错误:

  1. 在错误消息中查找提供的 URL
  2. 按照链接在 Firebase 控制台中创建所需的索引
  3. 创建索引后重试查询(可能需要几分钟)
firestore_list_collections的 Zod 验证错误

如果您在使用firestore_list_collections工具时看到 Zod 验证错误,并显示消息“预期对象,收到布尔值”:

⚠️已知问题firestore_list_collections工具可能会在客户端日志中返回 Zod 验证错误。这是 MCP SDK 中的错误验证错误,因为我们的调查确认响应中不存在布尔值。尽管出现该错误消息,查询仍然正常运行并返回正确的集合数据。这是一个日志级别的错误,不会影响功能。

调试

启用文件日志记录

为了帮助诊断问题,您可以启用文件日志记录:

# Log to default location (~/.firebase-mcp/debug.log) DEBUG_LOG_FILE=true npx @gannonh/firebase-mcp # Log to a custom location DEBUG_LOG_FILE=/path/to/custom/debug.log npx @gannonh/firebase-mcp

您还可以在 MCP 客户端配置中启用日志记录:

{ "firebase-mcp": { "command": "npx", "args": ["-y", "@gannonh/firebase-mcp"], "env": { "SERVICE_ACCOUNT_KEY_PATH": "/path/to/serviceAccountKey.json", "FIREBASE_STORAGE_BUCKET": "your-project-id.firebasestorage.app", "DEBUG_LOG_FILE": "true" } } }
实时日志查看

实时查看日志:

# Using tail to follow the log file tail -f ~/.firebase-mcp/debug.log # Using a split terminal to capture stderr npm start 2>&1 | tee logs.txt
使用 MCP 检查器

MCP Inspector 提供交互式调试:

# Install MCP Inspector npm install -g @mcp/inspector # Connect to your MCP server mcp-inspector --connect stdio --command "node ./dist/index.js"

📋 响应格式

存储上传响应示例

{ "name": "reports/quarterly.pdf", "size": "1024000", "contentType": "application/pdf", "updated": "2025-04-11T15:37:10.290Z", "downloadUrl": "https://storage.googleapis.com/bucket/reports/quarterly.pdf?alt=media", "bucket": "your-project.appspot.com" }

向用户显示为:

## File Successfully Uploaded! 📁 Your file has been uploaded to Firebase Storage: **File Details:** - **Name:** reports/quarterly.pdf - **Size:** 1024000 bytes - **Type:** application/pdf - **Last Updated:** April 11, 2025 at 15:37:10 UTC **[Click here to download your file](https://storage.googleapis.com/bucket/reports/quarterly.pdf?alt=media)**

🤝 贡献

  1. 分叉存储库
  2. 创建功能分支
  3. 通过测试实施变更(要求覆盖率 80% 以上)
  4. 提交拉取请求

📄 许可证

MIT 许可证 - 详情请参阅许可证文件

🔗 相关资源

Related MCP Servers

  • A
    security
    F
    license
    A
    quality
    A server providing a unified interface to interact with Firebase services, including Authentication, Firestore, and Storage.
    Last updated -
    9
    7
    TypeScript
  • -
    security
    F
    license
    -
    quality
    An MCP server that provides access to Firebase Remote Config, allowing clients to interact with and manage Firebase remote configuration settings through the Model Context Protocol.
    Last updated -
    TypeScript
  • -
    security
    F
    license
    -
    quality
    Auto-generated MCP server that enables interaction with the Firebase App Distribution API, allowing users to manage distribution of pre-release app builds to testers through natural language commands.
    Last updated -
    Python
  • -
    security
    F
    license
    -
    quality
    An MCP Server providing access to Google's Firebase API, allowing natural language interaction with Firebase services and resources.
    Last updated -
    Python
    • Linux
    • Apple

View all related MCP servers

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gannonh/firebase-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server