listDecks
Retrieve all Anki flashcard decks with pagination controls to manage large collections efficiently.
Instructions
List all Anki decks with optional pagination
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of decks to return | |
| offset | No | Number of decks to skip |
Implementation Reference
- src/index.ts:68-83 (handler)Handler function that fetches the list of Anki decks using the ankiApiRequest helper, with optional pagination parameters.execute: async args => { try { const queryParams: Record<string, boolean | number | string> = {}; if (args.limit !== undefined) queryParams.limit = args.limit; if (args.offset !== undefined) queryParams.offset = args.offset; const data = await ankiApiRequest( 'GET', '/api/v1/decks', undefined, queryParams, ); return JSON.stringify(data, null, 2); } catch (error) { return `Error: ${error instanceof Error ? error.message : String(error)}`; }
- src/index.ts:86-89 (schema)Zod schema defining optional input parameters: limit (number) and offset (number) for pagination.parameters: z.object({ limit: z.number().optional().describe('Number of decks to return'), offset: z.number().optional().describe('Number of decks to skip'), }),
- src/index.ts:66-90 (registration)Registration of the 'listDecks' tool with FastMCP server, including description, handler, name, and parameters schema.server.addTool({ description: 'List all Anki decks with optional pagination', execute: async args => { try { const queryParams: Record<string, boolean | number | string> = {}; if (args.limit !== undefined) queryParams.limit = args.limit; if (args.offset !== undefined) queryParams.offset = args.offset; const data = await ankiApiRequest( 'GET', '/api/v1/decks', undefined, queryParams, ); return JSON.stringify(data, null, 2); } catch (error) { return `Error: ${error instanceof Error ? error.message : String(error)}`; } }, name: 'listDecks', parameters: z.object({ limit: z.number().optional().describe('Number of decks to return'), offset: z.number().optional().describe('Number of decks to skip'), }), });
- src/index.ts:23-63 (helper)Shared helper function for making authenticated HTTP requests to the Anki API, used by listDecks and other tools.async function ankiApiRequest( method: string, endpoint: string, body?: Record<string, unknown>, queryParams?: Record<string, boolean | number | string | undefined>, ) { const url = new URL(`${ANKI_BASE_URL}${endpoint}`); // Add query parameters if provided if (queryParams) { Object.entries(queryParams).forEach(([key, value]) => { if (value !== undefined && value !== '') { url.searchParams.append(key, String(value)); } }); } const options: RequestInit = { headers: { Authorization: `Bearer ${ANKI_API_KEY}`, 'Content-Type': 'application/json', }, method, }; if (body && method !== 'GET') { options.body = JSON.stringify(body); } const response = await fetch(url.toString(), options); const data = (await response.json()) as unknown; if (!response.ok) { const errorData = data as { error?: { message?: string } }; throw new Error( errorData.error?.message || `API request failed: ${response.statusText}`, ); } return data; }