read_graph
Retrieve recent entities and their relationships stored in MCP Memory LibSQL, with optional embeddings for advanced analysis and vector search.
Instructions
Get recent entities and their relations
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeEmbeddings | No | Whether to include embeddings in the returned entities (default: false) |
Input Schema (JSON Schema)
{
"properties": {
"includeEmbeddings": {
"description": "Whether to include embeddings in the returned entities (default: false)",
"type": "boolean"
}
},
"required": [],
"type": "object"
}
Implementation Reference
- src/services/graph-service.ts:19-51 (handler)Core handler function that implements the logic to read recent entities and their relations from the database to form a graph.public static async readGraph( limit = 10, includeEmbeddings = false, ): Promise<GraphResult> { try { // Get recent entities const recentEntities = await getRecentEntities(limit, includeEmbeddings); // If no entities found, return empty graph if (!recentEntities || recentEntities.length === 0) { return { entities: [], relations: [], }; } // Get entity names const entityNames = recentEntities.map((entity: Entity) => entity.name); // Get relations for these entities const relations = await getRelationsForEntities(entityNames); // Return graph result return { entities: recentEntities, relations, }; } catch (error) { throw new DatabaseError( `Failed to read graph: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:356-370 (handler)MCP server tool handler for 'read_graph' that parses input, calls the readGraph service function, and formats the response.case 'read_graph': { // Safely access properties with type assertions const includeEmbeddings = args.includeEmbeddings as boolean || false; // Use a fixed limit of 10 for the number of entities to return const result = await readGraph(10, includeEmbeddings); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:171-183 (registration)Registration of the 'read_graph' tool in the MCP server's listTools response, including name, description, and input schema.name: 'read_graph', description: 'Get recent entities and their relations', inputSchema: { type: 'object', properties: { includeEmbeddings: { type: 'boolean', description: 'Whether to include embeddings in the returned entities (default: false)', }, }, required: [], }, },
- src/index.ts:286-288 (schema)TypeScript interface defining the input schema for the read_graph tool.interface ReadGraphInput { includeEmbeddings?: boolean; }