Skip to main content
Glama

Azure Cosmos DB MCP Server

by robinong79

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

NameRequiredDescriptionDefault
containerNameYesName of the container
idYesID of the item to update
updatesYesThe 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

  • 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}`, }; } }
  • 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;

Other Tools

Related 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/robinong79/mcp-cosmos'

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