MCP Firestore服务器
一种模型上下文协议(MCP)服务器,为Firestore数据库操作提供双端点支持(仿真器+生产)。
安装
npx @nerd305/mcp-firestore-server配置
| 环境变量 | 目的 | 必填项? |
|---|---|---|
GOOGLE_CLOUD_PROJECT / FIREBASE_PROJECT_ID | 项目ID | 是(或从gcloud/.firebaserc自动检测到) |
FIRESTORE_EMULATOR_HOST | 仿真器地址(例如。 127.0.0.1:8080) | 否(启用模拟器目标) |
GOOGLE_APPLICATION_CREDENTIALS | 服务帐户密钥路径 | 否(启用生产目标) |
MCP_FIRESTORE_DEFAULT_TARGET | 默认目标: "emulator" 或 "production" | 否(自动解决) |
至少一个 FIRESTORE_EMULATOR_HOST 或 GOOGLE_APPLICATION_CREDENTIALS 必须设置。当两者都配置好时,服务器会同时连接到两个端点,并默认为模拟器。
使用Claude Desktop
添加到您的 .mcp.json 配置:
仅限模拟器
{
"mcpServers": {
"firestore": {
"command": "npx",
"args": ["-y", "@nerd305/mcp-firestore-server"],
"env": {
"GOOGLE_CLOUD_PROJECT": "your-project-id",
"FIRESTORE_EMULATOR_HOST": "127.0.0.1:8080"
}
}
}
}仅生产
{
"mcpServers": {
"firestore": {
"command": "npx",
"args": ["-y", "@nerd305/mcp-firestore-server"],
"env": {
"GOOGLE_CLOUD_PROJECT": "your-project-id",
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account.json"
}
}
}
}双端点(仿真器+生产)
{
"mcpServers": {
"firestore": {
"command": "npx",
"args": ["-y", "@nerd305/mcp-firestore-server"],
"env": {
"GOOGLE_CLOUD_PROJECT": "your-project-id",
"FIRESTORE_EMULATOR_HOST": "127.0.0.1:8080",
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account.json"
}
}
}
}当两者都配置好后,使用 target 任何工具上的参数,用于选择要查询的端点。默认目标是模拟器(用覆盖 MCP_FIRESTORE_DEFAULT_TARGET).
可用工具
所有工具都支持可选 target 参数("emulator" | "production")并包括已解决的 target 在每一个回应中。集合路径支持子集合(例如。 "users/uid/posts").
查询集合
从支持分页的Firestore集合中查询文档。
{
collection: string; // Collection path
limit?: number; // Default: 10
orderBy?: string;
orderDirection?: "asc" | "desc";
startAfter?: string; // Document ID for pagination (use lastDocId from previous response)
target?: "emulator" | "production";
}get_document
按ID获取特定文档。
{
collection: string;
docId: string;
target?: "emulator" | "production";
}查询地点
查询具有where条件的文档。支持多子句和自动值类型强制转换(从字符串中自动检测数字、布尔值、数组)。
{
collection: string;
// Multi-clause format (preferred)
where?: [field: string, operator: string, value: string][];
// Legacy single-clause format
field?: string;
operator?: "==" | "!=" | "" | ">=" | "array-contains" | "in" | "array-contains-any";
value?: string;
limit?: number;
orderBy?: string;
orderDirection?: "asc" | "desc";
startAfter?: string;
target?: "emulator" | "production";
}示例:
{ "collection": "users", "where": [["age", ">", "18"], ["status", "==", "active"]] }
{ "collection": "users", "field": "email", "operator": "==", "value": "user@example.com" }list_collections
列出特定文档的顶级集合或子集合。
{
documentPath?: string; // e.g. "users/uid" to list subcollections
target?: "emulator" | "production";
}count_文档
使用Firestore的本机聚合(无文档获取)统计文档。支持可选的where条件。
{
collection: string;
where?: [field: string, operator: string, value: string][];
target?: "emulator" | "production";
}批次组
在单个请求中按ID获取多个文档。
{
collection: string;
docIds: string[];
target?: "emulator" | "production";
}创建_文档
创建新文档。
{
collection: string;
docId?: string; // Auto-generated if not provided
data: object;
target?: "emulator" | "production";
}update_document
更新现有文档。
{
collection: string;
docId: string;
data: object;
merge?: boolean; // Default: true
target?: "emulator" | "production";
}删除文档
删除文档。
{
collection: string;
docId: string;
target?: "emulator" | "production";
}本地开发
- 克隆存储库
- 安装依赖项:
npm install - 在本地运行:
npm start
使用npm链接进行测试
cd mcp-firestore-server
npm link
# In your project
npm link @nerd305/mcp-firestore-server许可证
麻省理工学院
