put_item
Inserts or replaces an item in a DynamoDB table using the specified table name and item details, ensuring data management without delete functionality.
Instructions
Inserts or replaces an item in a table
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| item | Yes | Item to put into the table | |
| tableName | Yes | Name of the table |
Input Schema (JSON Schema)
{
"properties": {
"item": {
"description": "Item to put into the table",
"type": "object"
},
"tableName": {
"description": "Name of the table",
"type": "string"
}
},
"required": [
"tableName",
"item"
],
"type": "object"
}
Implementation Reference
- src/index.ts:464-483 (handler)The handler function that executes the 'put_item' tool. It marshals the provided item and sends a PutItemCommand to the DynamoDB client.async function putItem(params: any) { try { const command = new PutItemCommand({ TableName: params.tableName, Item: marshall(params.item), }); await dynamoClient.send(command); return { success: true, message: `Item added successfully to table ${params.tableName}`, item: params.item, }; } catch (error) { console.error("Error putting item:", error); return { success: false, message: `Failed to put item: ${error}`, }; }
- src/index.ts:165-172 (schema)Input schema for the 'put_item' tool, defining required parameters: tableName (string) and item (object).inputSchema: { type: "object", properties: { tableName: { type: "string", description: "Name of the table" }, item: { type: "object", description: "Item to put into the table" }, }, required: ["tableName", "item"], },
- src/index.ts:162-173 (registration)Definition of the PUT_ITEM_TOOL Tool object, which includes the name, description, and input schema for registration.const PUT_ITEM_TOOL: Tool = { name: "put_item", description: "Inserts or replaces an item in a table", inputSchema: { type: "object", properties: { tableName: { type: "string", description: "Name of the table" }, item: { type: "object", description: "Item to put into the table" }, }, required: ["tableName", "item"], }, };
- src/index.ts:598-600 (registration)Registration of the 'put_item' tool (via PUT_ITEM_TOOL) in the ListToolsRequestHandler, listing it among available tools.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [CREATE_TABLE_TOOL, UPDATE_CAPACITY_TOOL, PUT_ITEM_TOOL, GET_ITEM_TOOL, QUERY_TABLE_TOOL, SCAN_TABLE_TOOL, DESCRIBE_TABLE_TOOL, LIST_TABLES_TOOL, CREATE_GSI_TOOL, UPDATE_GSI_TOOL, CREATE_LSI_TOOL, UPDATE_ITEM_TOOL], }));
- src/index.ts:629-631 (registration)Dispatch registration in the CallToolRequestHandler switch statement, which calls the putItem handler for the 'put_item' tool.case "put_item": result = await putItem(args); break;