Skip to main content
Glama
OrionPotter

Meilisearch MCP Server

by OrionPotter

add-documents

Add documents to a Meilisearch index by providing a JSON array of documents and specifying the target index identifier. This tool enables document ingestion for search functionality.

Instructions

Add documents to a Meilisearch index

Input Schema

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

Implementation Reference

  • Handler function for 'add-documents' tool: parses JSON documents string, validates array, sets optional primaryKey param, and POSTs to Meilisearch /indexes/{indexUid}/documents endpoint.
    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 input schema for 'add-documents' tool parameters.
    {
      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 matching the handler parameters for 'add-documents'.
    interface AddDocumentsParams {
      indexUid: string;
      documents: string;
      primaryKey?: string;
    }
  • Direct MCP server.tool registration block for the 'add-documents' tool.
    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 call to registerDocumentTools(server), which registers the 'add-documents' tool among others.
    registerDocumentTools(server);

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Add documents' implies a write operation, it doesn't specify whether this creates new documents, updates existing ones, or both; whether it's idempotent; what happens on failure; or any rate limits/permissions required. This leaves significant behavioral gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a tool with good schema documentation and gets straight to the point without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns, how errors are handled, whether documents replace or merge with existing ones, or any side effects. Given the complexity of document addition operations, more context is needed for proper agent usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so all parameters are documented in the schema. The description doesn't add any parameter-specific information beyond what's in the schema (e.g., format examples for the JSON array, primary key usage). Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Add documents') and target resource ('to a Meilisearch index'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'update-documents', which could also add documents to an index, leaving some ambiguity about when to use each.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'update-documents' or 'create-index'. It doesn't mention prerequisites (e.g., index must exist), exclusions, or typical use cases, leaving the agent with insufficient context for proper tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.