Skip to main content
Glama
jjikky

DynamoDB Read-Only MCP

by jjikky

count-items

Count items in a DynamoDB table using optional filters to retrieve specific data. Ideal for tracking table sizes or applying conditional queries in read-only operations.

Instructions

Count items in a DynamoDB table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expressionAttributeValuesNoFilter expression attribute values (optional)
filterExpressionNoFilter expression (optional)
tableNameYesTable name

Implementation Reference

  • Core handler function that executes the item counting logic by performing a DynamoDB Scan operation with Select: 'COUNT' and optional filters.
    export async function countItems(
      tableName: string,
      filterExpression?: string,
      expressionAttributeValues?: Record<string, any>
    ) {
      console.error('# Starting countItems function:', {
        tableName,
        filterExpression,
        expressionAttributeValues,
      });
    
      try {
        const params: any = {
          TableName: tableName,
          Select: 'COUNT',
        };
    
        if (filterExpression) {
          params.FilterExpression = filterExpression;
        }
    
        if (expressionAttributeValues) {
          params.ExpressionAttributeValues = expressionAttributeValues;
        }
    
        console.error('# Count parameters:', params);
        const command = new ScanCommand(params);
        console.error('# Count command created successfully');
    
        const response = await dynamodb.send(command);
        console.error('# Count response received:', response);
        return response.Count || 0;
      } catch (error) {
        console.error('# Error in countItems function:', error);
        throw error;
      }
    }
  • src/index.ts:294-328 (registration)
    Registers the 'count-items' tool with the MCP server, defines the input schema using Zod, and provides a thin wrapper handler that calls the core countItems function and formats the MCP response.
    server.tool(
      'count-items',
      'Count items in a DynamoDB table',
      {
        tableName: z.string().describe('Table name'),
        filterExpression: z.string().optional().describe('Filter expression (optional)'),
        expressionAttributeValues: z
          .record(z.any())
          .optional()
          .describe('Filter expression attribute values (optional)'),
      },
      async ({ tableName, filterExpression, expressionAttributeValues }) => {
        try {
          const count = await countItems(tableName, filterExpression, expressionAttributeValues);
          return {
            content: [
              {
                type: 'text',
                text: `Table "${tableName}" has ${count} items.`,
              },
            ],
          };
        } catch (error: any) {
          return {
            isError: true,
            content: [
              {
                type: 'text',
                text: `Error occurred: ${error.message}`,
              },
            ],
          };
        }
      }
    );
  • Zod schema defining the input parameters for the 'count-items' tool.
    {
      tableName: z.string().describe('Table name'),
      filterExpression: z.string().optional().describe('Filter expression (optional)'),
      expressionAttributeValues: z
        .record(z.any())
        .optional()
        .describe('Filter expression attribute values (optional)'),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. It states what the tool does but doesn't mention performance characteristics (e.g., whether it's optimized for counting vs. full scans), error handling, or any constraints like rate limits or permissions required for DynamoDB operations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero wasted words. It's appropriately sized and front-loaded with the essential information, making it highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, 100% schema coverage, and no output schema, the description is minimally adequate. It states the core purpose but lacks context about when to use it versus siblings, behavioral details, or output format, leaving gaps in completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all three parameters thoroughly. The description adds no additional meaning about parameters beyond implying filtering is possible, which is already covered in the schema. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Count') and resource ('items in a DynamoDB table'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'scan-table' or 'query-table' which might also return counts, so it misses the top score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'scan-table' and 'query-table' that might offer similar functionality, there's no indication of when this specific counting tool is preferred or what its limitations are.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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/jjikky/dynamo-readonly-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server