createDeck
Create a new Anki flashcard deck with a name and description to organize study materials for spaced repetition learning.
Instructions
Create a new Anki deck
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | Description of the deck | |
| isPublic | No | Whether the deck should be public | |
| name | Yes | Name of the deck |
Implementation Reference
- src/index.ts:95-106 (handler)The execute function that performs the core logic of the createDeck tool: sends a POST request to the Anki API endpoint '/api/v1/decks' with the provided name, description, and optional isPublic flag.execute: async args => { try { const data = await ankiApiRequest('POST', '/api/v1/decks', { description: args.description, isPublic: args.isPublic || false, name: args.name, }); return JSON.stringify(data, null, 2); } catch (error) { return `Error: ${error instanceof Error ? error.message : String(error)}`; } },
- src/index.ts:108-115 (schema)Zod schema defining the input parameters for the createDeck tool: required name and description (strings), optional isPublic (boolean).parameters: z.object({ description: z.string().describe('Description of the deck'), isPublic: z .boolean() .optional() .describe('Whether the deck should be public'), name: z.string().describe('Name of the deck'), }),
- src/index.ts:93-116 (registration)The FastMCP server.addTool registration for the createDeck tool, including name, description, handler, and schema.server.addTool({ description: 'Create a new Anki deck', execute: async args => { try { const data = await ankiApiRequest('POST', '/api/v1/decks', { description: args.description, isPublic: args.isPublic || false, name: args.name, }); return JSON.stringify(data, null, 2); } catch (error) { return `Error: ${error instanceof Error ? error.message : String(error)}`; } }, name: 'createDeck', parameters: z.object({ description: z.string().describe('Description of the deck'), isPublic: z .boolean() .optional() .describe('Whether the deck should be public'), name: z.string().describe('Name of the deck'), }), });
- src/index.ts:23-63 (helper)Shared helper function for making authenticated HTTP requests to the Anki API, used by createDeck 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; }