Skip to main content
Glama
hendrickcastro

MCP CosmosDB

mcp_update_document

Replace a CosmosDB document in a container with a complete updated version. Supply container, document ID, full document (including id), and partition key. For partial updates, get the document first.

Instructions

Update (replace) an existing document in a CosmosDB container.

NOTE: This performs a full document replacement. Include ALL fields you want to keep. For partial updates, first get the document with mcp_get_document_by_id, modify it, then update.

Example: mcp_update_document({ container_id: 'users', document_id: 'user-456', document: {id: 'user-456', email: 'new@example.com', status: 'inactive'}, partition_key: 'user-456', connection_id: 'athlete' })

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_idYesThe ID/name of the container
document_idYesThe ID of the document to update
documentYesThe complete document with updated values. Must include 'id' field.
partition_keyYesThe partition key value for the document
connection_idNoID of the connection to use. Use mcp_list_connections to see available connections. If not specified, uses the default connection.

Implementation Reference

  • The main handler function for mcp_update_document. Updates (replaces) an existing document in a CosmosDB container. Takes UpdateDocumentArgs plus optional connection_id, validates modifications are allowed, ensures document ID consistency, performs the replace operation via CosmosDB SDK, and returns DocumentOperationResult with id, _etag, _ts, and requestCharge.
    export const mcp_update_document = async (args: UpdateDocumentArgs & { connection_id?: string }): Promise<ToolResult<DocumentOperationResult>> => {
      const { container_id, document_id, document, partition_key, connection_id } = args;
      log(`Executing mcp_update_document with: ${JSON.stringify({ container_id, document_id, partition_key, connection_id })}`);
    
      try {
        // Validate modifications are allowed
        validateModificationAllowed('update_document', connection_id);
        
        // Ensure document has the correct id
        if (document.id && document.id !== document_id) {
          return { success: false, error: "Document 'id' field must match 'document_id' parameter" };
        }
        
        // Ensure id is set
        const documentToUpdate = { ...document, id: document_id };
    
        const container = getContainer(container_id, connection_id);
        
        const { resource: updatedDocument, requestCharge } = await container
          .item(document_id, partition_key)
          .replace(documentToUpdate);
    
        if (!updatedDocument) {
          return { success: false, error: "Failed to update document - no response from CosmosDB" };
        }
    
        return { 
          success: true, 
          data: {
            id: updatedDocument.id,
            _etag: updatedDocument._etag,
            _ts: updatedDocument._ts,
            requestCharge: requestCharge || 0
          }
        };
      } catch (error: any) {
        log(`Error in mcp_update_document for document ${document_id}: ${error.message}`);
        
        // Provide more helpful error messages
        if (error.code === 404) {
          return { success: false, error: `Document with id '${document_id}' not found` };
        }
        
        return { success: false, error: error.message };
      }
    };
  • The UpdateDocumentArgs interface defining the input schema for mcp_update_document: container_id, document_id, document (Record<string, any>), and partition_key (string | number | boolean).
    export interface UpdateDocumentArgs {
      container_id: string;
      document_id: string;
      document: Record<string, any>;
      partition_key: PartitionKeyValue;
    }
  • src/tools.ts:276-314 (registration)
    Tool registration/definition for mcp_update_document in the MCP_COSMOSDB_TOOLS array. Defines the tool name, description (with full replacement note and example), and inputSchema with required fields: container_id, document_id, document, partition_key, and optional connection_id.
      // 10. Update/Replace Document
      {
        name: "mcp_update_document",
        description: `Update (replace) an existing document in a CosmosDB container.
    
    NOTE: This performs a full document replacement. Include ALL fields you want to keep.
    For partial updates, first get the document with mcp_get_document_by_id, modify it, then update.
    
    Example: mcp_update_document({
      container_id: 'users',
      document_id: 'user-456',
      document: {id: 'user-456', email: 'new@example.com', status: 'inactive'},
      partition_key: 'user-456',
      connection_id: 'athlete'
    })`,
        inputSchema: {
          type: "object",
          properties: {
            container_id: {
              type: "string",
              description: "The ID/name of the container"
            },
            document_id: {
              type: "string",
              description: "The ID of the document to update"
            },
            document: {
              type: "object",
              description: "The complete document with updated values. Must include 'id' field."
            },
            partition_key: {
              type: ["string", "number", "boolean"],
              description: "The partition key value for the document"
            },
            ...connectionIdProperty
          },
          required: ["container_id", "document_id", "document", "partition_key"]
        }
      },
  • src/server.ts:148-154 (registration)
    Server-side routing: the CallTool handler switch case for 'mcp_update_document' that dispatches to toolHandlers.mcp_update_document (imported from './mcp-server.js' which re-exports from './tools/index.js').
    // CRUD operations
    case 'mcp_create_document':
        result = await toolHandlers.mcp_create_document(input as any);
        break;
    case 'mcp_update_document':
        result = await toolHandlers.mcp_update_document(input as any);
        break;
  • The validateModificationAllowed helper function called by mcp_update_document. Checks if modifications are allowed for the given connection and throws an error if not, preventing unauthorized writes.
    /**
     * Validate that modifications are allowed before performing write operations
     */
    export const validateModificationAllowed = (operation: string, connectionId?: string): void => {
      const id = resolveConnectionId(connectionId);
      
      if (!isModificationAllowed(connectionId)) {
        throw new Error(
          `Database modifications are disabled for connection '${id}'. ` +
          `Operation '${operation}' was blocked. ` +
          `Set allowModifications=true in the connection config to enable write operations.`
        );
      }
    };
Behavior4/5

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

With no annotations, the description carries full burden. It states 'full document replacement' and that all fields must be included. However, it does not mention what happens if the document doesn't exist or other side effects.

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?

Concise and well-structured: a clear purpose statement, a note about replacement behavior, and an example. Every sentence adds value.

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

Completeness5/5

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

Given no output schema, the description fully explains the tool's behavior, prerequisites (get document for partial updates), and all required parameters. It references relevant sibling tools for context.

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

Parameters4/5

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

Schema coverage is 100%, baseline 3. The description adds value by explaining the full replacement nature and need to include all fields, plus an example demonstrating usage, which is beyond the schema's parameter descriptions.

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 it updates (replaces) an existing document in a CosmosDB container. It distinguishes from sibling tools like mcp_create_document, mcp_delete_document, and mcp_upsert_document by specifying it's a full replacement.

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

Usage Guidelines5/5

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

Provides explicit guidance: 'For partial updates, first get the document with mcp_get_document_by_id, modify it, then update.' This tells the agent when to use this tool versus alternatives and includes an example.

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/hendrickcastro/MCPCosmosDB'

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