Firebase MCP(Model Context Protocol)为开发者提供了通过模型上下文协议与 Firebase 服务进行交互的能力,涵盖身份验证、Firestore 数据库和云存储等功能。本指南将详细介绍其安装、配置、使用方法以及相关开发信息。
若要开始使用 Firebase MCP,请按以下步骤操作:
npm install -g firebase-tools
firebase init
在 src/index.ts 文件中,添加如下环境变量:
import { config } from 'dotenv';
config({
serviceAccountKeyPath: './path/to/service-account.json',
projectId: 'your-project-id',
storageBucket: 'your-storage-bucket.appspot.com'
});
auth.createUser 工具创建新用户。{
"tool": "auth.createUser",
"params": {
"email": "user@example.com",
"password": "secure-password"
}
}
auth.signInUser 工具让用户登录。{
"tool": "auth.signInUser",
"params": {
"email": "user@example.com",
"password": "secure-password"
}
}
{
"tool": "firestore.addDoc",
"params": {
"collectionPath": "users",
"data": {
"name": "John Doe",
"email": "john@example.com"
}
}
}
{
"tool": "firestore.queryCollection",
"params": {
"collectionPath": "users",
"filters": [
{
"field": "name",
"operator": "==",
"value": "John Doe"
}
]
}
}
{
"tool": "storage.uploadFile",
"params": {
"filePath": "uploads/profile.jpg",
"data": "base64-encoded-string"
}
}
{
"tool": "storage.getFileInfo",
"params": {
"filePath": "uploads/profile.jpg"
}
}
在 src/index.ts 文件中,导出以下模块:
export const config = require('dotenv').config();
export { default as auth } from './auth';
export { default as firestore } from './firestore';
export { default as storage } from './storage';
interface AuthConfig {
serviceAccountKeyPath: string;
projectId: string;
}
interface CreateUserParams {
email: string;
password: string;
}
interface FirestoreConfig extends AuthConfig {
storageBucket: string;
}
interface FirestoreDoc {
id?: string;
data: T;
}
在项目根目录中创建 testing.json 文件:
{
"serviceAccountKeyPath": "./test/service-account.json",
"projectId": "test-project-id",
"storageBucket": "test-storage-bucket.appspot.com"
}
使用以下命令运行测试:
npm test
Auth Interface:
createUser(params: CreateUserParams)signInUser(params: SignInUserParams)Firestore Interface:
addDoc(collectionPath: string, doc: FirestoreDoc) queryCollection(collectionPath: string, filters: Filter[])使用以下命令提交更改:
git add .
git commit -m "添加新功能"
git push origin main
本项目遵循 MIT 许可证。请查看 LICENSE 文件以获取详细信息。
serviceAccountKeyPath 是否指向正确的 JSON 文件。有问题请联系支持团队:
firebase support contact
感谢使用 Firebase MCP 协议!如需更多帮助,请参考 Firebase 官方文档。