get-document
Retrieve specific documents by ID from a Meilisearch index, specifying fields to return for efficient data access and management through the Meilisearch MCP Server.
Instructions
Get a document by its ID from a Meilisearch index
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| documentId | Yes | ID of the document to retrieve | |
| fields | No | Fields to return in the document | |
| indexUid | Yes | Unique identifier of the index |
Implementation Reference
- src/tools/document-tools.ts:99-112 (handler)The asynchronous handler function that retrieves a specific document from a Meilisearch index by ID using the apiClient to call the Meilisearch API.async ({ indexUid, documentId, fields }: GetDocumentParams) => { try { const response = await apiClient.get(`/indexes/${indexUid}/documents/${documentId}`, { params: { fields: fields?.join(','), }, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } }
- src/tools/document-tools.ts:94-98 (schema)Zod schema defining the input parameters for the get-document tool: indexUid, documentId, and optional fields.{ indexUid: z.string().describe('Unique identifier of the index'), documentId: z.string().describe('ID of the document to retrieve'), fields: z.array(z.string()).optional().describe('Fields to return in the document'), },
- src/tools/document-tools.ts:92-113 (registration)Direct registration of the 'get-document' tool using server.tool() within the registerDocumentTools function.'get-document', 'Get a document by its ID from a Meilisearch index', { indexUid: z.string().describe('Unique identifier of the index'), documentId: z.string().describe('ID of the document to retrieve'), fields: z.array(z.string()).optional().describe('Fields to return in the document'), }, async ({ indexUid, documentId, fields }: GetDocumentParams) => { try { const response = await apiClient.get(`/indexes/${indexUid}/documents/${documentId}`, { params: { fields: fields?.join(','), }, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } } );
- src/tools/document-tools.ts:22-26 (schema)TypeScript interface defining the parameters for the get-document handler.interface GetDocumentParams { indexUid: string; documentId: string; fields?: string[]; }
- src/index.ts:65-65 (registration)Top-level call to registerDocumentTools on the MCP server instance, which includes the get-document tool.registerDocumentTools(server);