Skip to main content
Glama
johnreitano

MCP Datastore Server

by johnreitano

datastore_count

Query and count entities in Google Cloud Datastore by specifying the entity kind and optional filters to match exact field values.

Instructions

Count entities in a kind, optionally with a filter

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldNoThe field name to filter on (optional)
kindYesThe entity kind to count
valueNoThe value to match exactly (required if field is provided)

Implementation Reference

  • Core implementation of the datastore_count tool logic: creates a Datastore query for the given kind, applies optional filter on field/value, runs the query, and returns the count of matching entities.
    async countEntities(kind: string, field?: string, value?: string): Promise<number> {
      try {
        let query = this.datastore.createQuery(kind).select('__key__');
    
        if (field && value !== undefined) {
          if (field === '__key__' || field === 'key') {
            const keyValue = isNaN(Number(value)) ? value : parseInt(value);
            const entityKey = this.datastore.key([kind, keyValue]);
            query = query.filter('__key__', '=', entityKey);
          } else {
            const convertedValue = this.convertValue(value);
            query = query.filter(field, '=', convertedValue);
          }
        }
    
        const [entities] = await this.datastore.runQuery(query);
        return entities.length;
      } catch (error) {
        throw new Error(`Failed to count entities: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • MCP CallTool handler for 'datastore_count': extracts arguments, calls DatastoreClient.countEntities, formats and returns the count as text content.
    case 'datastore_count':
      const count = await datastoreClient.countEntities(
        args.kind as string,
        args.field as string | undefined,
        args.value as string | undefined
      );
      return {
        content: [
          {
            type: 'text',
            text: `Count: ${count}`,
          },
        ],
      };
  • src/index.ts:106-127 (registration)
    Registers the 'datastore_count' tool in the ListTools response, including name, description, and input schema.
    {
      name: 'datastore_count',
      description: 'Count entities in a kind, optionally with a filter',
      inputSchema: {
        type: 'object',
        properties: {
          kind: {
            type: 'string',
            description: 'The entity kind to count',
          },
          field: {
            type: 'string',
            description: 'The field name to filter on (optional)',
          },
          value: {
            type: 'string',
            description: 'The value to match exactly (required if field is provided)',
          },
        },
        required: ['kind'],
      },
    },
  • Input schema definition for the datastore_count tool, specifying parameters: kind (required), field and value (optional for filtering).
    inputSchema: {
      type: 'object',
      properties: {
        kind: {
          type: 'string',
          description: 'The entity kind to count',
        },
        field: {
          type: 'string',
          description: 'The field name to filter on (optional)',
        },
        value: {
          type: 'string',
          description: 'The value to match exactly (required if field is provided)',
        },
      },
      required: ['kind'],
  • Helper method used in countEntities (and others) to convert string filter values to appropriate types (boolean, number, etc.).
    private convertValue(value: string): any {
      if (value.toLowerCase() === 'true') return true;
      if (value.toLowerCase() === 'false') return false;
      if (value.toLowerCase() === 'null') return null;
      
      const numValue = Number(value);
      if (!isNaN(numValue)) return numValue;
      
      return value;
    }
Behavior2/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 mentions optional filtering but doesn't disclose behavioral traits such as performance implications, rate limits, authentication needs, or what happens with large datasets. For a read operation with no annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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, efficient sentence that front-loads the core purpose ('Count entities in a kind') and adds necessary detail ('optionally with a filter') without any wasted words. Every part earns its place, making it highly concise and well-structured.

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

Completeness2/5

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

Given the complexity of a counting tool with filtering, no annotations, and no output schema, the description is incomplete. It doesn't explain the return value (e.g., integer count), error conditions, or how filtering works semantically, leaving the agent with insufficient context to use the tool effectively beyond basic parameter passing.

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 parameters (kind, field, value) with their descriptions and requirements. The description adds minimal value by hinting at the optional filter but doesn't provide additional semantics beyond what the schema specifies, meeting the baseline for high coverage.

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 verb ('count') and resource ('entities in a kind'), making the purpose specific and understandable. It distinguishes from siblings like datastore_filter (which likely returns entities) and datastore_list_kinds (which lists kinds), though it doesn't explicitly name alternatives. The optional filter mention adds useful context.

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 like datastore_query or datastore_filter, nor does it mention prerequisites or exclusions. It implies usage for counting with optional filtering but lacks explicit context for selection among sibling tools.

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/johnreitano/daisy'

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