Skip to main content
Glama

search_nodes

Search for entities and their relations via text or vector similarity on the MCP server, leveraging libSQL for efficient semantic knowledge storage and retrieval.

Instructions

Search for entities and their relations using text or vector similarity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • MCP server tool handler for 'search_nodes': validates input, calls db.search_nodes(query, limit), returns JSON result or error.
    server.tool<typeof SearchNodesSchema>(
    	{
    		name: 'search_nodes',
    		description:
    			'Search for entities and their relations using text search with relevance ranking',
    		schema: SearchNodesSchema,
    	},
    	async ({ query, limit }) => {
    		try {
    			const result = await db.search_nodes(query, limit);
    			return {
    				content: [
    					{
    						type: 'text' as const,
    						text: JSON.stringify(result, null, 2),
    					},
    				],
    			};
    		} catch (error) {
    			return {
    				content: [
    					{
    						type: 'text' as const,
    						text: JSON.stringify(
    							{
    								error: 'internal_error',
    								message:
    									error instanceof Error
    										? error.message
    										: 'Unknown error',
    							},
    							null,
    							2,
    						),
    					},
    				],
    				isError: true,
    			};
    		}
    	},
  • Valibot schema definition for search_nodes tool input: query (required string), limit (optional number).
    const SearchNodesSchema = v.object({
    	query: v.string(),
    	limit: v.optional(v.number()),
    });
  • src/index.ts:102-141 (registration)
    Registration of 'search_nodes' tool on the MCP server within setupTools function.
    server.tool<typeof SearchNodesSchema>(
    	{
    		name: 'search_nodes',
    		description:
    			'Search for entities and their relations using text search with relevance ranking',
    		schema: SearchNodesSchema,
    	},
    	async ({ query, limit }) => {
    		try {
    			const result = await db.search_nodes(query, limit);
    			return {
    				content: [
    					{
    						type: 'text' as const,
    						text: JSON.stringify(result, null, 2),
    					},
    				],
    			};
    		} catch (error) {
    			return {
    				content: [
    					{
    						type: 'text' as const,
    						text: JSON.stringify(
    							{
    								error: 'internal_error',
    								message:
    									error instanceof Error
    										? error.message
    										: 'Unknown error',
    							},
    							null,
    							2,
    						),
    					},
    				],
    				isError: true,
    			};
    		}
    	},
  • DatabaseManager.search_nodes: core logic searches entities using text query with relevance, fetches associated relations.
    async search_nodes(
    	query: string,
    	limit?: number,
    ): Promise<{ entities: Entity[]; relations: Relation[] }> {
    	try {
    		// Validate text query
    		if (typeof query !== 'string') {
    			throw new Error('Text query must be a string');
    		}
    		if (query.trim() === '') {
    			throw new Error('Text query cannot be empty');
    		}
    
    		// Text-based search with optional limit
    		const entities = await this.search_entities(query, limit);
    
    		// If no entities found, return empty result
    		if (entities.length === 0) {
    			return { entities: [], relations: [] };
    		}
    
    		const relations = await this.get_relations_for_entities(
    			entities,
    		);
    		return { entities, relations };
    	} catch (error) {
    		throw new Error(
    			`Node search failed: ${
    				error instanceof Error ? error.message : String(error)
    			}`,
    		);
    	}
    }
  • DatabaseManager.search_entities: performs fuzzy text search on entities, types, observations with relevance scoring.
    async search_entities(
    	query: string,
    	limit: number = 10,
    ): Promise<Entity[]> {
    	// Normalize query for fuzzy matching
    	const normalized_query = `%${query.replace(/[\s_-]+/g, '%')}%`;
    
    	const results = await this.client.execute({
    		sql: `
           SELECT DISTINCT
             e.name,
             e.entity_type,
             e.created_at,
             CASE
               WHEN e.name LIKE ? COLLATE NOCASE THEN 3
               WHEN e.entity_type LIKE ? COLLATE NOCASE THEN 2
               ELSE 1
             END as relevance_score
           FROM entities e
           LEFT JOIN observations o ON e.name = o.entity_name
           WHERE e.name LIKE ? COLLATE NOCASE
              OR e.entity_type LIKE ? COLLATE NOCASE
              OR o.content LIKE ? COLLATE NOCASE
           ORDER BY relevance_score DESC, e.created_at DESC
           LIMIT ?
         `,
    		args: [
    			normalized_query,
    			normalized_query,
    			normalized_query,
    			normalized_query,
    			normalized_query,
    			limit > 50 ? 50 : limit, // Cap at 50
    		],
    	});
    
    	const entities: Entity[] = [];
    	for (const row of results.rows) {
    		const name = row.name as string;
    		const observations = await this.client.execute({
    			sql: 'SELECT content FROM observations WHERE entity_name = ?',
    			args: [name],
    		});
    
    		entities.push({
    			name,
    			entityType: row.entity_type as string,
    			observations: observations.rows.map(
    				(obs) => obs.content as string,
    			),
    		});
    	}
    
    	return entities;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While it mentions the search functionality, it doesn't describe what happens during execution - whether it's read-only or has side effects, what permissions are required, how results are returned, or any rate limits. The description is too minimal for a search tool with no annotation support.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single sentence that directly states the tool's function. There's no wasted language or unnecessary elaboration. It's front-loaded with the core purpose and uses efficient phrasing.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a search tool with no annotations, no output schema, and minimal parameter documentation, the description is insufficient. It doesn't explain what 'entities and relations' mean in this context, how results are structured, whether there are pagination or filtering options, or any operational constraints. The description leaves too many questions unanswered for effective tool use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'text or vector similarity' which aligns with the schema's oneOf structure for the query parameter. However, with 0% schema description coverage, the description doesn't add meaningful details about parameter usage, format requirements, or search behavior. It provides basic context but doesn't compensate for the complete lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as searching for entities and their relations using text or vector similarity. It specifies both the resource (entities and relations) and the method (text or vector similarity search). However, it doesn't explicitly differentiate from sibling tools like 'read_graph' which might also involve reading/searching operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when this search tool should be used instead of 'read_graph' or other siblings, nor does it provide any context about prerequisites, limitations, or appropriate scenarios for text versus vector search.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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/spences10/mcp-memory-libsql'

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