### Run HTTP Server via Global Installation Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Start the server in HTTP mode after a global installation, supporting custom port and host configurations. ```bash # Install once npm install -g @ankimcp/anki-mcp-server # Run the server ankimcp # With custom options ankimcp --port 8080 --host 0.0.0.0 ankimcp --anki-connect http://localhost:8765 ``` -------------------------------- ### Run development and production modes Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Commands for starting the server in various development and production configurations. ```bash # Development - STDIO mode (watch mode with auto-rebuild) npm run start:dev:stdio # Development - HTTP mode (watch mode with auto-rebuild) npm run start:dev:http # Production - STDIO mode npm run start:prod:stdio # or node dist/main-stdio.js # Production - HTTP mode npm run start:prod:http # or PORT=8080 HOST=0.0.0.0 node dist/main-http.js ``` -------------------------------- ### Install and Configure STDIO Globally Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Install the server globally via npm and use the 'ankimcp' command in your MCP client configuration. ```bash npm install -g @ankimcp/anki-mcp-server ``` ```json { "mcpServers": { "anki-mcp": { "command": "ankimcp", "args": ["--stdio"], "env": { "ANKI_CONNECT_URL": "http://localhost:8765" } } } } ``` -------------------------------- ### Run HTTP Server from Source Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Build and start the server from the source code for development purposes. ```bash npm install npm run build npm run start:prod:http ``` -------------------------------- ### Install Anki MCP Server globally with npm Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Use this command to install the server globally, allowing MCP clients to run the 'ankimcp' command directly. ```bash npm install -g @ankimcp/anki-mcp-server ``` -------------------------------- ### Anki MCP Server CLI Options and Usage Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Lists available command-line options and demonstrates how to run the server using npx or a global installation. ```bash ankimcp [options] Options: --stdio Run in STDIO mode (for MCP clients) --tunnel [url] Connect via the managed tunnel (authenticated) --login Authenticate for tunnel mode (OAuth device flow) --logout Clear saved tunnel credentials -p, --port Port to listen on (HTTP mode; default: 3000, or PORT env var) -h, --host
Host to bind to (HTTP mode; default: 127.0.0.1, or HOST env var) -a, --anki-connect AnkiConnect URL (default: http://localhost:8765, or ANKI_CONNECT_URL env var) --ngrok Start ngrok tunnel (requires global ngrok installation) --read-only Run in read-only mode (blocks all write operations) --help Show help message Usage with npx (no installation needed): npx @ankimcp/anki-mcp-server # HTTP mode npx @ankimcp/anki-mcp-server --port 8080 # Custom port npx @ankimcp/anki-mcp-server --stdio # STDIO mode npx @ankimcp/anki-mcp-server --tunnel # Managed tunnel mode npx @ankimcp/anki-mcp-server --ngrok # HTTP mode with ngrok tunnel npx @ankimcp/anki-mcp-server --read-only # Read-only mode Usage with global installation: npm install -g @ankimcp/anki-mcp-server # Install once ankimcp # HTTP mode ankimcp --port 8080 # Custom port ankimcp --stdio # STDIO mode ankimcp --tunnel # Managed tunnel mode ankimcp --ngrok # HTTP mode with ngrok tunnel ankimcp --read-only # Read-only mode ``` -------------------------------- ### Start the Debug Server Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Starts the MCP Inspector with the debug server configuration, pausing execution at the first line. ```bash npm run inspector:debug ``` -------------------------------- ### Run Anki MCP Server with npx Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Execute the server on demand without requiring a permanent global installation. ```bash npx @ankimcp/anki-mcp-server ``` -------------------------------- ### Build Anki MCP server from source Source: https://github.com/ankimcp/anki-mcp-server/blob/main/docs/reviewer-setup.md Commands to clone, install dependencies, and build the Anki MCP server locally for source-level review. ```bash git clone https://github.com/ankimcp/anki-mcp-server.git cd anki-mcp-server npm ci npm run build ``` -------------------------------- ### Run HTTP mode with custom host and port Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Example of binding the HTTP server to all interfaces and allowing specific hostnames for external access. ```bash # Bind to all interfaces and accept the machine's LAN name + a public domain ALLOWED_HOSTS=my-nas.local,anki.example.com PORT=8080 HOST=0.0.0.0 node dist/main-http.js ``` -------------------------------- ### Launch ngrok Subprocess Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Command to expose the local HTTP mode publicly using ngrok. Requires a global ngrok installation and authtoken. ```bash # One-time ngrok setup, then: ankimcp --ngrok ``` -------------------------------- ### Run HTTP Server via npx Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Start the server in HTTP mode using npx, with optional flags for custom ports and host binding. ```bash # Quick start npx @ankimcp/anki-mcp-server # With custom options npx @ankimcp/anki-mcp-server --port 8080 --host 0.0.0.0 npx @ankimcp/anki-mcp-server --anki-connect http://localhost:8765 ``` -------------------------------- ### Start the Tunnel Service Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Commands to connect to the managed tunnel service or a custom self-hosted tunnel URL. ```bash # Connect to the managed tunnel service (wss://tunnel.ankimcp.ai) ankimcp --tunnel npx @ankimcp/anki-mcp-server --tunnel # Override the tunnel server URL (must be ws:// or wss://) — e.g. for self-hosting ankimcp --tunnel wss://my-tunnel.example.com ``` -------------------------------- ### Local NPM Package Testing Commands Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Commands to pack, install, test, and uninstall the npm package locally to simulate the user experience before publishing. ```bash # 1. Create local package npm run pack:local # Builds and creates @ankimcp/anki-mcp-server-*.tgz # 2. Install globally from local package npm run install:local # Installs from ./@ankimcp/anki-mcp-server-*.tgz # 3. Test the command ankimcp # Runs HTTP server on port 3000 # 4. Uninstall when done testing npm run uninstall:local # Removes global installation ``` -------------------------------- ### Configure STDIO via npx Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Use this JSON configuration for MCP clients like Claude Desktop or Cursor to run the server via npx without prior installation. ```json { "mcpServers": { "anki-mcp": { "command": "npx", "args": ["-y", "@ankimcp/anki-mcp-server", "--stdio"], "env": { "ANKI_CONNECT_URL": "http://localhost:8765" } } } } ``` -------------------------------- ### Anki Note Management Tool Invocations Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Examples of using findNotes, notesInfo, updateNoteFields, and deleteNotes tools to manage Anki content. ```text # Search for notes in a specific deck findNotes(query: "deck:Spanish") # Get detailed information about notes notesInfo(notes: [1234567890, 1234567891]) # Update a note's fields (HTML content supported) updateNoteFields(note: { id: 1234567890, fields: { "Front": "¿Cómo estás?", "Back": "How are you?" } }) # Delete notes (requires confirmation) deleteNotes(notes: [1234567890], confirmDeletion: true) ``` -------------------------------- ### Claude Desktop Configuration Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Add this JSON block to your Claude Desktop configuration file to register the Anki MCP server. Ensure you replace the path in the args array with the absolute path to your local installation. ```json { "mcpServers": { "anki-mcp": { "command": "node", "args": ["/path/to/anki-mcp-server/dist/main-stdio.js"], "env": { "ANKI_CONNECT_URL": "http://localhost:8765" } } } } ``` -------------------------------- ### Read-Only Mode CLI Usage Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Examples of enabling read-only mode via CLI flags to prevent modifications to the Anki collection. ```bash # HTTP mode with read-only ankimcp --read-only # STDIO mode with read-only ankimcp --stdio --read-only # Can combine with other flags ankimcp --ngrok --read-only ``` -------------------------------- ### Build the project Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Builds the project once and creates the dist/ directory containing all three entry points. ```bash npm run build # Builds once, creates dist/ with all three entry points ``` -------------------------------- ### Project Build, Test, and Debug Commands Source: https://github.com/ankimcp/anki-mcp-server/blob/main/CLAUDE.md A collection of npm scripts for building, testing, and debugging the Anki MCP server. Includes commands for STDIO, HTTP, and tunnel modes, as well as various test suites and quality checks. ```bash # Build & Run npm run build # Build → dist/ (all three entry points) npm run start:dev:stdio # STDIO mode with watch npm run start:dev:http # HTTP mode with watch npm run start:dev:tunnel # Tunnel mode with watch + debug # Testing npm test # All tests npm test -- path/to/file.spec.ts # Single test file npm run test:tools # Tool unit tests only npm run test:workflows # Multi-tool workflow scenarios (mocked) npm run test:cov # With coverage (70% threshold) npm run e2e:full:local # One-shot E2E: up → test → down npm run smoke:pack # Pack + install from tarball (no lockfile), verify initialize/tools-list # Quality npm run lint && npm run type-check # Pre-push checks (also runs via Husky) # Debugging npm run inspector:stdio # MCP Inspector UI for testing tools npm run inspector:stdio:debug # With debugger on port 9229 npm run inspector:http # Inspector against HTTP transport ``` -------------------------------- ### Build an MCPB Bundle Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Creates a distributable .mcpb bundle by syncing versions, building the project, and optimizing dependencies. ```bash npm run mcpb:bundle ``` -------------------------------- ### Module System Entry Point Flow Source: https://github.com/ankimcp/anki-mcp-server/blob/main/CLAUDE.md The initialization flow for different transport modes, showing how the MCP strategy and primitive modules are composed. ```text AppModule.forStdio()/forHttp()/forTunnel() → MCP_STRATEGY provider # the McpStrategy the entry point built → McpPrimitivesAnkiEssentialModule.forRoot() → McpPrimitivesAnkiGuiModule.forRoot() ``` -------------------------------- ### Project Build Commands Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Common npm scripts for building the project, running in development modes, and performing quality checks. ```bash npm run build # Build the project (compile TypeScript to JavaScript) npm run start:dev:stdio # STDIO mode with watch (auto-rebuild) npm run start:dev:http # HTTP mode with watch (auto-rebuild) npm run type-check # Run TypeScript type checking npm run lint # Run ESLint npm run mcpb:bundle # Sync version, clean, build, and create MCPB bundle ``` -------------------------------- ### Configure MCP client with npx Source: https://github.com/ankimcp/anki-mcp-server/blob/main/docs/reviewer-setup.md Use this configuration for any STDIO-based MCP client to run the Anki MCP server via npx. ```json { "mcpServers": { "anki": { "command": "npx", "args": ["-y", "@ankimcp/anki-mcp-server", "--stdio"] } } } ``` -------------------------------- ### Configure anki-mcp-server for STDIO Source: https://github.com/ankimcp/anki-mcp-server/blob/main/FAQ.md Use this configuration in your MCP client settings to run the server via npx using STDIO transport. ```json { "mcpServers": { "anki-mcp": { "command": "npx", "args": ["-y", "@ankimcp/anki-mcp-server", "--stdio"] } } } ``` -------------------------------- ### Run a single unit test file Source: https://github.com/ankimcp/anki-mcp-server/blob/main/CLAUDE.md Executes a specific test file using the npm test command. ```bash # Single test file npm test -- src/mcp/primitives/essential/tools/__tests__/sync.tool.spec.ts ``` -------------------------------- ### Project Testing Commands Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Various npm scripts for executing unit, integration, and end-to-end tests, including options for watch mode and coverage reporting. ```bash npm test # Run all tests npm run test:unit # Run unit tests only npm run test:tools # Run tool-specific tests npm run test:workflows # Run workflow integration tests npm run test:e2e # Run end-to-end tests npm run test:cov # Run tests with coverage report npm run test:watch # Run tests in watch mode npm run test:debug # Run tests with debugger npm run test:ci # Run tests for CI (silent, with coverage) ``` -------------------------------- ### Tail MCP Server Logs Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md View real-time logs for the Anki MCP server on macOS. ```bash tail -f ~/Library/Logs/Claude/mcp-server-Anki\ MCP\ Server.log ``` -------------------------------- ### E2E test lifecycle commands Source: https://github.com/ankimcp/anki-mcp-server/blob/main/CLAUDE.md Commands to manage the Docker-based E2E test environment and execute test suites. ```bash npm run e2e:up # Start Anki + AnkiConnect containers npm run e2e:test # Run all E2E tests npm run e2e:test:stdio # STDIO transport only npm run e2e:test:http # HTTP transport only npm run e2e:down # Stop containers npm run e2e:full:local # All-in-one: up → test → down ``` -------------------------------- ### Deck Management Tools Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Tools for listing, creating, and modifying decks. ```APIDOC ## listDecks ### Description List all decks, optionally with per-deck study-queue statistics. ## createDeck ### Description Create a new empty deck (supports Parent::Child, max 2 levels). ``` -------------------------------- ### Authenticate and Manage Credentials Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Commands to perform OAuth 2.0 device flow login or clear saved credentials. ```bash # Pre-authenticate (optional — --tunnel will trigger this automatically if needed) ankimcp --login npx @ankimcp/anki-mcp-server --login # Clear saved credentials ankimcp --logout ``` -------------------------------- ### Tool Implementation Pattern Source: https://github.com/ankimcp/anki-mcp-server/blob/main/CLAUDE.md The standard pattern for creating a new tool, involving Zod schema validation, controller registration, and the @Tool decorator. ```typescript // 1. Zod schema for input validation // 2. @McpController() class with AnkiConnectClient injected (registered as a module controller) // 3. @Tool({ name, description, parameters, outputSchema, annotations }) decorator // 4. Handler method taking @Payload() params, calling AnkiConnectClient.invoke() // 5. Success: return raw object matching outputSchema (handler wraps it automatically) // 6. Error: return createErrorResponse() (bypasses outputSchema validation) ``` -------------------------------- ### Configure Claude Desktop for Debugging Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Update the claude_desktop_config.json file to enable the Node.js inspector on port 9229. ```json { "mcpServers": { "anki-mcp": { "command": "node", "args": [ "--inspect=9229", "/anki-mcp-server/dist/main-stdio.js" ], "env": { "ANKI_CONNECT_URL": "http://localhost:8765" } } } } ``` -------------------------------- ### GUI Tools Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Tools that drive the Anki desktop interface for note editing, creation, and deck management. ```APIDOC ## GUI Tools - `guiBrowse`: Open the Card Browser and search for cards. - `guiSelectCard`: Select a specific card in the Card Browser. - `guiSelectedNotes`: Get IDs of notes currently selected in the Card Browser. - `guiAddCards`: Open the Add Cards dialog with preset note details. - `guiEditNote`: Open the note editor for a specific note. - `guiDeckOverview`: Open the Deck Overview dialog for a specific deck. - `guiDeckBrowser`: Open the Deck Browser dialog. - `guiCurrentCard`: Get info about the current card in review mode. - `guiShowQuestion`: Show the question side of the current card. - `guiShowAnswer`: Show the answer side of the current card. - `guiUndo`: Undo the last action in Anki. ``` -------------------------------- ### Check Node.js Version Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Run this command in your terminal to verify your current Node.js version. ```bash node --version ``` -------------------------------- ### Media Management Tools Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Tools for listing, retrieving, storing, and deleting media files within the Anki collection. ```APIDOC ## Media Management - `getMediaFilesNames`: List media files in `collection.media`, optionally filtered by pattern. - `retrieveMediaFile`: Download a media file as base64 content. - `storeMediaFile`: Upload media from base64 data, an absolute file path, or a URL. - `deleteMediaFile`: Remove a media file from `collection.media` (destructive). ``` -------------------------------- ### CLI Output Usage Source: https://github.com/ankimcp/anki-mcp-server/blob/main/CLAUDE.md Use the cli utility for user-facing output in CLI commands such as tunnel, login, logout, and startup banners. This output is clean and does not include timestamps. ```typescript import { cli } from '@/cli/cli-output'; cli.success('Connected to Anki'); // ✓ Connected to Anki cli.error('Connection failed'); // ✗ Connection failed cli.info('Starting server...'); // Starting server... cli.box('Tunnel URL', 'https://...'); // Boxed message cli.blank(); // Empty line ``` -------------------------------- ### VS Code Debugger Configuration Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Add this configuration to your .vscode/launch.json file to attach the VS Code debugger to the running Anki MCP server process. ```json { "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "Attach to Anki MCP (Claude Desktop)", "port": 9229, "skipFiles": ["/**"], "sourceMaps": true, "outFiles": ["${workspaceFolder}/dist/**/*.js"] } ] } ``` -------------------------------- ### Troubleshoot ERR_REQUIRE_ESM Error Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md This error indicates an incompatible Node.js version. The server requires Node.js 22.12.0 or higher. ```text Error [ERR_REQUIRE_ESM]: require() of ES Module not supported ``` -------------------------------- ### Review & Study Tools Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Tools for syncing, fetching, and rating cards during study sessions. ```APIDOC ## sync ### Description Sync with AnkiWeb to pull latest data and push changes. ## get_due_cards ### Description Get cards that are due for review, optionally filtered by deck. - **include_answer** (boolean) - Optional - If true, includes the answer in the output (default: false). ## rate_card ### Description Rate card performance (Again, Hard, Good, Easy) and schedule the next review. ``` -------------------------------- ### Note Management Tools Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Tools for creating, searching, and updating notes. ```APIDOC ## addNote ### Description Create a single note with specified fields and tags. ## findNotes ### Description Search for notes using Anki query syntax (e.g., deck:, tag:, is:due). ## updateNoteFields ### Description Update existing note fields (CSS-aware, supports HTML content). ``` -------------------------------- ### Model/Template Management Tools Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Tools for managing Anki note types, including fields, styling, and templates. ```APIDOC ## Model/Template Management - `modelNames`: List all available note types/models. - `modelFieldNames`: Get field names for a specific note type. - `modelStyling`: Get CSS styling information for a note type. - `modelTemplates`: Get the card templates (Front and Back HTML) for a note type. - `createModel`: Create a new note type with custom fields, card templates, and CSS. - `updateModelStyling`: Update the CSS styling for an existing note type. - `updateModelTemplates`: Update the card templates for an existing note type. - `addModelField`: Add a new field to an existing note type. - `removeModelField`: Remove a field from an existing note type. - `renameModelField`: Rename a field in an existing note type. - `repositionModelField`: Change the position of a field within an existing note type. ``` -------------------------------- ### Read-Only Mode Environment Variable Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Enabling read-only mode using an environment variable. ```bash READ_ONLY=true ankimcp ``` -------------------------------- ### Read-Only Mode MCP Client Configuration Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Configuring read-only mode within an MCP client configuration file. ```json { "mcpServers": { "anki-mcp": { "command": "npx", "args": ["-y", "@ankimcp/anki-mcp-server", "--stdio", "--read-only"], "env": { "ANKI_CONNECT_URL": "http://localhost:8765" } } } } ``` -------------------------------- ### notesInfo Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Retrieves detailed information about specific notes, including CSS styling. ```APIDOC ## notesInfo ### Description Retrieves detailed information about a list of notes by their IDs, including CSS styling information. ### Parameters - **notes** (array) - Required - A list of note IDs to retrieve information for. ``` -------------------------------- ### Statistics Tools Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Tools for retrieving aggregated statistics and review history analysis. ```APIDOC ## Statistics - `collection_stats`: Aggregated statistics across all decks with per-deck breakdown and collection-wide card-state counts. - `review_stats`: Review history analysis (temporal patterns, retention metrics, study streaks). ``` -------------------------------- ### Configure Debug Server in MCP Inspector Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Configuration for the MCP Inspector to enable Node.js debugging on port 9229. ```json { "mcpServers": { "stdio-server-debug": { "type": "stdio", "command": "node", "args": ["--inspect-brk=9229", "dist/main-stdio.js"], "env": { "MCP_SERVER_NAME": "anki-mcp-stdio-debug", "MCP_SERVER_VERSION": "1.0.0", "LOG_LEVEL": "debug" }, "note": "Anki MCP server with debugging enabled on port 9229" } } } ``` -------------------------------- ### findNotes Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Searches for notes in Anki based on a query string using Anki's query syntax. ```APIDOC ## findNotes ### Description Searches for notes in Anki based on a query string. Supports Anki's query syntax such as deck names, tags, and due status. ### Parameters - **query** (string) - Required - The search query string (e.g., "deck:Spanish") ``` -------------------------------- ### updateNoteFields Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Updates the fields of an existing note. ```APIDOC ## updateNoteFields ### Description Updates the fields of a specific note. Supports HTML content and preserves CSS styling. Note: Do not view the note in Anki's browser while updating. ### Parameters - **note** (object) - Required - An object containing the note 'id' and a 'fields' object with field names and values. ``` -------------------------------- ### Internal Logger Usage Source: https://github.com/ankimcp/anki-mcp-server/blob/main/CLAUDE.md Use the NestJS Logger for internal service logging, debugging, and warnings. This includes timestamps and log levels. ```typescript import { Logger } from '@nestjs/common'; private readonly logger = new Logger(MyService.name); this.logger.log('Info message'); this.logger.warn('Warning message'); this.logger.error('Error message'); this.logger.debug('Debug message'); ``` -------------------------------- ### deleteNotes Source: https://github.com/ankimcp/anki-mcp-server/blob/main/README.md Deletes specified notes from Anki. ```APIDOC ## deleteNotes ### Description Permanently deletes notes and all associated cards. Requires explicit confirmation. ### Parameters - **notes** (array) - Required - A list of note IDs to delete. - **confirmDeletion** (boolean) - Required - Must be set to true to confirm the deletion. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.