Skip to main content
@meilisearch/ai-sdk adds Meilisearch search tools to the Vercel AI SDK, letting an LLM decide when to search your data and how to use the results.

Requirements

  • A Meilisearch project with at least one index containing documents
  • A search API key for that project
  • An API key from an LLM provider (this example uses OpenAI, but any provider supported by the AI SDK works)

Install

Add your credentials to your environment:
.env

Give an agent a search tool

The model decides whether and how many times to call search before answering. The description field tells it what the index contains and when to use it.

Agentic movie search demo

See a movie recommendation agent built with this integration

AI SDK demo

Next.js chatbox example application

Use Meilisearch MCP

The AI SDK can also connect to the Meilisearch MCP server. It wraps the tools exposed by the server and passes them to the model like any other tool. This is the quickest way to get started, because you do not configure any search tool yourself. If you need typed tools and control over search parameters, use meilisearchSearch as shown above. Before you start, enable the MCP route and create an API key for MCP. The key needs the search, documents.get, and indexes.get actions, otherwise calls to listIndexes and describeIndex fail. The default search API key is not enough. Install the MCP client package:
Create an MCP client, load its tools, and pass them to generateText:
For the list of available tools and limitations, see the MCP guide. If the client cannot connect, see troubleshooting.

Going further

Getting started with agentic search

Build a multi-turn chatbot with streaming responses.

Display source documents

Show users which documents an agent used to answer.

Configure guardrails

Keep agents on topic and grounded in your data.

Handle errors and fallbacks

Make your agent resilient to search and LLM failures.
For the full list of available tools, see the SDK repository.