datastore_filter
Filter entities stored in Google Cloud Datastore by exact field matches. Specify kind, field, and value to retrieve filtered results efficiently.
Instructions
Query entities with a simple equality filter on any field
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| field | Yes | The field name to filter on (can be key field or property) | |
| kind | Yes | The entity kind to query | |
| limit | No | Maximum number of results to return (default: 100) | |
| value | Yes | The value to match exactly |
Input Schema (JSON Schema)
{
"properties": {
"field": {
"description": "The field name to filter on (can be key field or property)",
"type": "string"
},
"kind": {
"description": "The entity kind to query",
"type": "string"
},
"limit": {
"description": "Maximum number of results to return (default: 100)",
"type": "number"
},
"value": {
"description": "The value to match exactly",
"type": "string"
}
},
"required": [
"kind",
"field",
"value"
],
"type": "object"
}
Implementation Reference
- src/datastore.ts:68-92 (handler)Core implementation of the datastore_filter tool: creates a Google Cloud Datastore query filtered by the specified field and value, applies limit, and maps results to include keys.async filterEntities(kind: string, field: string, value: string, limit = 100): Promise<any[]> { try { let query = this.datastore.createQuery(kind); 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); } query = query.limit(limit); const [entities] = await this.datastore.runQuery(query); return entities.map(entity => ({ key: entity[this.datastore.KEY], ...entity, })); } catch (error) { throw new Error(`Failed to filter entities: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
- src/index.ts:80-105 (schema)Input schema definition for the datastore_filter tool, including parameters kind, field, value (required), and optional limit.{ name: 'datastore_filter', description: 'Query entities with a simple equality filter on any field', inputSchema: { type: 'object', properties: { kind: { type: 'string', description: 'The entity kind to query', }, field: { type: 'string', description: 'The field name to filter on (can be key field or property)', }, value: { type: 'string', description: 'The value to match exactly', }, limit: { type: 'number', description: 'Maximum number of results to return (default: 100)', }, }, required: ['kind', 'field', 'value'], }, },
- src/index.ts:181-195 (handler)Handler case in the CallToolRequestHandler that invokes the DatastoreClient.filterEntities method and formats the response as text content.case 'datastore_filter': const filteredResults = await datastoreClient.filterEntities( args.kind as string, args.field as string, args.value as string, args.limit as number | undefined ); return { content: [ { type: 'text', text: JSON.stringify(filteredResults, null, 2), }, ], };
- src/datastore.ts:116-126 (helper)Helper method used in filterEntities to convert string input value to appropriate type (boolean, number, null, or string) for Datastore filter.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; } }