Skip to main content
Glama
wrediam

Better Qdrant MCP Server

search

Find similar documents in a specified collection using semantic search. Input a query, choose an embedding service, and retrieve relevant results for efficient information discovery.

Instructions

Search for similar documents in a collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesName of the collection to search in
embeddingServiceYesEmbedding service to use
limitNoMaximum number of results to return (optional)
queryYesSearch query

Implementation Reference

  • The primary handler for the 'search' tool. Embeds the query using the specified embedding service, performs vector search in Qdrant via qdrantService.search, formats and returns the top results.
    private async handleSearch(args: SearchArgs) {
      try {
        // Create embedding service
        const embeddingService = createEmbeddingService({
          type: args.embeddingService,
          apiKey: process.env[`${args.embeddingService.toUpperCase()}_API_KEY`],
          endpoint: process.env[`${args.embeddingService.toUpperCase()}_ENDPOINT`],
        });
    
        // Generate query embedding
        const [queryEmbedding] = await embeddingService.generateEmbeddings([args.query]);
    
        // Search collection
        const results = await this.qdrantService.search(
          args.collection,
          queryEmbedding,
          args.limit
        );
    
        // Format the results to only include the payload text
        let responseText = '';
        
        results.forEach((result, index) => {
          // For documents collection, the text is in result.payload.text
          // For other collections, it might be in different fields
          const text = result.payload.text || result.payload.content || JSON.stringify(result.payload);
          const source = result.payload.source || result.payload.metadata?.source || '';
          const score = result.score.toFixed(2);
          
          responseText += `Result ${index + 1} (Score: ${score}):\n${text}\n`;
          if (source) {
            responseText += `Source: ${source}\n`;
          }
          responseText += '\n';
        });
        
        if (responseText === '') {
          responseText = 'No results found.';
        }
    
        return {
          content: [
            {
              type: 'text',
              text: responseText,
            },
          ],
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: 'text',
              text: `Error searching: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
  • src/index.ts:148-174 (registration)
    Registration of the 'search' tool in the ListTools response, including name, description, and input schema.
    {
      name: 'search',
      description: 'Search for similar documents in a collection',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Search query',
          },
          collection: {
            type: 'string',
            description: 'Name of the collection to search in',
          },
          embeddingService: {
            type: 'string',
            enum: ['openai', 'openrouter', 'fastembed', 'ollama'],
            description: 'Embedding service to use',
          },
          limit: {
            type: 'number',
            description: 'Maximum number of results to return (optional)',
          },
        },
        required: ['query', 'collection', 'embeddingService'],
      },
    },
  • JSON input schema defining the parameters for the 'search' tool: query (string), collection (string), embeddingService (enum), limit (number optional).
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: 'Search query',
        },
        collection: {
          type: 'string',
          description: 'Name of the collection to search in',
        },
        embeddingService: {
          type: 'string',
          enum: ['openai', 'openrouter', 'fastembed', 'ollama'],
          description: 'Embedding service to use',
        },
        limit: {
          type: 'number',
          description: 'Maximum number of results to return (optional)',
        },
      },
      required: ['query', 'collection', 'embeddingService'],
    },
  • QdrantService.search method: Performs POST to /points/search endpoint with vector query, retrieves results with payload and vector, maps to SearchResult objects.
    async search(
      collection: string,
      vector: number[],
      limit: number = 10
    ): Promise<SearchResult[]> {
      try {
        console.log('Attempting to search Qdrant collection using direct fetch...');
        
        // Use direct fetch instead of the client
        const searchUrl = `${this.url}/collections/${collection}/points/search`;
        console.log(`Fetching from: ${searchUrl}`);
        
        const response = await fetch(searchUrl, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            ...(this.apiKey ? { 'api-key': this.apiKey } : {})
          },
          // @ts-ignore - node-fetch supports timeout
          timeout: 5000, // 5 second timeout
          body: JSON.stringify({
            vector,
            limit,
            with_payload: true,
            with_vector: true
          })
        });
        
        if (!response.ok) {
          throw new Error(`HTTP error! Status: ${response.status}`);
        }
        
        const data = await response.json() as { 
          result: Array<{
            id: string;
            score: number;
            payload: Record<string, any>;
            vector?: number[];
          }> 
        };
        
        console.log('Successfully retrieved search results:', data);
        
        return data.result.map(result => {
          const searchResult: SearchResult = {
            id: result.id,
            score: result.score,
            payload: result.payload,
          };
          
          // Only include vector if it's a number array
          if (Array.isArray(result.vector) && result.vector.every(v => typeof v === 'number')) {
            searchResult.vector = result.vector;
          }
          
          return searchResult;
        });
      } catch (error) {
        console.error('Error in search:', error);
        if (error instanceof Error) {
          console.error(`${error.name}: ${error.message}`);
          console.error('Stack:', error.stack);
        }
        throw error;
      }
    }
  • TypeScript interface defining the structure of search results returned by Qdrant search.
    export interface SearchResult {
      id: string;
      score: number;
      payload: Record<string, any>;
      vector?: number[];
    }
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. It mentions 'similar documents' but doesn't explain how similarity is determined (e.g., via embeddings), what the output looks like (e.g., relevance scores), or any constraints like rate limits or authentication needs. This leaves significant gaps for a search tool with multiple parameters.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to grasp quickly, which is ideal for conciseness.

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?

Given the complexity of a search tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It fails to explain key aspects like the search mechanism (embedding-based), expected output format, or error conditions. This leaves the agent with insufficient context to use the tool effectively beyond basic parameter input.

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 schema description coverage is 100%, so the schema already documents all parameters well. The description adds no additional meaning beyond what's in the schema, such as explaining the relationship between query and embeddingService or how limit affects results. This meets the baseline for high schema coverage but doesn't enhance understanding.

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

Purpose3/5

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

The description states the tool's purpose as 'Search for similar documents in a collection', which clearly indicates a search operation. However, it's vague about what 'similar' means (e.g., semantic similarity via embeddings) and doesn't distinguish from siblings like list_collections, which might also involve collections but for listing rather than searching. It's adequate but lacks specificity.

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. For example, it doesn't clarify if this is for semantic search (implied by embeddingService) versus other search methods, or how it relates to siblings like add_documents or list_collections. There's no mention of prerequisites, such as needing an existing collection, leaving usage context unclear.

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/wrediam/better-qdrant-mcp-server'

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