get-document
Retrieve a specific document from a Meilisearch index using its unique ID, optionally selecting which fields to return in the result.
Instructions
Get a document by its ID from a Meilisearch index
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| indexUid | Yes | Unique identifier of the index | |
| documentId | Yes | ID of the document to retrieve | |
| fields | No | Fields to return in the document |
Implementation Reference
- src/tools/document-tools.ts:100-112 (handler)Handler function that retrieves a specific document from a Meilisearch index by ID using the configured API client and returns the JSON-formatted response or an error response.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:95-99 (schema)Zod schema defining the input parameters for the 'get-document' tool: required indexUid and documentId, optional fields array.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) => {
- src/tools/document-tools.ts:92-113 (registration)Registration of the 'get-document' MCP tool on the server, specifying name, description, input schema, and handler 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 tool, used in the handler type annotation.interface GetDocumentParams { indexUid: string; documentId: string; fields?: string[]; }
- src/index.ts:65-65 (registration)Call to registerDocumentTools function which includes registration of the 'get-document' tool.registerDocumentTools(server);