update-documents
Modify existing documents in a Meilisearch index by providing updated JSON data and the index identifier, enabling real-time content synchronization.
Instructions
Update documents in a Meilisearch index
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| indexUid | Yes | Unique identifier of the index | |
| documents | Yes | JSON array of documents to update | |
| primaryKey | No | Primary 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 update",
"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
- src/tools/document-tools.ts:163-187 (handler)Handler function that parses the input documents JSON, validates it is an array, constructs API parameters, performs a PUT request to the Meilisearch /indexes/{indexUid}/documents endpoint to update documents, and returns the response or handles errors using createErrorResponse.async ({ indexUid, documents, primaryKey }: UpdateDocumentsParams) => { 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.put(`/indexes/${indexUid}/documents`, parsedDocuments, { params, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) {
- src/tools/document-tools.ts:158-162 (schema)Zod schema defining input parameters for the update-documents tool: indexUid (required string), documents (required string JSON array), primaryKey (optional string).{ indexUid: z.string().describe('Unique identifier of the index'), documents: z.string().describe('JSON array of documents to update'), primaryKey: z.string().optional().describe('Primary key for the documents'), },
- src/tools/document-tools.ts:155-191 (registration)MCP server.tool registration for 'update-documents', including description, input schema, and handler function.server.tool( 'update-documents', 'Update documents in a Meilisearch index', { indexUid: z.string().describe('Unique identifier of the index'), documents: z.string().describe('JSON array of documents to update'), primaryKey: z.string().optional().describe('Primary key for the documents'), }, async ({ indexUid, documents, primaryKey }: UpdateDocumentsParams) => { 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.put(`/indexes/${indexUid}/documents`, parsedDocuments, { params, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } } );
- src/tools/document-tools.ts:34-38 (schema)TypeScript interface defining the parameters for the update-documents handler.interface UpdateDocumentsParams { indexUid: string; documents: string; primaryKey?: string; }
- src/index.ts:65-65 (registration)Invocation of registerDocumentTools on the main MCP server instance, which registers the update-documents tool among other document tools.registerDocumentTools(server);