Skip to main content
Glama
datastax

Astra DB MCP Server

Official

EstimateDocumentCount

Quickly estimate the number of documents in a collection in Astra DB using a fast, approximate counting method to support efficient data management.

Instructions

Estimate the number of documents in a collection using a fast, approximate count method

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionNameYesName of the collection to estimate document count for

Implementation Reference

  • The main handler function implementing the EstimateDocumentCount tool. It estimates the document count in the given collection using estimatedDocumentCount() if available, falling back to fetching all documents and counting them.
    export async function EstimateDocumentCount(params: {
      collectionName: string;
    }) {
      const { collectionName } = params;
    
      const collection = db.collection(collectionName);
      
      try {
        // Try to use estimatedDocumentCount if available
        if (typeof collection.estimatedDocumentCount === 'function') {
          return await collection.estimatedDocumentCount();
        } else {
          // Last resort: get all documents and count them
          const cursor = collection.find({});
          
          // Handle the case when toArray is not available
          if (!cursor || typeof cursor.toArray !== 'function') {
            console.warn(`cursor.toArray is not available for collection '${collectionName}'`);
            return 0;
          }
          
          const documents = await cursor.toArray();
          return documents.length;
        }
      } catch (error) {
        console.error(`Error estimating document count for collection '${collectionName}':`, error);
        return 0;
      }
    }
  • The tool registration entry defining the name, description, and input schema (requiring collectionName string). This is part of the exported tools array used for listing tools.
    {
      name: "EstimateDocumentCount",
      description: "Estimate the number of documents in a collection using a fast, approximate count method",
      inputSchema: {
        type: "object",
        properties: {
          collectionName: {
            type: "string",
            description: "Name of the collection to estimate document count for",
          },
        },
        required: ["collectionName"],
      },
    },
  • index.ts:100-111 (registration)
    The switch case in the server tool call handler that dispatches to the EstimateDocumentCount function and formats the response.
    case "EstimateDocumentCount":
      const count = await EstimateDocumentCount({
        collectionName: args.collectionName as string,
      });
      return {
        content: [
          {
            type: "text",
            text: `Estimated document count in "${args.collectionName}": ${count}`,
          },
        ],
      };
  • index.ts:42-42 (registration)
    Import statement for the EstimateDocumentCount handler function.
    import { EstimateDocumentCount } from "./tools/EstimateDocumentCount.js";
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits: the method is 'fast' and 'approximate,' which helps set expectations about performance and accuracy. However, it lacks details on potential limitations (e.g., error margins, refresh rates, or permissions required), leaving gaps in behavioral context.

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, well-structured sentence that efficiently conveys the tool's purpose and key behavioral traits ('fast, approximate'). It's front-loaded with essential information and has no wasted words, making it highly concise and effective.

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?

Given the tool's moderate complexity (estimation with one parameter), no annotations, and no output schema, the description provides a basic but incomplete picture. It covers purpose and method but lacks details on output format, error handling, or integration with siblings. It's adequate as a minimum viable description but has clear gaps in context.

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?

The input schema has 100% description coverage, with the parameter 'collectionName' clearly documented. The description doesn't add any meaning beyond what the schema provides, as it doesn't mention parameters at all. With high schema coverage, the baseline score is 3, as the description doesn't compensate but also doesn't need to given the schema's clarity.

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 tool's purpose: 'Estimate the number of documents in a collection using a fast, approximate count method.' It specifies the verb ('estimate'), resource ('number of documents in a collection'), and method ('fast, approximate count'). However, it doesn't explicitly differentiate from potential siblings like 'ListRecords' or 'GetCollections' that might provide exact counts or different functionality.

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

Usage Guidelines3/5

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

The description implies usage context by mentioning 'fast, approximate count method,' suggesting this tool is for quick estimates rather than precise counts. However, it doesn't provide explicit guidance on when to use this versus alternatives (e.g., 'ListRecords' for exact counts) or any exclusions. The usage is implied but not clearly articulated.

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/datastax/astra-db-mcp'

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