get_recent
Retrieve recently accessed entities and their relations from the Elasticsearch Knowledge Graph for MCP, with options to limit results and include detailed observations, supporting efficient memory-based queries.
Instructions
Get recently accessed entities from knowledge graph (memory) and their relations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeObservations | No | Whether to include full entity observations in results (default: false) | |
| limit | No | Max results (default: 20 if includeObservations is false, 5 if true) | |
| memory_zone | Yes | Optional memory zone to get recent entities from. If not specified, uses the default zone. |
Implementation Reference
- src/index.ts:447-471 (registration)Registration of the get_recent tool in the listTools response, including name, description, and input schema.{ name: "get_recent", description: "Get recently accessed entities from knowledge graph (memory) and their relations", inputSchema: { type: "object", properties: { limit: { type: "integer", description: "Max results (default: 20 if includeObservations is false, 5 if true)" }, includeObservations: { type: "boolean", description: "Whether to include full entity observations in results (default: false)", default: false }, memory_zone: { type: "string", description: "Optional memory zone to get recent entities from. If not specified, uses the default zone." } }, required: ["memory_zone"], additionalProperties: false, "$schema": "http://json-schema.org/draft-07/schema#" } },
- src/index.ts:1082-1097 (handler)Handler for executing the get_recent tool call, parses arguments, invokes kgClient.getRecentEntities, and formats response.else if (toolName === "get_recent") { const limit = params.limit || 20; const includeObservations = params.includeObservations ?? false; const zone = params.memory_zone; const recentEntities = await kgClient.getRecentEntities(limit, includeObservations, zone); return formatResponse({ entities: recentEntities.map(e => ({ name: e.name, entityType: e.entityType, observations: e.observations })), total: recentEntities.length }); }
- src/kg-client.ts:1836-1858 (helper)Helper method getRecentEntities in KnowledgeGraphClient that implements the core logic by searching all entities sorted by lastRead timestamp (recency).async getRecentEntities(limit: number, includeObservations: boolean, zone?: string): Promise<ESEntity[]> { const actualZone = zone || this.defaultZone; // Search with empty query but sort by recency const searchParams: ESSearchParams = { query: "*", // Use wildcard instead of empty query to match all documents limit: limit, sortBy: 'recent', // Sort by recency includeObservations }; // Add zone if specified if (actualZone) { (searchParams as any).zone = actualZone; } const results = await this.search(searchParams); // Filter to only include entities return results.hits.hits .filter((hit: any) => hit._source.type === 'entity') .map((hit: any) => hit._source); }