update_item
Modify specific attributes of an item in an Azure Cosmos DB container by providing the container name, item ID, and updated attributes.
Instructions
Updates specific attributes of an item in a Azure Cosmos DB container
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| containerName | Yes | Name of the container | |
| id | Yes | ID of the item to update | |
| updates | Yes | The updated attributes of the item |
Input Schema (JSON Schema)
{
"properties": {
"containerName": {
"description": "Name of the container",
"type": "string"
},
"id": {
"description": "ID of the item to update",
"type": "string"
},
"updates": {
"description": "The updated attributes of the item",
"type": "object"
}
},
"required": [
"containerName",
"id",
"updates"
],
"type": "object"
}
Implementation Reference
- src/index.ts:80-104 (handler)The core handler function for the update_item tool. It reads the existing item from the hardcoded Cosmos DB container, merges the provided updates (ignoring containerName), and replaces the item in the database, returning success or error details.async function updateItem(params: any) { try { const { id, updates } = params; const { resource } = await container.item(id).read(); if (!resource) { throw new Error("Item not found"); } const updatedItem = { ...resource, ...updates }; const { resource: updatedResource } = await container.item(id).replace(updatedItem); return { success: true, message: `Item updated successfully`, item: updatedResource, }; } catch (error) { console.error("Error updating item:", error); return { success: false, message: `Failed to update item: ${error}`, }; } }
- src/index.ts:25-37 (schema)Defines the tool object for update_item, including its name, description, and input schema specifying containerName, id, and updates object.const UPDATE_ITEM_TOOL: Tool = { name: "update_item", description: "Updates specific attributes of an item in a Azure Cosmos DB container", inputSchema: { type: "object", properties: { containerName: { type: "string", description: "Name of the container" }, id: { type: "string", description: "ID of the item to update" }, updates: { type: "object", description: "The updated attributes of the item" }, }, required: ["containerName", "id", "updates"], }, };
- src/index.ts:177-179 (registration)Registers the update_item tool in the ListToolsRequestHandler by including UPDATE_ITEM_TOOL in the tools array.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [PUT_ITEM_TOOL, GET_ITEM_TOOL, QUERY_CONTAINER_TOOL, UPDATE_ITEM_TOOL], }));
- src/index.ts:196-198 (registration)In the CallToolRequestHandler, the switch statement maps the 'update_item' tool name to invoke the updateItem handler function.case "update_item": result = await updateItem(args); break;