CPEL-SAC/firestore-mcp-server
If you are the rightful owner of firestore-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A Model Context Protocol (MCP) server designed for querying Firestore databases, supporting both legacy SSE and modern Streamable HTTP transports, and is Vercel compatible.
Firestore MCP Server
An MCP (Model Context Protocol) server that exposes a Firestore database as a set of read-only tools. The project ships three transports (Streamable HTTP, SSE, STDIO) so it can run locally, on traditional servers, or in serverless environments such as Vercel.
Highlights
- Firestore-aware tools to list collections, inspect sampled schemas, and run filtered/aggregated queries
- Safe serialization for Firestore primitives (timestamps, GeoPoint, references) to avoid JSON errors
- Clean MCP server bootstrap shared across STDIO, Streamable HTTP, and SSE transports
- Ready-to-use scripts for development (
npm run dev*) and production (npm start,npm run start:*) - Works with Codex CLI, Claude CLI, Gemini CLI, or any MCP-compatible client
Prerequisites
- Node.js 18+ (or the runtime required by your hosting provider)
- Firebase service account JSON with Firestore access
- Environment variable
FIREBASE_SERVICE_ACCOUNTcontaining the JSON string (single line or escaped)
.env example:
FIREBASE_SERVICE_ACCOUNT='{"type":"service_account","project_id":"your-project",...}'
PORT=3000
Install & Run
npm install
# Streamable HTTP (recommended for remote/serverless)
npm run dev # hot reload via tsx
npm start # production build (uses dist/mcp-streamable-server.js)
# SSE HTTP (legacy long-lived connections)
npm run dev:sse
npm run start:sse
# STDIO (local CLI integrations)
npm run dev:stdio
npm run start:stdio
# Build TypeScript -> dist/
npm run build
Transport Modes
Streamable HTTP (recommended)
- File:
src/mcp-streamable-server.ts - Endpoints:
GET /health– readiness probeGET|POST|DELETE /mcp– handled byStreamableHTTPServerTransport
- Stateless by default and deployable to Vercel, Netlify, Cloudflare, etc.
Server-Sent Events (legacy)
- File:
src/mcp-http-server.ts - Workflow:
GET /mcpopens the SSE stream and returns the session idPOST /mcp?sessionId=...sends JSON-RPC messagesDELETE /mcp?sessionId=...closes the session
- Suitable for platforms such as Railway or Render that keep connections open.
STDIO (local only)
- File:
src/index.ts - Exposes the same toolset over standard I/O; ideal for local CLI usage or tests.
MCP Tools
| Tool | Purpose | Notes |
|---|---|---|
list_collections | Lists all top-level collections. | Returns a newline-separated list. |
inspect_collection_schema | Samples documents (default 10) and reports field types and examples. | Handles nested objects; Firestore special types are serialized safely. |
query_firestore | Runs filters, ordering, limits, and aggregations. | Aggregations (sum, avg) ignore non-numeric entries and the response reports ignored counts. |
Example query_firestore call:
{
"name": "query_firestore",
"arguments": {
"collectionPath": "users",
"filters": [
{"field": "age", "operator": ">=", "value": 18}
],
"orderBy": [
{"field": "createdAt", "direction": "desc"}
],
"limit": 10,
"aggregation": {
"count": true,
"sum": "points",
"avg": "score"
}
}
}
Connecting MCP Clients
Codex CLI (STDIO)
{
"mcpServers": {
"firestore": {
"command": "node",
"args": ["/absolute/path/to/dist/index.js"],
"env": {
"FIREBASE_SERVICE_ACCOUNT": "<service-account-json>"
}
}
}
}
Codex/Claude/Gemini CLI (remote Streamable HTTP)
Point the client at the deployed endpoint and set transport to streamable-http:
{
"mcpServers": {
"firestore": {
"url": "https://your-app.example.com/mcp",
"transport": "streamable-http"
}
}
}
Notes
- The server is read-only; mutations must be implemented separately if required.
FIREBASE_SERVICE_ACCOUNTmust remain private—configure it in your hosting dashboard or secrets manager.
Deployment
Vercel (Streamable HTTP)
npm i -g vercelvercel loginvercel env add FIREBASE_SERVICE_ACCOUNTnpm run buildvercel --prod
Render (Streamable HTTP)
- Usa el blueprint
render.yamlo configuralo manualmente:- Build command:
npm run build - Start command:
npm start - Env var obligatoria:
FIREBASE_SERVICE_ACCOUNT
- Build command:
Railway (SSE o Streamable)
- Build command:
npm run build - Start command:
npm start(Streamable) onpm run start:sse(SSE) - Env var:
FIREBASE_SERVICE_ACCOUNT
API Summary
GET /– service metadataGET /health– health check- Streamable HTTP:
GET|POST|DELETE /mcp - SSE:
GET /mcp,POST /mcp?sessionId=...,DELETE /mcp?sessionId=...
Troubleshooting
- Missing credentials: ensure
FIREBASE_SERVICE_ACCOUNTis defined and valid JSON. - Non-numeric aggregation results: the response indicates how many documents were ignored.
- Session errors: for SSE include the
sessionIdquery parameter; for Streamable HTTP ensure clients send theMcp-Session-Idheader when required. - CORS: open CORS is enabled by default; tighten if you control the client origin.
License
MIT – see LICENSE for details.