Anki MCP Server

repository·master·Indexed 42 days ago

https://github.com/nailuogg/anki-mcp-server

A Model Context Protocol (MCP) server version 0.1.8 that enables LLMs to interact with Anki flashcard software via the AnkiConnect add-on. It allows agents to create, search, update, and manage decks, notes, and tags using tools such as anki_create_note, anki_batch_create_notes, and anki_search_notes. Compatible with Claude Desktop, Cline, and Claude Code.

Tokens
11K
Snippets
42
Records
65
Agent score
54%

What's inside Anki MCP Server

  1. Managing Tags and Decks

    master

    Deck Naming

    Use double colons :: to create hierarchical deck structures (e.g., Language::English::Vocabulary or CS::Algorithms::Sorting).

    Tag Management

    • Use anki_list_tags to inspect existing tags.
    • For metadata-only changes (adding/removing tags without changing card content), use anki_add_note_tags or anki_remove_note_tags.
    • Use anki_update_note only when you intend to replace the entire tag list for a note.
  2. Note Types and Field Requirements

    master

    When creating notes, you must match the fields required by the note type. Always call anki_get_note_type_info first to verify field names for custom types.

    TypeFieldsUse For
    BasicFront, BackDefinitions, facts, Q&A
    ClozeText (with {{c1::deletion}})Fill-in-the-blank, sequences
  3. Workflow: Converting text/notes to Flashcards

    master

    Follow this workflow to ensure successful card creation:

    1. Verify Deck: Call anki_list_decks to confirm the target deck exists (create it with anki_create_deck if needed).
    2. Verify Fields: Call anki_get_note_type_info to confirm the exact field names for your chosen note type. Field names are case-sensitive.
    3. Extract Knowledge: Break down information into single concepts—one concept per card.
    4. Batch Create: Call anki_batch_create_notes.
      • Aim for 10–20 notes per call.
      • The absolute maximum is 50 notes per call.

    Minimum information principle: Each card should test exactly one thing.

  4. Verify anki-mcp-server installation

    master

    To confirm the server is working correctly:

    1. Ensure the Anki application is currently running.
    2. Start Claude.
    3. Use a prompt to attempt a note creation, for example:

    Create an Anki card in the "Default" deck with: Front: What is the capital of France? Back: Paris

  5. Manually configure anki-mcp-server for Claude Desktop

    master

    If you prefer manual configuration, add the server to your claude_desktop_config.json file.

    Config file locations:

    • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%/Claude/claude_desktop_config.json

    Add the following entry to the mcpServers object:

    {
      "mcpServers": {
        "anki": {
          "command": "npx",
          "args": ["--yes", "anki-mcp-server"]
        }
      }
    }
  6. Set up Anki MCP Evaluations using a fixture

    master

    To run evaluations for the Anki MCP Server, you must first prepare a disposable Anki profile with a specific data set (fixture).

    1. Load the file fixtures/anki-agent-readonly-fixture.json into a new, disposable Anki profile using the anki_batch_create_notes tool.
    2. Once loaded, the questions defined in anki-agent-readonly-evaluation.xml become available as read-only data for testing agent capabilities.

    Fixture Details:

    • Deck Name: MCP Eval::Agent Basics
    • Tag: Every fixture note is tagged with mcp-eval.
    // Use this file to populate your test profile
    fixtures/anki-agent-readonly-fixture.json
  7. Configure the Anki MCP Server in Claude Desktop

    master

    To use the Anki MCP server with Claude Desktop, add the following configuration to your claude_desktop_config.json.

    Important: Do not use the .mcpb packaged version, as it outputs Electron metadata to stdout which breaks the MCP stdio protocol. Instead, use the npx command as shown below.

    Prerequisites

    1. The Anki desktop app must be running.
    2. The AnkiConnect addon must be installed (default port 8765).
    {
      "mcpServers": {
        "anki": {
          "command": "npx",
          "args": ["-y", "anki-mcp-server"]
        }
      }
    }
  8. Test and develop anki-mcp-server

    master

    For developers or those verifying the environment:

    • Run the test suite: Verifies server initialization, AnkiConnect communication, note operations, and deck operations.
    • Development mode: Use the watch command to automatically rebuild on changes.
    # Run tests
    npm test
    
    # Run with auto-rebuild
    npm run watch
  9. Install Anki MCP Server via Claude Desktop

    master

    You can install the Anki MCP Server in Claude Desktop using two methods:

    1. Generate the .mcpb file locally:
      npm run mcpb
    2. Open Claude Desktop Settings → Extensions.
    3. Drag the generated .mcpb file into the window and click Install.

    Method 2: Manual Configuration via JSON

    Add the server to your claude_desktop_config.json file:

    {
      "mcpServers": {
        "anki": {
          "command": "npx",
          "args": ["--yes", "anki-mcp-server"]
        }
      }
    }

    Note: If your AnkiConnect is running on a non-default port, use the --port argument:

    {
      "mcpServers": {
        "anki": {
          "command": "npx",
          "args": ["--yes", "anki-mcp-server", "--port", "8080"]
        }
      }
    }

    CRITICAL: Do not use the .mcpb packaged version as the MCP server via npx for standard stdio communication, as it outputs Electron metadata to stdout which breaks the protocol. Use npx -y anki-mcp-server instead.

  10. Install anki-mcp-server via Desktop Extension (.mcpb)

    master

    The preferred method for installing the server in Claude Desktop is using a .mcpb bundle. This provides a one-click installation experience.

    1. Download the .mcpb bundle from the Releases page (or build it locally).
    2. Open Claude Desktop.
    3. Navigate to Settings → Extensions.
    4. Drag the .mcpb file into the window and click Install.
    # To build the bundle locally
    npm install -g @anthropic-ai/mcpb
    mcpb pack
  11. Prerequisites for Anki MCP Server

    master

    Before using the server, ensure the following are installed and configured:

    1. Anki: The core flashcard software installed on your system.
    2. AnkiConnect: The Anki add-on must be installed within Anki to allow API communication.
    3. Node.js: Version 20.11 or newer is required.