Skip to main content
Glama
OrionPotter

Meilisearch MCP Server

by OrionPotter

add-documents

Add documents to a Meilisearch index for search functionality by specifying the index identifier and JSON document array.

Instructions

Add documents to a Meilisearch index

Input Schema

NameRequiredDescriptionDefault
indexUidYesUnique identifier of the index
documentsYesJSON array of documents to add
primaryKeyNoPrimary key for the documents

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "documents": { "description": "JSON array of documents to add", "type": "string" }, "indexUid": { "description": "Unique identifier of the index", "type": "string" }, "primaryKey": { "description": "Primary key for the documents", "type": "string" } }, "required": [ "indexUid", "documents" ], "type": "object" }

Implementation Reference

  • The main handler function for the 'add-documents' tool. It parses the documents JSON string, validates it's an array, optionally sets primaryKey param, and performs a POST request to the Meilisearch API to add the documents, returning the response or error.
    async ({ indexUid, documents, primaryKey }: AddDocumentsParams) => { try { // Parse the documents string to ensure it's valid JSON const parsedDocuments = JSON.parse(documents); // Ensure documents is an array if (!Array.isArray(parsedDocuments)) { return { isError: true, content: [{ type: 'text', text: 'Documents must be a JSON array' }], }; } const params: Record<string, string> = {}; if (primaryKey) { params.primaryKey = primaryKey; } const response = await apiClient.post(`/indexes/${indexUid}/documents`, parsedDocuments, { params, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } }
  • Zod schema defining the input parameters for the 'add-documents' tool: indexUid (required string), documents (required JSON string), primaryKey (optional string).
    { indexUid: z.string().describe('Unique identifier of the index'), documents: z.string().describe('JSON array of documents to add'), primaryKey: z.string().optional().describe('Primary key for the documents'), },
  • TypeScript interface defining the parameters for the add-documents handler function.
    interface AddDocumentsParams { indexUid: string; documents: string; primaryKey?: string; }
  • Registration of the 'add-documents' tool on the MCP server using server.tool(), including name, description, input schema, and handler function.
    server.tool( 'add-documents', 'Add documents to a Meilisearch index', { indexUid: z.string().describe('Unique identifier of the index'), documents: z.string().describe('JSON array of documents to add'), primaryKey: z.string().optional().describe('Primary key for the documents'), }, async ({ indexUid, documents, primaryKey }: AddDocumentsParams) => { try { // Parse the documents string to ensure it's valid JSON const parsedDocuments = JSON.parse(documents); // Ensure documents is an array if (!Array.isArray(parsedDocuments)) { return { isError: true, content: [{ type: 'text', text: 'Documents must be a JSON array' }], }; } const params: Record<string, string> = {}; if (primaryKey) { params.primaryKey = primaryKey; } const response = await apiClient.post(`/indexes/${indexUid}/documents`, parsedDocuments, { params, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } } );
  • src/index.ts:65-65 (registration)
    Top-level registration call to registerDocumentTools(server), which registers the 'add-documents' tool (and other document tools) with the main MCP server instance.
    registerDocumentTools(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/OrionPotter/iflow-mcp_meilisearch-ts-mcp'

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