Skip to main content
Glama
gemini-dk

Firebase MCP Server

by gemini-dk

firestore_list_collections

List collections in Firestore, including root collections or subcollections under a specific document path for database organization.

Instructions

List collections in Firestore. If documentPath is provided, returns subcollections under that document; otherwise returns root collections.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
documentPathNoOptional parent document path
limitNoNumber of collections to return
pageTokenNoToken for pagination to get the next page of results

Implementation Reference

  • The core handler function implementing the firestore_list_collections tool. Lists root or sub-collections in Firestore with pagination.
    export async function list_collections(documentPath?: string, limit: number = 20, pageToken?: string) {
      try {
        if (!db) {
          return { content: [{ type: 'text', text: 'Firebase is not initialized. SERVICE_ACCOUNT_KEY_PATH environment variable is required.' }], isError: true };
        }
        
        let collections;
        if (documentPath) {
          const docRef = db.doc(documentPath);
          collections = await docRef.listCollections();
        } else {
          collections = await db.listCollections();
        }
        
        // Sort collections by name
        collections.sort((a, b) => a.id.localeCompare(b.id));
        
        // Find start index
        const startIndex = pageToken ? collections.findIndex(c => c.id === pageToken) + 1 : 0;
        
        // Apply limit
        const paginatedCollections = collections.slice(startIndex, startIndex + limit);
        
        const projectId = getProjectId();
        const collectionData = paginatedCollections.map((collection) => {
          const collectionUrl = `https://console.firebase.google.com/project/${projectId}/firestore/data/${documentPath}/${collection.id}`;
          return { name: collection.id, url: collectionUrl };
        });
        
        return { 
          content: [{
            type: 'text', 
            text: JSON.stringify({
              collections: collectionData,
              nextPageToken: collections.length > startIndex + limit ? 
                paginatedCollections[paginatedCollections.length - 1].id : null,
              hasMore: collections.length > startIndex + limit
            })
          }]
        };
      } catch (error) {
        return { content: [{ type: 'text', text: `Error listing collections: ${(error as Error).message}` }], isError: true };
      }
    }
  • The input schema and metadata registration for the firestore_list_collections tool in the ListTools handler.
    {
      name: 'firestore_list_collections',
      description: 'List collections in Firestore. If documentPath is provided, returns subcollections under that document; otherwise returns root collections.',
      inputSchema: {
        type: 'object',
        properties: {
        documentPath: {
          type: 'string',
          description: 'Optional parent document path'
        },
        limit: {
          type: 'number',
          description: 'Number of collections to return',
          default: 20
        },
        pageToken: {
          type: 'string',
          description: 'Token for pagination to get the next page of results'
        }
        },
        required: []
      }
    },
  • src/index.ts:244-249 (registration)
    Tool dispatcher registration in the CallToolRequestHandler switch statement, mapping the tool name to the list_collections handler.
    case 'firestore_list_collections':
      return list_collections(
        args.documentPath as string | undefined,
        args.limit as number | undefined,
        args.pageToken as string | undefined
      );
  • src/index.ts:4-4 (registration)
    Import of the list_collections handler function from firestoreClient.
    import { addDocument, getDocument, updateDocument, deleteDocument, listDocuments, list_collections } from './lib/firebase/firestoreClient';
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses the behavioral trait of returning different results based on documentPath, which is useful. However, it doesn't mention other behavioral aspects like whether this is a read-only operation (implied but not stated), error handling, or performance considerations, leaving gaps in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loaded with the core purpose and followed by conditional behavior. Every word earns its place with no redundancy or fluff, making it highly efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (listing with optional filtering and pagination), no annotations, and no output schema, the description is adequate but incomplete. It covers the basic operation and parameter effect, but lacks details on return format, error cases, or pagination behavior, which would be helpful for an agent to use it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters. The description adds marginal value by explaining the effect of documentPath on the operation, but doesn't provide additional syntax, format details, or usage examples beyond what the schema specifies. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('collections in Firestore'), specifying the exact operation. It distinguishes from sibling tools like firestore_list_documents (which lists documents) and firestore_get_document (which retrieves a single document), making the purpose specific and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use the tool: with documentPath for subcollections or without it for root collections. However, it doesn't explicitly mention when not to use it or name alternatives (e.g., firestore_list_documents for listing documents instead of collections), so it falls short of a perfect score.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gemini-dk/mcp-server-firebase'

If you have feedback or need assistance with the MCP directory API, please join our Discord server