Skip to main content
Glama
gemini-dk

Firebase MCP Server

by gemini-dk

firestore_update_document

Modify existing document data in a Firestore collection by specifying the collection name, document ID, and updated fields.

Instructions

Update a document in a Firestore collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
idYesDocument ID
dataYesUpdated document data

Implementation Reference

  • The core handler function that updates a Firestore document using the Firebase Admin SDK, handles errors, converts timestamps, and returns a formatted response with console URL.
    export async function updateDocument(collection: string, id: string, data: any) {
      try {
        if (!db) {
          return { content: [{ type: 'text', text: 'Firebase is not initialized. SERVICE_ACCOUNT_KEY_PATH environment variable is required.' }], isError: true };
        }
        
        await db.collection(collection).doc(id).update(data);
        const projectId = getProjectId();
        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 updating document: ${(error as Error).message}` }], isError: true };
      }
    }
  • src/index.ts:141-162 (registration)
    Tool registration in the listTools response, including name, description, and input schema.
    {
      name: 'firestore_update_document',
      description: 'Update a document in a Firestore collection',
      inputSchema: {
        type: 'object',
        properties: {
          collection: {
            type: 'string',
            description: 'Collection name'
          },
          id: {
            type: 'string',
            description: 'Document ID'
          },
          data: {
            type: 'object',
            description: 'Updated document data'
          }
        },
        required: ['collection', 'id', 'data']
      }
    },
  • src/index.ts:240-241 (registration)
    Dispatch in the CallToolRequest handler switch statement that routes to the updateDocument implementation.
    case 'firestore_update_document':
      return updateDocument(args.collection as string, args.id as string, args.data as object);
  • Helper function used in updateDocument (and others) to convert Firestore Timestamp objects to ISO strings for JSON serialization.
    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. While 'Update' implies a mutation operation, it doesn't specify whether this is a partial or full update, if it requires specific permissions, what happens on conflicts, or what the response contains. For a mutation tool with zero annotation coverage, this leaves significant behavioral gaps.

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 any 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 this is a mutation tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the update operation returns, potential side effects, error conditions, or how it interacts with sibling tools. The high schema coverage helps with parameters, but overall context for safe and effective use is lacking.

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 clear descriptions for all three parameters (collection, id, data). The description doesn't add any additional semantic context beyond what the schema already provides, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate.

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 ('Update') and resource ('a document in a Firestore collection'), making the purpose immediately understandable. It distinguishes from siblings like firestore_add_document (create) and firestore_delete_document (delete), though it doesn't explicitly mention these distinctions in the description text itself.

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?

The description provides no guidance on when to use this tool versus alternatives like firestore_add_document for creation or firestore_get_document for reading. It lacks any context about prerequisites, such as needing an existing document to update, or exclusions for when not to use it.

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