datastore_get
Retrieve a specific entity from Google Cloud Datastore using its key and kind, with optional parent key for hierarchical data structures.
Instructions
Get an entity by its key
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"kind": "<kind>",
"key": "<key>"
},
"name": "datastore_get"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The entity key (name or ID) | |
| kind | Yes | The entity kind | |
| parent | No | Parent key if the entity has a parent (optional) |
Implementation Reference
- src/datastore.ts:24-49 (handler)Core implementation of the datastore_get tool logic: retrieves an entity from Google Cloud Datastore by constructing the key (handling numeric/ID or string name, optional parent) and fetching it.
async getEntity(kind: string, key: string, parent?: string): Promise<any> { try { let entityKey; const keyValue = isNaN(Number(key)) ? key : parseInt(key); if (parent) { const parentKeyValue = isNaN(Number(parent)) ? parent : parseInt(parent); entityKey = this.datastore.key([kind, parentKeyValue, kind, keyValue]); } else { entityKey = this.datastore.key([kind, keyValue]); } const [entity] = await this.datastore.get(entityKey); if (!entity) { return null; } return { key: entity[this.datastore.KEY], ...entity, }; } catch (error) { throw new Error(`Failed to get entity: ${error instanceof Error ? error.message : 'Unknown error'}`); } } - src/index.ts:39-56 (schema)Input schema for the datastore_get tool defining required 'kind' and 'key' parameters, optional 'parent'.
inputSchema: { type: 'object', properties: { kind: { type: 'string', description: 'The entity kind', }, key: { type: 'string', description: 'The entity key (name or ID)', }, parent: { type: 'string', description: 'Parent key if the entity has a parent (optional)', }, }, required: ['kind', 'key'], }, - src/index.ts:36-57 (registration)Registration of the datastore_get tool in the MCP listTools response.
{ name: 'datastore_get', description: 'Get an entity by its key', inputSchema: { type: 'object', properties: { kind: { type: 'string', description: 'The entity kind', }, key: { type: 'string', description: 'The entity key (name or ID)', }, parent: { type: 'string', description: 'Parent key if the entity has a parent (optional)', }, }, required: ['kind', 'key'], }, }, - src/index.ts:151-164 (handler)MCP callTool handler case for datastore_get: calls DatastoreClient.getEntity and returns text response with JSON or not found message.
case 'datastore_get': const entity = await datastoreClient.getEntity( args.kind as string, args.key as string, args.parent as string | undefined ); return { content: [ { type: 'text', text: entity ? JSON.stringify(entity, null, 2) : 'Entity not found', }, ], };