get-item
Retrieve a specific item from a DynamoDB table using a defined key in JSON format. Simplify querying and access data directly from AWS DynamoDB databases.
Instructions
Get an item from a DynamoDB table based on a specific key
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Item key (JSON format) | |
| tableName | Yes | Table name |
Implementation Reference
- src/dynamo-helpers.ts:148-163 (handler)Core implementation of the get-item tool logic using AWS SDK's GetItemCommand to retrieve a single item from DynamoDB.export async function getItem(tableName: string, key: Record<string, any>) { console.error('# Starting getItem function:', { tableName, key }); try { const command = new GetItemCommand({ TableName: tableName, Key: key, }); console.error('# GetItem command created successfully'); const response = await dynamodb.send(command); console.error('# GetItem response received:', response); return response.Item; } catch (error) { console.error('# Error in getItem function:', error); throw error; } }
- src/index.ts:255-258 (schema)Zod input schema defining parameters for the get-item tool: tableName and key.{ tableName: z.string().describe('Table name'), key: z.record(z.any()).describe('Item key (JSON format)'), },
- src/index.ts:252-292 (registration)MCP server tool registration for 'get-item', including description, schema, and handler wrapper that calls the core getItem function.server.tool( 'get-item', 'Get an item from a DynamoDB table based on a specific key', { tableName: z.string().describe('Table name'), key: z.record(z.any()).describe('Item key (JSON format)'), }, async ({ tableName, key }) => { try { const item = await getItem(tableName, key); if (!item) { return { content: [ { type: 'text', text: 'Could not find the corresponding item.', }, ], }; } return { content: [ { type: 'text', text: JSON.stringify(item, null, 2), }, ], }; } catch (error: any) { return { isError: true, content: [ { type: 'text', text: `Error occurred: ${error.message}`, }, ], }; } } );