Skip to main content
Glama
NigelThorne

Firebase MCP Server

by NigelThorne

query_collection

Retrieve Firestore documents from a collection using filters, ordering, and limits to find specific data in Firebase Emulator environments.

Instructions

Query a collection with filters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionPathYesCollection path
filtersNoArray of filter objects: {field, operator, value}
orderByNoField to order by
orderDirectionNo
limitNoMax documents to return (default: 20)

Implementation Reference

  • The implementation of the `handleQueryCollection` function, which executes the actual Firestore query based on provided filters, ordering, and limits.
    async function handleQueryCollection(
      collectionPath: string,
      filters?: QueryFilter[],
      orderBy?: string,
      orderDirection?: "asc" | "desc",
      limit = 20
    ) {
      let query: FirebaseFirestore.Query = db.collection(collectionPath);
      if (filters) {
        for (const filter of filters) {
          query = query.where(filter.field, filter.operator, filter.value);
        }
      }
      if (orderBy) {
        query = query.orderBy(orderBy, orderDirection || "asc");
      }
      query = query.limit(limit);
      const snapshot = await query.get();
      return snapshot.docs.map(docToObject);
    }
  • The tool definition and input schema registration for `query_collection` in `src/index.ts`.
      name: "query_collection",
      description: "Query a collection with filters",
      inputSchema: {
        type: "object" as const,
        properties: {
          collectionPath: { type: "string", description: "Collection path" },
          filters: {
            type: "array",
            description: "Array of filter objects: {field, operator, value}",
            items: {
              type: "object",
              properties: {
                field: { type: "string" },
                operator: { type: "string", enum: ["==", "!=", "<", "<=", ">", ">=", "array-contains", "in", "array-contains-any"] },
                value: {},
              },
              required: ["field", "operator", "value"],
            },
          },
          orderBy: { type: "string", description: "Field to order by" },
          orderDirection: { type: "string", enum: ["asc", "desc"] },
          limit: { type: "number", description: "Max documents to return (default: 20)" },
        },
        required: ["collectionPath"],
      },
    },
  • src/index.ts:407-415 (registration)
    The registration of the `query_collection` case within the `CallToolRequestSchema` handler in `src/index.ts`.
    case "query_collection":
      result = await handleQueryCollection(
        args?.collectionPath as string,
        args?.filters as QueryFilter[],
        args?.orderBy as string,
        args?.orderDirection as "asc" | "desc",
        args?.limit as number
      );
      break;
Behavior2/5

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

No annotations are provided, so the description must carry the full burden of behavioral disclosure. It fails to indicate whether this is read-only, what happens when no documents match, pagination behavior, or performance characteristics. Only the basic action is stated.

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

Conciseness3/5

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

Extremely terse at 5 words. While there is no wasted prose, the brevity constitutes underspecification rather than efficient precision given the tool's complexity (5 parameters, nested filter objects).

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

Completeness2/5

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

Given the presence of complex filtering, ordering, and limiting capabilities alongside 5 parameters and no output schema, the single-sentence description is insufficient. It omits return value description, error conditions, and maximum result limits.

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 coverage is 80% (high), establishing a baseline of 3. The schema already documents the filter structure, ordering, and limits adequately. The description mentions 'filters' but adds no additional semantics regarding syntax or valid combinations beyond the schema.

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

Purpose4/5

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

Specific verb 'Query' and resource 'collection' are stated, with mention of 'filters' indicating the key capability. However, it fails to distinguish from sibling 'list_documents' or clarify when querying is preferable to listing.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool versus alternatives like 'list_documents' or 'get_document'. No prerequisites or conditions mentioned.

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/NigelThorne/firebase_mcp_server'

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