get_item
Retrieve specific items from DynamoDB tables using their primary key with this tool. Designed for secure and precise data access without delete functionality to prevent data loss.
Instructions
Retrieves an item from a table by its primary key
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Primary key of the item to retrieve | |
| tableName | Yes | Name of the table |
Implementation Reference
- src/index.ts:486-505 (handler)The main handler function for the 'get_item' tool. It constructs a GetItemCommand with the provided tableName and key, sends it to the DynamoDB client, unmarshalls the response item if present, and returns a success/error object.async function getItem(params: any) { try { const command = new GetItemCommand({ TableName: params.tableName, Key: marshall(params.key), }); const response = await dynamoClient.send(command); return { success: true, message: `Item retrieved successfully from table ${params.tableName}`, item: response.Item ? unmarshall(response.Item) : null, }; } catch (error) { console.error("Error getting item:", error); return { success: false, message: `Failed to get item: ${error}`, }; }
- src/index.ts:175-186 (schema)The Tool object definition for 'get_item', including name, description, and inputSchema for validation (requires tableName and key).const GET_ITEM_TOOL: Tool = { name: "get_item", description: "Retrieves an item from a table by its primary key", inputSchema: { type: "object", properties: { tableName: { type: "string", description: "Name of the table" }, key: { type: "object", description: "Primary key of the item to retrieve" }, }, required: ["tableName", "key"], }, };
- src/index.ts:598-600 (registration)Registration of the 'get_item' tool (as GET_ITEM_TOOL) in the ListToolsRequestHandler, where the server lists all 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:632-634 (registration)Dispatch/registration in the CallToolRequestHandler switch statement, routing calls to 'get_item' to the getItem handler function.case "get_item": result = await getItem(args); break;
- src/index.ts:16-16 (helper)Import of the AWS SDK GetItemCommand class used in the handler.GetItemCommand,