Skip to main content
Glama

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
NameRequiredDescriptionDefault
limitNoNumber of decks to return
offsetNoNumber of decks to skip

Implementation Reference

  • The execute function that implements the core logic of the listDecks tool: constructs query params from args, calls ankiApiRequest to GET /api/v1/decks, returns JSON stringified data or error.
    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)}`; } },
  • Zod input schema for listDecks tool parameters: optional limit (number) and offset (number).
    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 using server.addTool, including name, description, handler, and 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'), }), });
  • Shared helper function ankiApiRequest used by the listDecks handler to make authenticated HTTP requests to the Anki API.
    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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zlatanpham/anki-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server