get-document
Retrieve a specific document from a Meilisearch index using its unique ID, optionally selecting which fields to return.
Instructions
Get a document by its ID from a Meilisearch index
Input 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 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"documentId": {
"description": "ID of the document to retrieve",
"type": "string"
},
"fields": {
"description": "Fields to return in the document",
"items": {
"type": "string"
},
"type": "array"
},
"indexUid": {
"description": "Unique identifier of the index",
"type": "string"
}
},
"required": [
"indexUid",
"documentId"
],
"type": "object"
}
Implementation Reference
- src/tools/document-tools.ts:99-112 (handler)The core handler function for the 'get-document' tool. It makes an API call to retrieve a specific document by ID from the specified Meilisearch index and returns the JSON response or an 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 input schema defining the 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'), },
- src/tools/document-tools.ts:92-113 (registration)Registration of the 'get-document' MCP tool on the server, including name, description, input schema, and handler.'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 for typing the input parameters of the get-document handler.interface GetDocumentParams { indexUid: string; documentId: string; fields?: string[]; }
- src/index.ts:65-65 (registration)Top-level call to register all document tools, including 'get-document', on the MCP server instance.registerDocumentTools(server);