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
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) |
Input Schema (JSON Schema)
{
"properties": {
"key": {
"description": "The entity key (name or ID)",
"type": "string"
},
"kind": {
"description": "The entity kind",
"type": "string"
},
"parent": {
"description": "Parent key if the entity has a parent (optional)",
"type": "string"
}
},
"required": [
"kind",
"key"
],
"type": "object"
}
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', }, ], };