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

  • 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)}`; }
  • 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'), }), });
  • 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; }

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