
Firestore
STDIO提供安全、权限控制的Firebase Firestore访问服务
提供安全、权限控制的Firebase Firestore访问服务
A Model Context Protocol (MCP) server that provides secure, permission-controlled access to Firebase Firestore. This server allows AI assistants and other MCP clients to interact with Firestore databases through a standardized interface.
npm install mcp-firestore # or yarn add mcp-firestore # or pnpm add mcp-firestore
git clone https://github.com/yourusername/mcp-firestore.git cd mcp-firestore pnpm install pnpm build
Create a .env
file with your Firestore configuration:
# Required FIRESTORE_PROJECT_ID=your-project-id # Optional - for authentication GOOGLE_APPLICATION_CREDENTIALS=path/to/service-account.json
Create a permissions.json
file to control access:
{ "collections": [ { "collectionId": "users", "operations": ["read", "write", "query"] }, { "collectionId": "posts", "operations": ["read", "query"] } ], "defaultAllow": false }
# With default permissions mcp-firestore # With custom permissions file mcp-firestore --config permissions.json # With full access (development only) mcp-firestore --full-access # With read-only access to specific collections mcp-firestore --read-only --collections users,posts
Add to your Claude Desktop configuration:
{ "servers": { "firestore": { "command": "mcp-firestore", "args": ["--config", "path/to/permissions.json"], "env": { "FIRESTORE_PROJECT_ID": "your-project-id" } } } }
firestore-list-collections
{}
firestore-get-collection
{ "collectionId": "users" }
firestore-get-document
{ "collectionId": "users", "documentId": "user123" }
firestore-create-document
{ "collectionId": "users", "documentId": "user123", "data": { "name": "John Doe", "email": "[email protected]" } }
firestore-update-document
{ "collectionId": "users", "documentId": "user123", "data": { "name": "Jane Doe" } }
firestore-delete-document
{ "collectionId": "users", "documentId": "user123" }
{ "collectionId": "users", "filters": [ { "field": "age", "operator": ">", "value": 18 } ], "orderBy": { "field": "createdAt", "direction": "desc" }, "limit": 10 }
firestore-list-subcollections
{ "documentPath": "users/user123" }
firestore-get-collection-by-path
{ "collectionPath": "users/user123/orders" }
firestore-create-document-by-path
{ "collectionPath": "users/user123/orders", "data": { "item": "Widget", "quantity": 2 } }
firestore-batch-write
{ "operations": [ { "type": "create", "collectionPath": "products", "documentId": "product1", "data": { "name": "Widget" } }, { "type": "update", "documentPath": "inventory/product1", "data": { "count": 100 } } ] }
firestore-batch-read
{ "documentPaths": [ "users/user1", "users/user2", "products/product1" ] }
firestore-transaction
{ "reads": ["products/product1"], "operations": [ { "type": "update", "documentPath": "products/product1", "data": { "stock": 99 } } ], "conditionScript": "return readResults['products/product1'].data.stock > 0;" }
firestore-increment-field
{ "documentPath": "stats/daily", "field": "visitCount", "incrementBy": 1 }
firestore-array-union
{ "documentPath": "users/user123", "field": "tags", "elements": ["premium", "verified"] }
firestore-server-timestamp
{ "documentPath": "users/user123", "fields": ["lastLogin", "modifiedAt"] }
The server also provides MCP resources for direct access to Firestore data:
firestore://collections
- List all collectionsfirestore://collection/{collectionId}
- Access collection datafirestore://collection/{collectionId}/document/{documentId}
- Access document datafirestore://path/{path}
- Access any path (collections or documents)// Create a new user await client.callTool("firestore-create-document", { collectionId: "users", documentId: "user123", data: { name: "John Doe", email: "[email protected]", createdAt: new Date().toISOString() } }); // Update user data await client.callTool("firestore-update-document", { collectionId: "users", documentId: "user123", data: { lastLogin: new Date().toISOString() } }); // Query active users await client.callTool("firestore-query-collection", { collectionId: "users", filters: [ { field: "status", operator: "==", value: "active" } ], orderBy: { field: "createdAt", direction: "desc" }, limit: 10 });
// Create an order for a user await client.callTool("firestore-create-document-by-path", { collectionPath: "users/user123/orders", data: { items: ["widget1", "widget2"], total: 99.99, status: "pending" } }); // Get all orders for a user await client.callTool("firestore-get-collection-by-path", { collectionPath: "users/user123/orders" });
// Atomic updates across multiple documents await client.callTool("firestore-batch-write", { operations: [ { type: "update", documentPath: "products/widget1", data: { stock: 95 } }, { type: "create", collectionPath: "orders", data: { product: "widget1", quantity: 5, userId: "user123" } }, { type: "update", documentPath: "users/user123", data: { orderCount: 1 } } ] });
// Increment a counter await client.callTool("firestore-increment-field", { documentPath: "stats/global", field: "totalOrders", incrementBy: 1 }); // Add tags without duplicates await client.callTool("firestore-array-union", { documentPath: "products/widget1", field: "tags", elements: ["bestseller", "featured"] }); // Set server timestamp await client.callTool("firestore-server-timestamp", { documentPath: "logs/access", fields: ["timestamp", "lastModified"] });
defaultAllow: false
in production environmentspnpm test pnpm test:coverage
pnpm build
# Build image docker build -t mcp-firestore . # Run container docker run -e FIRESTORE_PROJECT_ID=your-project mcp-firestore
Authentication Errors
GOOGLE_APPLICATION_CREDENTIALS
points to a valid service accountPermission Denied
Connection Issues
Contributions are welcome! Please read our Contributing Guide for details.
MIT License - see LICENSE for details.
Built on the Model Context Protocol by Anthropic.