Skip to main content
Glama

Search Vectors

search-vectors

Find files and code snippets using natural language queries in your project directory with semantic vector search.

Instructions

Search for files and code snippets using natural language queries

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNatural language search query
pathNoProject path to search (defaults to current directory)
providerNoEmbedding provider to use (defaults to configured provider)
limitNoMaximum number of results
similarityThresholdNoMinimum similarity score (0-1)
filesOnlyNoReturn only file paths without chunks

Implementation Reference

  • The main handler function that executes the 'search-vectors' tool logic. It validates input, checks for indexed vectors, gets embedding provider, and calls either getRelatedFiles or searchVectors based on filesOnly flag, then formats the results.
    export async function handleSearchVectors(args: SearchVectorsInput): Promise<string> {
      const configManager = new ConfigManager();
    
      logger.log('Searching vectors...');
    
      try {
        // Check if project is indexed
        const vectorCount = await getVectorCount(args.path);
        if (vectorCount === 0) {
          return 'No vectors found. Please run index-vectors first.';
        }
    
        // Get embedding provider
        let provider: EmbeddingProvider;
        if (args.provider) {
          provider = new EmbeddingProvider({ provider: args.provider }, configManager);
        } else {
          provider = await getDefaultEmbeddingProvider(configManager);
        }
    
        if (args.filesOnly) {
          // Get related files only
          const files = await getRelatedFiles({
            projectPath: args.path,
            query: args.query,
            provider,
            limit: args.limit,
            similarityThreshold: args.similarityThreshold,
          });
    
          if (files.length === 0) {
            return 'No matching files found.';
          }
    
          return `Found ${files.length} related files:\n\n${files.map(f => `- ${f}`).join('\n')}`;
        } else {
          // Get full search results with chunks
          const results = await searchVectors({
            projectPath: args.path,
            query: args.query,
            provider,
            limit: args.limit,
            similarityThreshold: args.similarityThreshold,
          });
    
          if (results.length === 0) {
            return 'No matching results found.';
          }
    
          const formatted = results.map((result, index) => {
            const preview = result.chunk.slice(0, 200).replace(/\n/g, ' ');
            return `${index + 1}. ${result.relpath}
       Similarity: ${(result.similarity * 100).toFixed(1)}%
       Chunk ID: ${result.chunkId}
       Preview: ${preview}${result.chunk.length > 200 ? '...' : ''}`;
          }).join('\n\n');
    
          return `Found ${results.length} matches:\n\n${formatted}`;
        }
      } catch (error) {
        logger.error('Vector search failed:', error);
        throw new Error(`Search failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Zod schema defining the input parameters for the search-vectors tool, used for validation.
    // Input schema for search-vectors tool
    export const SearchVectorsSchema = z.object({
      query: z.string(),
      path: z.string().default(process.cwd()),
      provider: z.enum(['openai', 'azure', 'gemini']).optional(),
      limit: z.number().min(1).max(50).default(10),
      similarityThreshold: z.number().min(0).max(1).default(0.7),
      filesOnly: z.boolean().default(false),
    });
  • src/server.ts:467-489 (registration)
    Registration of the 'search-vectors' tool on the MCP server, dynamically importing and calling the handler function.
    server.registerTool("search-vectors", {
      title: "Search Vectors",
      description: "Search for files and code snippets using natural language queries",
      inputSchema: SearchVectorsSchema.shape,
    }, async (args) => {
      const { handleSearchVectors } = await import("./handlers/vector");
      const result = await handleSearchVectors({
        query: args.query,
        path: args.path || process.cwd(),
        provider: args.provider,
        limit: args.limit || 10,
        similarityThreshold: args.similarityThreshold || 0.7,
        filesOnly: args.filesOnly || false,
      });
      return {
        content: [
          {
            type: "text",
            text: result
          }
        ]
      };
    });
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It mentions the search functionality but doesn't describe what happens during execution (e.g., does it modify data, require authentication, have rate limits, or return structured results?). For a search tool with no annotation coverage, this leaves significant behavioral aspects undocumented.

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 a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a search tool and front-loads the core functionality without unnecessary elaboration.

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

Completeness3/5

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

Given the tool's moderate complexity (6 parameters, no output schema, no annotations), the description is minimally adequate. It states the purpose clearly but lacks behavioral context, usage guidelines, and output information. With no annotations to supplement, this leaves gaps in understanding how the tool behaves and when to use it.

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?

Schema description coverage is 100%, so the schema fully documents all 6 parameters. The description doesn't add any parameter-specific information beyond what's in the schema (e.g., it doesn't explain how 'natural language queries' map to the 'query' parameter or provide examples). Baseline 3 is appropriate when the schema does all the parameter documentation work.

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: 'Search for files and code snippets using natural language queries'. It specifies the verb ('Search'), resource ('files and code snippets'), and method ('natural language queries'). However, it doesn't differentiate from sibling tools like 'analyze-code' or 'investigate' which might also involve searching or examining code.

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. With many sibling tools like 'analyze-code', 'investigate', and 'research', there's no indication of this tool's specific context or prerequisites. It simply states what it does without any usage boundaries.

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

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/RealMikeChong/ultra-mcp'

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