Skip to main content
Glama

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
NameRequiredDescriptionDefault
card_idsYesArray of card IDs to tag as reviewed
custom_tag_prefixNoCustom 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"],
      },
    },
  • Main handler function for executing the 'tag_reviewed_cards' tool logic, validates input, calls AnkiConnect to add tags, and returns success response
    private 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
            ),
          },
        ],
      };
    }
  • Core helper method in AnkiConnectClient that converts card IDs to note IDs, generates date-based tag, and adds the tag via AnkiConnect API
    async 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;
      }
    }
  • Helper method to generate the date-based reviewed tag string used by addTagsToCards
    private 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}`;
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

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/captain-blue210/anki-mcp-server'

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