Skip to main content
Glama
gemini-dk

Firebase MCP Server

by gemini-dk

firestore_get_document

Retrieve a specific document from a Firestore collection by providing the collection name and document ID. This tool enables reading data from Firebase's Firestore database through the Firebase MCP Server interface.

Instructions

Get a document from a Firestore collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
idYesDocument ID

Implementation Reference

  • Implements the core logic for retrieving a specific document from a Firestore collection by collection name and document ID, including error handling, timestamp conversion, and generating console URL.
    export async function getDocument(collection: string, id: string) {
      try {
        if (!db) {
          return { content: [{ type: 'text', text: 'Firebase is not initialized. SERVICE_ACCOUNT_KEY_PATH environment variable is required.' }], isError: true };
        }
        
        const doc = await db.collection(collection).doc(id).get();
        if (!doc.exists) {
          return { content: [{ type: 'text', text: 'Document not found' }], isError: true };
        }
        const projectId = getProjectId();
        const data = doc.data();
        convertTimestampsToISO(data);
        const consoleUrl = `https://console.firebase.google.com/project/${projectId}/firestore/data/${collection}/${id}`;
        return { content: [{ type: 'text', text: JSON.stringify({ id, url: consoleUrl, document: data }) }] };
      } catch (error) {
        return { content: [{ type: 'text', text: `Error getting document: ${(error as Error).message}` }], isError: true };
      }
    }
  • Defines the input schema for the firestore_get_document tool, specifying required collection and id parameters.
    inputSchema: {
      type: 'object',
      properties: {
        collection: {
          type: 'string',
          description: 'Collection name'
        },
        id: {
          type: 'string',
          description: 'Document ID'
        }
      },
      required: ['collection', 'id']
    }
  • src/index.ts:123-140 (registration)
    Registers the firestore_get_document tool in the MCP server's tool list, including name, description, and input schema.
    {
      name: 'firestore_get_document',
      description: 'Get a document from a Firestore collection',
      inputSchema: {
        type: 'object',
        properties: {
          collection: {
            type: 'string',
            description: 'Collection name'
          },
          id: {
            type: 'string',
            description: 'Document ID'
          }
        },
        required: ['collection', 'id']
      }
    },
  • src/index.ts:238-239 (registration)
    Registers the handler dispatch for firestore_get_document tool calls in the CallToolRequestHandler switch statement.
    case 'firestore_get_document':
      return getDocument(args.collection as string, args.id as string);
  • Utility function to convert Firestore Timestamp objects to ISO date strings, used in document retrieval.
    function convertTimestampsToISO(data: any) {
      for (const key in data) {
        if (data[key] instanceof Timestamp) {
          data[key] = data[key].toDate().toISOString();
        }
      }
      return data;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the basic action but omits critical details: whether this is a read-only operation, potential error conditions (e.g., missing documents), authentication requirements, rate limits, or return format. This leaves significant gaps for agent decision-making.

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 a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 lack of annotations and output schema, the description is incomplete. It fails to address behavioral aspects like safety, error handling, or return values, which are crucial for a read operation in a database context. This leaves the agent with insufficient information for reliable use.

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?

The schema description coverage is 100%, with both parameters ('collection' and 'id') clearly documented in the schema. The description doesn't add any meaningful semantic context beyond what the schema provides, such as format examples or constraints, so it 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.

Purpose4/5

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

The description clearly states the action ('Get') and resource ('a document from a Firestore collection'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'firestore_list_documents' or 'storage_get_file_info', which prevents a perfect score.

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 guidance is provided on when to use this tool versus alternatives. The description lacks context about prerequisites (e.g., authentication), exclusions, or comparisons to siblings like 'firestore_list_documents' for listing multiple documents or 'firestore_update_document' for modifications.

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