search_nodes
Query nodes in the MCP Memory Server's knowledge graph to match entity names, types, and observation content, enabling precise information retrieval for LLMs.
Instructions
Search for nodes in the knowledge graph based on a query
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query to match against entity names, types, and observation content |
Input Schema (JSON Schema)
{
"properties": {
"query": {
"description": "The search query to match against entity names, types, and observation content",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- src/index.ts:137-161 (handler)Implementation of the searchNodes method in KnowledgeGraphManager class, which filters entities matching the query in name, type, or observations, and includes relations between matching entities.async searchNodes(query: string): Promise<KnowledgeGraph> { const graph = await this.loadGraph(); // Filter entities const filteredEntities = graph.entities.filter(e => e.name.toLowerCase().includes(query.toLowerCase()) || e.entityType.toLowerCase().includes(query.toLowerCase()) || e.observations.some(o => o.toLowerCase().includes(query.toLowerCase())) ); // Create a Set of filtered entity names for quick lookup const filteredEntityNames = new Set(filteredEntities.map(e => e.name)); // Filter relations to only include those between filtered entities const filteredRelations = graph.relations.filter(r => filteredEntityNames.has(r.from) && filteredEntityNames.has(r.to) ); const filteredGraph: KnowledgeGraph = { entities: filteredEntities, relations: filteredRelations, }; return filteredGraph; }
- src/index.ts:349-355 (schema)Input schema definition for the search_nodes tool, specifying a required 'query' string parameter.inputSchema: { type: "object", properties: { query: { type: "string", description: "The search query to match against entity names, types, and observation content" }, }, required: ["query"], },
- src/index.ts:347-356 (registration)Registration of the search_nodes tool in the listTools response, including name, description, and input schema.name: "search_nodes", description: "Search for nodes in the knowledge graph based on a query", inputSchema: { type: "object", properties: { query: { type: "string", description: "The search query to match against entity names, types, and observation content" }, }, required: ["query"], }, },
- src/index.ts:401-402 (handler)Dispatcher case in the CallToolRequestSchema handler that invokes the searchNodes method with the provided query argument.case "search_nodes": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.searchNodes(args.query as string), null, 2) }] };