Skip to main content
Glama
devlimelabs

Meilisearch MCP Server

by devlimelabs

vector-search

Search Meilisearch indexes using vector embeddings to find semantically similar content, supporting hybrid text-vector searches and customizable filtering.

Instructions

Perform a vector search in a Meilisearch index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexUidYesUnique identifier of the index
vectorYesJSON array representing the vector to search for
limitNoMaximum number of results to return (default: 20)
offsetNoNumber of results to skip (default: 0)
filterNoFilter to apply (e.g., 'genre = horror AND year > 2020')
embedderNoName of the embedder to use (if omitted, a 'vector' must be provided)
attributesNoAttributes to include in the vector search
queryNoText query to search for (if using 'embedder' instead of 'vector')
hybridNoWhether to perform a hybrid search (combining vector and text search)
hybridRatioNoRatio of vector vs text search in hybrid search (0-1, default: 0.5)

Implementation Reference

  • The async handler function that performs the vector search by parsing inputs, validating requirements (vector or embedder+query), building search parameters, and POSTing to Meilisearch's /indexes/{indexUid}/search endpoint.
    async ({ indexUid, vector, limit, offset, filter, embedder, attributes, query, hybrid, hybridRatio }) => {
      try {
        const searchParams: Record<string, any> = {};
        
        // Add required vector parameter
        if (vector) {
          try {
            searchParams.vector = JSON.parse(vector);
          } catch (parseError) {
            return {
              isError: true,
              content: [{ type: "text", text: "Vector must be a valid JSON array" }],
            };
          }
        }
        
        // Add embedder parameters
        if (embedder) {
          searchParams.embedder = embedder;
          
          if (query !== undefined) {
            searchParams.q = query;
          }
        }
        
        // Ensure we have either vector or (embedder + query)
        if (!vector && (!embedder || query === undefined)) {
          return {
            isError: true,
            content: [{ type: "text", text: "Either 'vector' or both 'embedder' and 'query' must be provided" }],
          };
        }
        
        // Add optional parameters
        if (limit !== undefined) searchParams.limit = limit;
        if (offset !== undefined) searchParams.offset = offset;
        if (filter) searchParams.filter = filter;
        if (attributes?.length) searchParams.attributes = attributes;
        if (hybrid !== undefined) searchParams.hybrid = hybrid;
        if (hybridRatio !== undefined) searchParams.hybridRatio = hybridRatio;
        
        const response = await apiClient.post(`/indexes/${indexUid}/search`, searchParams);
        return {
          content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }],
        };
      } catch (error) {
        return createErrorResponse(error);
      }
    }
  • Zod schema defining the input parameters for the vector-search tool.
    {
      indexUid: z.string().describe("Unique identifier of the index"),
      vector: z.string().describe("JSON array representing the vector to search for"),
      limit: z.number().min(1).max(1000).optional().describe("Maximum number of results to return (default: 20)"),
      offset: z.number().min(0).optional().describe("Number of results to skip (default: 0)"),
      filter: z.string().optional().describe("Filter to apply (e.g., 'genre = horror AND year > 2020')"),
      embedder: z.string().optional().describe("Name of the embedder to use (if omitted, a 'vector' must be provided)"),
      attributes: z.array(z.string()).optional().describe("Attributes to include in the vector search"),
      query: z.string().optional().describe("Text query to search for (if using 'embedder' instead of 'vector')"),
      hybrid: z.boolean().optional().describe("Whether to perform a hybrid search (combining vector and text search)"),
      hybridRatio: z.number().min(0).max(1).optional().describe("Ratio of vector vs text search in hybrid search (0-1, default: 0.5)"),
    },
  • Direct registration of the 'vector-search' tool on the MCP server using server.tool(), including description, input schema, and handler.
    server.tool(
      "vector-search",
      "Perform a vector search in a Meilisearch index",
      {
        indexUid: z.string().describe("Unique identifier of the index"),
        vector: z.string().describe("JSON array representing the vector to search for"),
        limit: z.number().min(1).max(1000).optional().describe("Maximum number of results to return (default: 20)"),
        offset: z.number().min(0).optional().describe("Number of results to skip (default: 0)"),
        filter: z.string().optional().describe("Filter to apply (e.g., 'genre = horror AND year > 2020')"),
        embedder: z.string().optional().describe("Name of the embedder to use (if omitted, a 'vector' must be provided)"),
        attributes: z.array(z.string()).optional().describe("Attributes to include in the vector search"),
        query: z.string().optional().describe("Text query to search for (if using 'embedder' instead of 'vector')"),
        hybrid: z.boolean().optional().describe("Whether to perform a hybrid search (combining vector and text search)"),
        hybridRatio: z.number().min(0).max(1).optional().describe("Ratio of vector vs text search in hybrid search (0-1, default: 0.5)"),
      },
      async ({ indexUid, vector, limit, offset, filter, embedder, attributes, query, hybrid, hybridRatio }) => {
        try {
          const searchParams: Record<string, any> = {};
          
          // Add required vector parameter
          if (vector) {
            try {
              searchParams.vector = JSON.parse(vector);
            } catch (parseError) {
              return {
                isError: true,
                content: [{ type: "text", text: "Vector must be a valid JSON array" }],
              };
            }
          }
          
          // Add embedder parameters
          if (embedder) {
            searchParams.embedder = embedder;
            
            if (query !== undefined) {
              searchParams.q = query;
            }
          }
          
          // Ensure we have either vector or (embedder + query)
          if (!vector && (!embedder || query === undefined)) {
            return {
              isError: true,
              content: [{ type: "text", text: "Either 'vector' or both 'embedder' and 'query' must be provided" }],
            };
          }
          
          // Add optional parameters
          if (limit !== undefined) searchParams.limit = limit;
          if (offset !== undefined) searchParams.offset = offset;
          if (filter) searchParams.filter = filter;
          if (attributes?.length) searchParams.attributes = attributes;
          if (hybrid !== undefined) searchParams.hybrid = hybrid;
          if (hybridRatio !== undefined) searchParams.hybridRatio = hybridRatio;
          
          const response = await apiClient.post(`/indexes/${indexUid}/search`, searchParams);
          return {
            content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }],
          };
        } catch (error) {
          return createErrorResponse(error);
        }
      }
    );
  • src/index.ts:68-68 (registration)
    Registers the vector tools module (including vector-search) on the main MCP server instance.
    registerVectorTools(server);

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/devlimelabs/meilisearch-ts-mcp'

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