datastore_query
Execute queries on Google Cloud Datastore entities with optional filters, pagination, and equality conditions to retrieve specific data sets efficiently.
Instructions
Execute a query on entities with optional filters
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kind | Yes | The entity kind to query | |
| limit | No | Maximum number of results to return (default: 100) | |
| offset | No | Number of results to skip (default: 0) |
Input Schema (JSON Schema)
{
"properties": {
"kind": {
"description": "The entity kind to query",
"type": "string"
},
"limit": {
"description": "Maximum number of results to return (default: 100)",
"type": "number"
},
"offset": {
"description": "Number of results to skip (default: 0)",
"type": "number"
}
},
"required": [
"kind"
],
"type": "object"
}
Implementation Reference
- src/datastore.ts:51-66 (handler)The main handler function that executes the datastore_query tool logic, creating and running a Google Cloud Datastore query for the given kind with optional limit and offset.async queryEntities(kind: string, limit = 100, offset = 0): Promise<any[]> { try { const query = this.datastore.createQuery(kind) .limit(limit) .offset(offset); const [entities] = await this.datastore.runQuery(query); return entities.map(entity => ({ key: entity[this.datastore.KEY], ...entity, })); } catch (error) { throw new Error(`Failed to query entities: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
- src/index.ts:58-79 (schema)Input schema and metadata definition for the datastore_query tool, used in ListTools response.{ name: 'datastore_query', description: 'Execute a query on entities with optional filters', inputSchema: { type: 'object', properties: { kind: { type: 'string', description: 'The entity kind to query', }, limit: { type: 'number', description: 'Maximum number of results to return (default: 100)', }, offset: { type: 'number', description: 'Number of results to skip (default: 0)', }, }, required: ['kind'], }, },
- src/index.ts:166-179 (registration)Dispatches the CallToolRequest for datastore_query to the queryEntities handler and formats the response.case 'datastore_query': const results = await datastoreClient.queryEntities( args.kind as string, args.limit as number | undefined, args.offset as number | undefined ); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], };