Skip to main content
Glama

Knowledge Graph Memory Server

search_nodes

Find nodes in the knowledge graph by matching names, types, or content with your search query, enabling precise information retrieval across chats.

Instructions

Search for nodes in the knowledge graph based on a query

Input Schema

NameRequiredDescriptionDefault
queryYesThe 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

  • Core handler function implementing the search_nodes tool logic in KnowledgeGraphManager. Filters knowledge graph entities matching the query in name, type, or observations (case-insensitive), and includes relations connecting those 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; }
  • Registration of the search_nodes MCP tool, including schema definition and thin wrapper handler that invokes the core searchNodes method and formats the output.
    server.registerTool( "search_nodes", { title: "Search Nodes", description: "Search for nodes in the knowledge graph based on a query", inputSchema: { query: z.string().describe("The search query to match against entity names, types, and observation content") }, outputSchema: { entities: z.array(EntitySchema), relations: z.array(RelationSchema) } }, async ({ query }) => { const graph = await knowledgeGraphManager.searchNodes(query); return { content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }], structuredContent: { ...graph } }; } );
  • Schema for search_nodes tool: input is a query string, output is a KnowledgeGraph with arrays of entities and relations using shared EntitySchema and RelationSchema.
    { title: "Search Nodes", description: "Search for nodes in the knowledge graph based on a query", inputSchema: { query: z.string().describe("The search query to match against entity names, types, and observation content") }, outputSchema: { entities: z.array(EntitySchema), relations: z.array(RelationSchema) } },

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/modelcontextprotocol/knowledge-graph-memory-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server