query_table
Retrieve data from a DynamoDB table using key conditions and optional filters, ensuring precise query results for efficient data management in the DynamoDB MCP Server.
Instructions
Queries a table using key conditions and optional filters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expressionAttributeNames | No | Attribute name mappings | |
| expressionAttributeValues | Yes | Values for the key condition expression | |
| filterExpression | No | Filter expression for results | |
| keyConditionExpression | Yes | Key condition expression | |
| limit | No | Maximum number of items to return | |
| tableName | Yes | Name of the table |
Implementation Reference
- src/index.ts:508-534 (handler)The main handler function that performs a DynamoDB QueryCommand based on the provided parameters including table name, key condition expression, and optional filters.async function queryTable(params: any) { try { const command = new QueryCommand({ TableName: params.tableName, KeyConditionExpression: params.keyConditionExpression, ExpressionAttributeValues: marshall(params.expressionAttributeValues), ExpressionAttributeNames: params.expressionAttributeNames, FilterExpression: params.filterExpression, Limit: params.limit, }); const response = await dynamoClient.send(command); return { success: true, message: `Query executed successfully on table ${params.tableName}`, items: response.Items ? response.Items.map(item => unmarshall(item)) : [], count: response.Count, scannedCount: response.ScannedCount, }; } catch (error) { console.error("Error querying table:", error); return { success: false, message: `Failed to query table: ${error}`, }; } }
- src/index.ts:188-203 (schema)Defines the tool schema for 'query_table', including input parameters validation and descriptions.const QUERY_TABLE_TOOL: Tool = { name: "query_table", description: "Queries a table using key conditions and optional filters", inputSchema: { type: "object", properties: { tableName: { type: "string", description: "Name of the table" }, keyConditionExpression: { type: "string", description: "Key condition expression" }, expressionAttributeValues: { type: "object", description: "Values for the key condition expression" }, expressionAttributeNames: { type: "object", description: "Attribute name mappings", optional: true }, filterExpression: { type: "string", description: "Filter expression for results", optional: true }, limit: { type: "number", description: "Maximum number of items to return", optional: true }, }, required: ["tableName", "keyConditionExpression", "expressionAttributeValues"], }, };
- src/index.ts:598-600 (registration)Registers the QUERY_TABLE_TOOL in the list of available tools returned by the ListToolsRequestHandler.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:635-637 (registration)In the CallToolRequestHandler switch statement, routes calls to the 'query_table' tool to the queryTable handler function.case "query_table": result = await queryTable(args); break;