tag_reviewed_cards
Add review date tags to Anki cards to track when they were last reviewed, using customizable tag prefixes for organization.
Instructions
Add a 'reviewed on date' tag to specified cards
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| card_ids | Yes | Array of card IDs to tag as reviewed | |
| custom_tag_prefix | No | Custom prefix for the tag (default: '見直し') |
Implementation Reference
- src/index.ts:502-522 (registration)Registration of the 'tag_reviewed_cards' tool in the ListToolsRequestHandler, including name, description, and input schema{ name: "tag_reviewed_cards", description: "Add a 'reviewed on date' tag to specified cards", inputSchema: { type: "object", properties: { card_ids: { type: "array", items: { type: "number", }, description: "Array of card IDs to tag as reviewed", }, custom_tag_prefix: { type: "string", description: "Custom prefix for the tag (default: '見直し')", }, }, required: ["card_ids"], }, },
- src/index.ts:675-720 (handler)Main handler function for executing the 'tag_reviewed_cards' tool logic, validates input, calls AnkiConnect to add tags, and returns success responseprivate async handleTagReviewedCards(request: any) { const cardIds = request.params.arguments?.card_ids; const customTagPrefix = request.params.arguments?.custom_tag_prefix; // Validate card IDs if (!cardIds || !Array.isArray(cardIds) || cardIds.length === 0) { return { content: [ { type: "text", text: "Error: No card IDs provided. Please provide an array of card IDs to tag.", }, ], isError: true, }; } // Add tags to cards // addTagsは成功してもresultもerrorもnullなので、例外発生しなければ成功 await this.ankiClient.addTagsToCards(cardIds, customTagPrefix); const now = new Date(); const tagDate = `${now.getFullYear()}${String(now.getMonth() + 1).padStart( 2, "0" )}${String(now.getDate()).padStart(2, "0")}`; const tagPrefix = customTagPrefix || "見直し"; return { content: [ { type: "text", text: JSON.stringify( { message: `Successfully tagged ${cardIds.length} cards with '${tagPrefix}_${tagDate}'`, tagged_cards: cardIds, tag_added: `${tagPrefix}_${tagDate}`, success: true, }, null, 2 ), }, ], }; }
- src/index.ts:372-409 (helper)Core helper method in AnkiConnectClient that converts card IDs to note IDs, generates date-based tag, and adds the tag via AnkiConnect APIasync addTagsToCards( cardIds: number[], customTagPrefix?: string ): Promise<boolean> { if (cardIds.length === 0) { console.error("No cards provided to tag"); return false; } try { // First, get the note IDs for the specified cards const cardsInfo = await this.request<any[]>("cardsInfo", { cards: cardIds, }); // Extract unique note IDs const noteIds = [...new Set(cardsInfo.map((card) => card.note))]; if (noteIds.length === 0) { console.error("Could not find note IDs for the provided card IDs"); return false; } // Generate the tag with current date const reviewedTag = this.generateReviewedTag(customTagPrefix); // Add the tag to all notes const result = await this.request<boolean>("addTags", { notes: noteIds, tags: reviewedTag, }); return result; } catch (error) { console.error("Error adding tags to cards:", error); throw error; } }
- src/index.ts:347-353 (helper)Helper method to generate the date-based reviewed tag string used by addTagsToCardsprivate generateReviewedTag(customPrefix: string = "見直し"): string { const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, "0"); const day = String(now.getDate()).padStart(2, "0"); return `${customPrefix}::${year}${month}${day}`; }