firestore_read
Read data from Firebase Firestore: list collections and documents, fetch single or multiple documents, query with filters and ordering, perform aggregations and count, and inspect indexes and distinct values.
Instructions
Read from Firebase Firestore. Use the operation field to select what to do.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ids | No | Document IDs within the collection field (used with collection for get_many_documents) | |
| path | No | Document path (EVEN segments, e.g. 'users/123' or 'stores/ABC') | |
| field | No | Single field name to count unique values for. Use fields[] for multi-field grouping. | |
| limit | No | Max number of documents to return | |
| paths | No | Full document paths for batch fetch (e.g. ['users/123', 'orders/456']) | |
| fields | No | Multiple field names to fetch. Each result value is an object keyed by field name. Use groupByFields to group on a subset. | |
| select | No | Field paths to return. Omit for all fields. | |
| filters | No | Where-clause filters | |
| orderBy | No | Ordering of results | |
| operation | Yes | - list_paths: Returns all named path templates registered in config for this project. Each entry has a template (using {param} placeholders), the extracted parameter names, whether it resolves to a document (even segments) or collection (odd segments), and an optional description. Call this early to avoid exploring the schema from scratch. - list_collections: List root collections, or subcollections of a document. Args: path?(EVEN segments — document path, e.g. "stores/ABC"), includeCounts?(bool). Returns collection paths (ODD segments) → use with list_documents or read_collection. - list_documents: List all doc IDs including phantoms. Always includes subcollections per doc. Args: collection(ODD segments). Returns document paths (EVEN segments) with collections[] → use with get_document or list_collections. - read_collection: Read documents from a collection. Args: collection(ODD segments), limit?, select?[], startAfter?(doc ID), includePhantoms?(bool) - get_document: Fetch a single document by path. Args: path(EVEN segments, e.g. "users/123"), select?[] - get_many_documents: Batch-fetch documents. Args: paths?[](each EVEN segments) OR (collection(ODD segments) + ids[]); select?[] - query_collection: Query with filters/ordering/pagination. Args: collection(ODD segments), filters?[], orderBy?[], limit?, select?[], startAfter?(doc ID) - query_collection_group: Query across all subcollections with the same name. Args: collectionId(single name, no slashes), filters?[], orderBy?[], limit?, select?[], startAfter?(full doc path) - count_documents: Server-side count without fetching docs. Args: collection(ODD segments), filters?[] - aggregate_collection: Server-side sum/avg/count aggregations. Args: collection(ODD segments), aggregations[]{alias,type,field?}, filters?[] - get_collection_schema: Infer field types by sampling docs. Args: collection(ODD segments), sampleSize?(default 20) - list_indexes: List composite indexes. Args: collectionGroup?(filter by name), includeNotReady?(bool) - distinct_values: Count occurrences of each unique value (or value combination) of one or more fields. Source: collection(ODD segments) OR collectionId(single name — queries across ALL subcollections with that name, like query_collection_group). Fields: field(single field name) OR fields([array of field names] — each result value becomes an object keyed by field name). groupByFields?([subset of fields] — use only these as the identity/grouping key; remaining fields become label arrays of unique values seen per group, e.g. groupByFields:["cashier"] with fields:["cashier","cashierNm"] groups by cashier ID while collecting all cashierNm variants as a label — useful when a display name varies across collections but the ID is stable). filters?[]. groupByPathSegment?(integer — when using collectionId, extracts this segment from the parent collection path as the byCollection key, e.g. 2 turns "shared/stores_data/ABC123/data/purchase_orders" into "ABC123"). minCollections?(integer or "all" — only return values present in at least this many distinct collection buckets; "all" means present in every bucket found without knowing the count upfront; operates on the groupByFields key so label variation across buckets does not cause missed matches; all values are annotated with collectionCount and collections[] regardless). Fetches all matching docs internally (up to maxBatchFetchSize). Returns values[] sorted by count desc. When using collectionId, also returns byCollection{} broken down by parent collection (or extracted segment). | |
| projectId | Yes | Project key as defined in firebase-mcp.json | |
| collection | No | Collection path (ODD segments, e.g. 'users' or 'users/123/posts') | |
| sampleSize | No | Number of documents to sample (default 20) | |
| startAfter | No | Pagination cursor: doc ID for collection queries, full doc path for collection group queries | |
| aggregations | No | Aggregation specs for aggregate_collection | |
| collectionId | No | Collection name without slashes (e.g. 'orders') for collection group operations | |
| groupByFields | No | Subset of fields[] to use as the grouping/identity key. Remaining fields are collected as label arrays (unique values seen per group). Allows minCollections to operate on a stable ID field even when a display name varies across collections. | |
| includeCounts | No | Include document count per collection | |
| minCollections | No | When using collectionId: only return values that appear in at least this many distinct collection buckets. Pass a number (e.g. 2) or "all" to mean "present in every collection bucket found". All returned values are annotated with collectionCount and collections[] regardless. | |
| collectionGroup | No | Filter results to a specific collection group name | |
| includeNotReady | No | Include indexes still being created or needing repair | |
| includePhantoms | No | Fall back to listDocuments() when the collection returns no docs | |
| groupByPathSegment | No | When using collectionId: 0-based index of the path segment to use as the byCollection key instead of the full path (e.g. 2 extracts "ABC123" from "shared/stores_data/ABC123/data/purchase_orders") |