get-document
Retrieve a specific document by its ID from a Meilisearch index, optionally selecting which fields to return for targeted data access.
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:99-112 (handler)Handler function that fetches a single document by ID from a Meilisearch index using the apiClient, returns JSON stringified response or error.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 for tool input parameters: 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:91-113 (registration)server.tool registration of the 'get-document' tool including name, description, schema, and handler.server.tool( '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/index.ts:65-65 (registration)Top-level call to registerDocumentTools which registers the get-document tool among others.registerDocumentTools(server);
- src/tools/document-tools.ts:22-26 (helper)TypeScript interface defining parameters for the get-document handler.interface GetDocumentParams { indexUid: string; documentId: string; fields?: string[]; }