cosmosdb_item_replace
Replace an existing item in an Azure Cosmos DB container by providing the item ID, partition key, and updated JSON data.
Instructions
Replace an item in a Cosmos DB container
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container_name | Yes | Name of the Cosmos DB container | |
| database_name | No | Name of the Cosmos DB database (optional, defaults to 'defaultdb') | |
| item_id | Yes | ID of the item to replace | |
| partition_key | Yes | Partition key value for the item | |
| item | Yes | Updated item data (JSON object) |
Implementation Reference
- mcp_server_azure/azure_server.py:285-294 (handler)Execution logic for the cosmosdb_item_replace tool: retrieves the container client and calls replace_item with the provided item_id, partition_key (used earlier), and new item body.name == "cosmosdb_item_replace" ): # Renamed from update to replace, and table to container, using replace_item for full replace container_client = database.get_container_client( arguments["container_name"] ) item = container_client.replace_item( item=arguments["item_id"], body=arguments["item"] ) response = {"item_id": item["id"], "replaced": True} elif name == "cosmosdb_item_delete": # Renamed table to container
- Input schema definition for the cosmosdb_item_replace tool, specifying parameters like container_name, database_name (optional), item_id, partition_key, and item.Tool( name="cosmosdb_item_replace", # Renamed from update to replace, and table to container, using replace_item for full replace description="Replace an item in a Cosmos DB container", # Updated description inputSchema={ "type": "object", "properties": { "container_name": { # Renamed from table_name "type": "string", "description": "Name of the Cosmos DB container", # Updated description }, "database_name": { "type": "string", "description": "Name of the Cosmos DB database (optional, defaults to 'defaultdb')", }, "item_id": { "type": "string", "description": "ID of the item to replace", }, "partition_key": { "type": "string", "description": "Partition key value for the item", }, "item": { "type": "object", "description": "Updated item data (JSON object)", }, }, "required": ["container_name", "item_id", "partition_key", "item"], }, ),
- mcp_server_azure/azure_server.py:172-176 (registration)Registration of all Azure tools, including cosmosdb_item_replace, via the list_tools handler that returns get_azure_tools().async def list_tools() -> list[Tool]: """List available Azure tools""" logger.debug("Handling list_tools request") return get_azure_tools() # Use get_azure_tools
- mcp_server_azure/azure_server.py:436-439 (registration)Tool dispatch logic in call_tool that routes cosmosdb_* tools, including cosmosdb_item_replace, to the handle_cosmosdb_operations function.elif name.startswith("cosmosdb_"): # Updated prefix to cosmosdb_ return await handle_cosmosdb_operations( azure_rm, name, arguments ) # Use cosmosdb handler