Google Cloud Firestore MCP Server
MCP FirestoreDB is a Node.js-based server that implements the Model Context Protocol (MCP) for Google Cloud Firestore operations. Currently at version 1.1.2, this package provides a robust set of 17 specialized tools, including document CRUD, batch operations, collection management, and advanced index configuration and analysis. It acts as an intermediary, enabling MCP-compatible clients (such as AI agents like Claude Desktop or Cursor IDE) to interact with Firestore databases via a standardized protocol. Key differentiators include its adherence to the MCP standard, comprehensive tooling for common and complex Firestore tasks (e.g., schema analysis, index generation), and capabilities for real-time operations, advanced querying, and high-performance batch processing. The package emphasizes production readiness with robust error handling and validation, and is primarily consumed by configuring it within an MCP client environment rather than requiring direct programmatic integration of its individual tools into an application. It provides the server-side logic for managing Firestore resources.
Common errors
-
Error: GOOGLE_APPLICATION_CREDENTIALS environment variable is not set.
cause The server failed to find the path to the Google service account credentials file.fixSet the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the absolute path of your service account JSON key file (e.g., `export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json`). -
Error: FIREBASE_PROJECT_ID environment variable is not set.
cause The Firebase/Google Cloud project ID was not provided to the server.fixSet the `FIREBASE_PROJECT_ID` environment variable to your specific project ID (e.g., `export FIREBASE_PROJECT_ID=my-gcp-project-123`). -
FirebaseError: The project ID is not set. Either specify a project ID via the 'projectId' property in the options object or set the GOOGLE_CLOUD_PROJECT environment variable.
cause Despite setting environment variables, the Firestore client could not pick up the project ID, possibly due to incorrect loading or application default credentials issues.fixEnsure `FIREBASE_PROJECT_ID` is correctly loaded. For programmatic usage, explicitly pass `projectId` in the configuration object to `startMCPServer`. For CLI/agent usage, verify the client's configuration for passing the project ID.
Warnings
- gotcha The `delete_collection` tool is powerful and, if used incorrectly, can permanently erase an entire Firestore collection and all its documents without confirmation. Use with extreme caution.
- breaking This package requires Node.js version 18 or higher. Running with older Node.js versions will result in execution errors due to modern JavaScript features and API dependencies.
- gotcha Correct configuration of `GOOGLE_APPLICATION_CREDENTIALS` and `FIREBASE_PROJECT_ID` environment variables is crucial for the server to authenticate with Google Cloud Firestore. Incorrect paths or missing variables will lead to authentication failures.
Install
-
npm install mcpfirestoredb -
yarn add mcpfirestoredb -
pnpm add mcpfirestoredb
Imports
- startMCPServer
const { startMCPServer } = require('mcpfirestoredb');import { startMCPServer } from 'mcpfirestoredb'; - FirestoreMCPServerConfig
import type { FirestoreMCPServerConfig } from 'mcpfirestoredb'; - MCPTool
import type { MCPTool } from 'mcpfirestoredb';
Quickstart
import { startMCPServer } from 'mcpfirestoredb';
import dotenv from 'dotenv';
import path from 'path';
dotenv.config(); // Load environment variables from .env
// Ensure required environment variables are set
if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) {
console.error('Error: GOOGLE_APPLICATION_CREDENTIALS environment variable is not set. Please provide the path to your service account JSON file.');
process.exit(1);
}
if (!process.env.FIREBASE_PROJECT_ID) {
console.error('Error: FIREBASE_PROJECT_ID environment variable is not set. Please provide your Google Cloud Project ID.');
process.exit(1);
}
async function runServer() {
try {
console.log('Starting MCP FirestoreDB Server...');
const serverInstance = await startMCPServer({
projectId: process.env.FIREBASE_PROJECT_ID,
credentialsPath: process.env.GOOGLE_APPLICATION_CREDENTIALS,
databaseId: process.env.FIRESTORE_DATABASE_ID || '(default)', // Optional
emulatorHost: process.env.FIRESTORE_EMULATOR_HOST // Optional
});
console.log(`MCP FirestoreDB Server started successfully on port ${serverInstance.port || 'default'}.`);
console.log('Ready to receive commands from MCP-compatible clients.');
} catch (error) {
console.error('Failed to start MCP FirestoreDB Server:', error);
process.exit(1);
}
}
runServer();