search
Find documents in a Meilisearch index using queries, filters, sorting, and highlighting to retrieve relevant information.
Instructions
Search for documents in a Meilisearch index
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| indexUid | Yes | Unique identifier of the index | |
| q | Yes | Search query | |
| limit | No | Maximum number of results to return (default: 20) | |
| offset | No | Number of results to skip (default: 0) | |
| filter | No | Filter query to apply | |
| sort | No | Attributes to sort by, e.g. ["price:asc"] | |
| facets | No | Facets to return | |
| attributesToRetrieve | No | Attributes to include in results | |
| attributesToCrop | No | Attributes to crop | |
| cropLength | No | Length at which to crop cropped attributes | |
| attributesToHighlight | No | Attributes to highlight | |
| highlightPreTag | No | Tag to insert before highlighted text | |
| highlightPostTag | No | Tag to insert after highlighted text | |
| showMatchesPosition | No | Whether to include match positions in results | |
| matchingStrategy | No | Matching strategy: 'all' or 'last' |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"attributesToCrop": {
"description": "Attributes to crop",
"items": {
"type": "string"
},
"type": "array"
},
"attributesToHighlight": {
"description": "Attributes to highlight",
"items": {
"type": "string"
},
"type": "array"
},
"attributesToRetrieve": {
"description": "Attributes to include in results",
"items": {
"type": "string"
},
"type": "array"
},
"cropLength": {
"description": "Length at which to crop cropped attributes",
"type": "number"
},
"facets": {
"description": "Facets to return",
"items": {
"type": "string"
},
"type": "array"
},
"filter": {
"description": "Filter query to apply",
"type": "string"
},
"highlightPostTag": {
"description": "Tag to insert after highlighted text",
"type": "string"
},
"highlightPreTag": {
"description": "Tag to insert before highlighted text",
"type": "string"
},
"indexUid": {
"description": "Unique identifier of the index",
"type": "string"
},
"limit": {
"description": "Maximum number of results to return (default: 20)",
"maximum": 1000,
"minimum": 1,
"type": "number"
},
"matchingStrategy": {
"description": "Matching strategy: 'all' or 'last'",
"type": "string"
},
"offset": {
"description": "Number of results to skip (default: 0)",
"minimum": 0,
"type": "number"
},
"q": {
"description": "Search query",
"type": "string"
},
"showMatchesPosition": {
"description": "Whether to include match positions in results",
"type": "boolean"
},
"sort": {
"description": "Attributes to sort by, e.g. [\"price:asc\"]",
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"indexUid",
"q"
],
"type": "object"
}
Implementation Reference
- src/tools/search-tools.ts:63-103 (handler)Handler function that performs the search request to Meilisearch API and returns the results or error response.async ({ indexUid, q, limit, offset, filter, sort, facets, attributesToRetrieve, attributesToCrop, cropLength, attributesToHighlight, highlightPreTag, highlightPostTag, showMatchesPosition, matchingStrategy }: SearchParams) => { try { const response = await apiClient.post(`/indexes/${indexUid}/search`, { q, limit, offset, filter, sort, facets, attributesToRetrieve, attributesToCrop, cropLength, attributesToHighlight, highlightPreTag, highlightPostTag, showMatchesPosition, matchingStrategy, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } }
- src/tools/search-tools.ts:46-62 (schema)Zod input schema defining all parameters for the search tool call.{ indexUid: z.string().describe('Unique identifier of the index'), q: z.string().describe('Search query'), 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 query to apply'), sort: z.array(z.string()).optional().describe('Attributes to sort by, e.g. ["price:asc"]'), facets: z.array(z.string()).optional().describe('Facets to return'), attributesToRetrieve: z.array(z.string()).optional().describe('Attributes to include in results'), attributesToCrop: z.array(z.string()).optional().describe('Attributes to crop'), cropLength: z.number().optional().describe('Length at which to crop cropped attributes'), attributesToHighlight: z.array(z.string()).optional().describe('Attributes to highlight'), highlightPreTag: z.string().optional().describe('Tag to insert before highlighted text'), highlightPostTag: z.string().optional().describe('Tag to insert after highlighted text'), showMatchesPosition: z.boolean().optional().describe('Whether to include match positions in results'), matchingStrategy: z.string().optional().describe("Matching strategy: 'all' or 'last'"), },
- src/tools/search-tools.ts:43-104 (registration)Registers the 'search' tool with the MCP server using server.tool() including name, description, schema, and handler.server.tool( 'search', 'Search for documents in a Meilisearch index', { indexUid: z.string().describe('Unique identifier of the index'), q: z.string().describe('Search query'), 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 query to apply'), sort: z.array(z.string()).optional().describe('Attributes to sort by, e.g. ["price:asc"]'), facets: z.array(z.string()).optional().describe('Facets to return'), attributesToRetrieve: z.array(z.string()).optional().describe('Attributes to include in results'), attributesToCrop: z.array(z.string()).optional().describe('Attributes to crop'), cropLength: z.number().optional().describe('Length at which to crop cropped attributes'), attributesToHighlight: z.array(z.string()).optional().describe('Attributes to highlight'), highlightPreTag: z.string().optional().describe('Tag to insert before highlighted text'), highlightPostTag: z.string().optional().describe('Tag to insert after highlighted text'), showMatchesPosition: z.boolean().optional().describe('Whether to include match positions in results'), matchingStrategy: z.string().optional().describe("Matching strategy: 'all' or 'last'"), }, async ({ indexUid, q, limit, offset, filter, sort, facets, attributesToRetrieve, attributesToCrop, cropLength, attributesToHighlight, highlightPreTag, highlightPostTag, showMatchesPosition, matchingStrategy }: SearchParams) => { try { const response = await apiClient.post(`/indexes/${indexUid}/search`, { q, limit, offset, filter, sort, facets, attributesToRetrieve, attributesToCrop, cropLength, attributesToHighlight, highlightPreTag, highlightPostTag, showMatchesPosition, matchingStrategy, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } } );
- src/index.ts:66-66 (registration)Top-level call to registerSearchTools which includes the 'search' tool registration on the main MCP server instance.registerSearchTools(server);
- src/tools/search-tools.ts:102-102 (helper)Uses createErrorResponse helper for error handling in the search tool handler.}
- src/tools/search-tools.ts:81-81 (helper)Uses apiClient helper to make the HTTP POST request to Meilisearch.const response = await apiClient.post(`/indexes/${indexUid}/search`, {