Skip to main content
Glama

Azure Cosmos DB MCP Server

by robinong79

put_item

Insert or replace an item in an Azure Cosmos DB container by specifying the container name and the item details. Facilitates direct database interaction via natural language queries on the Azure Cosmos DB MCP Server.

Instructions

Inserts or replaces an item in a Azure Cosmos DB container

Input Schema

NameRequiredDescriptionDefault
containerNameYesName of the container
itemYesItem to insert into the container

Input Schema (JSON Schema)

{ "properties": { "containerName": { "description": "Name of the container", "type": "string" }, "item": { "description": "Item to insert into the container", "type": "object" } }, "required": [ "containerName", "item" ], "type": "object" }

Implementation Reference

  • The handler function that implements the put_item tool logic. It extracts the 'item' from params (note: ignores 'containerName' from schema, uses global container), creates the item in Cosmos DB using container.items.create(), and returns success status with the resource.
    async function putItem(params: any) { try { const { item } = params; const { resource } = await container.items.create(item); return { success: true, message: `Item added successfully to container`, item: resource, }; } catch (error) { console.error("Error putting item:", error); return { success: false, message: `Failed to put item: ${error}`, }; } }
  • Tool object defining the schema for put_item, including name, description, and inputSchema specifying containerName (string) and item (object).
    const PUT_ITEM_TOOL: Tool = { name: "put_item", description: "Inserts or replaces an item in a Azure Cosmos DB container", inputSchema: { type: "object", properties: { containerName: { type: "string", description: "Name of the container" }, item: { type: "object", description: "Item to insert into the container" }, }, required: ["containerName", "item"], }, };
  • src/index.ts:177-179 (registration)
    Registers the put_item tool in the ListToolsRequestSchema handler by including PUT_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:187-188 (registration)
    Dispatches to the putItem handler in the CallToolRequestSchema switch statement based on tool name "put_item".
    case "put_item": result = await putItem(args);

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