@laomeifun/my-anki-mcp 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,783 +1,761 @@
1
- # Anki MCP Server
2
-
3
- > **⚠️ IMPORTANT: Project Renamed (v0.8.2+)**
4
- >
5
- > This project has been renamed and moved:
6
- > - **Package**: `anki-mcp-http` → `@ankimcp/anki-mcp-server`
7
- > - **Commands**: `anki-mcp-http` → `ankimcp` or `anki-mcp-server`
8
- > - **Repository**: `anki-mcp/anki-mcp-desktop` `ankimcp/anki-mcp-server`
9
- >
10
- > The old `anki-mcp-http` package continues to be published for backward compatibility but is deprecated. Please migrate to the new package.
11
- >
12
- > **[Read more about this change →](https://ankimcp.ai/blog/organization-and-naming-update/)**
13
-
14
- [![Tests](https://github.com/ankimcp/anki-mcp-server/actions/workflows/test.yml/badge.svg)](https://github.com/ankimcp/anki-mcp-server/actions/workflows/test.yml)
15
- [![npm version](https://badge.fury.io/js/@ankimcp%2Fanki-mcp-server.svg)](https://www.npmjs.com/package/@ankimcp/anki-mcp-server)
16
-
17
- <div align="center">
18
- <img src="./docs/images/ankimcp.png" alt="Anki + MCP Integration" width="600" />
19
-
20
- <p><strong>Seamlessly integrate <a href="https://apps.ankiweb.net">Anki</a> with AI assistants through the <a href="https://modelcontextprotocol.io">Model Context Protocol</a></strong></p>
21
- </div>
22
-
23
- **Beta** - This project is in active development. APIs and features may change.
24
-
25
- A Model Context Protocol (MCP) server that enables AI assistants to interact with Anki, the spaced repetition flashcard application.
26
-
27
- Transform your Anki experience with natural language interaction - like having a private tutor. The AI assistant doesn't just present questions and answers; it can explain concepts, make the learning process more engaging and human-like, provide context, and adapt to your learning style. It can create and edit notes on the fly, turning your study sessions into dynamic conversations. More features coming soon!
28
-
29
- ## Examples and Tutorials
30
-
31
- For comprehensive guides, real-world examples, and step-by-step tutorials on using this MCP server with Claude Desktop, visit:
32
-
33
- **[ankimcp.ai](https://ankimcp.ai)** - Complete documentation with practical examples and use cases
34
-
35
- ## Available Tools
36
-
37
- ### Review & Study
38
- - `sync` - Sync with AnkiWeb
39
- - `get_due_cards` - Get cards for review
40
- - `present_card` - Show card for review
41
- - `rate_card` - Rate card performance
42
-
43
- ### Deck Management
44
- - `list_decks` - Show available decks
45
- - `createDeck` - Create new decks
46
-
47
- ### Note Management
48
- - `addNote` - Create new notes
49
- - `findNotes` - Search for notes using Anki query syntax
50
- - `notesInfo` - Get detailed information about notes (fields, tags, CSS)
51
- - `updateNoteFields` - Update existing note fields (CSS-aware, supports HTML)
52
- - `deleteNotes` - Delete notes and their cards
53
-
54
- ### Media Management
55
- - `mediaActions` - Manage media files (audio/images)
56
- - `storeMediaFile` - Upload media from base64 data, file paths, or URLs
57
- - `retrieveMediaFile` - Download media as base64
58
- - `getMediaFilesNames` - List media files with optional pattern filtering
59
- - `deleteMediaFile` - Remove media files
60
-
61
- **💡 Best Practice for Images:**
62
- - ✅ **Use file paths** (e.g., `/Users/you/image.png`) - Fast and efficient
63
- - ✅ **Use URLs** (e.g., `https://example.com/image.jpg`) - Direct download
64
- - **Avoid base64** - Extremely slow and token-inefficient
65
-
66
- Just tell Claude where the image is, and it will handle the upload automatically using the most efficient method.
67
-
68
- ### Model/Template Management
69
- - `modelNames` - List note types
70
- - `modelFieldNames` - Get fields for a note type
71
- - `modelStyling` - Get CSS styling for a note type
72
-
73
- ## Prerequisites
74
-
75
- - [Anki](https://apps.ankiweb.net/) with [AnkiConnect](https://github.com/FooSoft/anki-connect) plugin installed
76
- - Node.js 20+
77
-
78
- ## Installation
79
-
80
- This server works in two modes:
81
-
82
- - **Local mode (STDIO)** - For Claude Desktop on your computer (recommended for most users)
83
- - **Remote mode (HTTP)** - For web-based AI assistants like ChatGPT or Claude.ai
84
-
85
- ### Option 1: MCPB Bundle (Recommended - Local Mode)
86
-
87
- The easiest way to install this MCP server for Claude Desktop:
88
-
89
- 1. Download the latest `.mcpb` bundle from the [Releases](https://github.com/ankimcp/anki-mcp-server/releases) page
90
- 2. In Claude Desktop, install the extension:
91
- - **Method 1**: Go to Settings → Extensions, then drag and drop the `.mcpb` file
92
- - **Method 2**: Go to Settings → Developer → Extensions → Install Extension, then select the `.mcpb` file
93
- 3. Configure AnkiConnect URL if needed (defaults to `http://localhost:8765`)
94
- 4. Restart Claude Desktop
95
-
96
- That's it! The bundle includes everything needed to run the server locally.
97
-
98
- ### Option 2: NPM Package with STDIO (For Other MCP Clients)
99
-
100
- Want to use Anki with MCP clients like **Cursor IDE**, **Cline**, or **Zed Editor**? Use the npm package with the `--stdio` flag:
101
-
102
- **Supported Clients:**
103
- - [Cursor IDE](https://www.cursor.com/) - AI-powered code editor
104
- - [Cline](https://github.com/cline/cline) - VS Code extension for AI assistance
105
- - [Zed Editor](https://zed.dev/) - Fast, modern code editor
106
- - Other MCP clients that support STDIO transport
107
-
108
- **Configuration - Choose one method:**
109
-
110
- **Method 1: Using npx (recommended - no installation needed)**
111
-
112
- ```json
113
- {
114
- "mcpServers": {
115
- "anki-mcp": {
116
- "command": "npx",
117
- "args": ["-y", "@ankimcp/anki-mcp-server", "--stdio"],
118
- "env": {
119
- "ANKI_CONNECT_URL": "http://localhost:8765"
120
- }
121
- }
122
- }
123
- }
124
- ```
125
-
126
- **Method 2: Using global installation**
127
-
128
- First, install globally:
129
- ```bash
130
- npm install -g @ankimcp/anki-mcp-server
131
- ```
132
-
133
- Then configure:
134
- ```json
135
- {
136
- "mcpServers": {
137
- "anki-mcp": {
138
- "command": "ankimcp",
139
- "args": ["--stdio"],
140
- "env": {
141
- "ANKI_CONNECT_URL": "http://localhost:8765"
142
- }
143
- }
144
- }
145
- }
146
- ```
147
-
148
- **Configuration file locations:**
149
- - **Cursor IDE**: `~/.cursor/mcp.json` (macOS/Linux) or `%USERPROFILE%\.cursor\mcp.json` (Windows)
150
- - **Cline**: Accessible via settings UI in VS Code
151
- - **Zed Editor**: Install as MCP extension through extension marketplace
152
-
153
- For client-specific features and troubleshooting, consult your MCP client's documentation.
154
-
155
- ### Option 3: HTTP Mode (For Remote AI Assistants)
156
-
157
- Want to use Anki with ChatGPT or Claude.ai in your browser? This mode lets you connect web-based AI tools to your local Anki.
158
-
159
- **How it works (simple explanation):**
160
- 1. You run a small server on your computer (where Anki is installed)
161
- 2. Use the built-in `--ngrok` flag to automatically create a public tunnel URL
162
- 3. Share that URL with ChatGPT or Claude.ai
163
- 4. Now the AI can talk to your Anki through the internet!
164
-
165
- **New in v0.8.0:** Integrated ngrok support with the `--ngrok` flag - no need to run ngrok separately!
166
-
167
- **Setup - Choose one method:**
168
-
169
- **Method 1: Using npx (recommended - no installation needed)**
170
-
171
- ```bash
172
- # Quick start
173
- npx @ankimcp/anki-mcp-server
174
-
175
- # With ngrok tunnel (recommended for web-based AI)
176
- npx @ankimcp/anki-mcp-server --ngrok
177
-
178
- # With custom options
179
- npx @ankimcp/anki-mcp-server --port 8080 --host 0.0.0.0
180
- npx @ankimcp/anki-mcp-server --anki-connect http://localhost:8765
181
- ```
182
-
183
- **Method 2: Using global installation**
184
-
185
- ```bash
186
- # Install once
187
- npm install -g @ankimcp/anki-mcp-server
188
-
189
- # Run the server
190
- ankimcp
191
-
192
- # With ngrok tunnel (recommended for web-based AI)
193
- ankimcp --ngrok
194
-
195
- # With custom options
196
- ankimcp --port 8080 --host 0.0.0.0
197
- ankimcp --anki-connect http://localhost:8765
198
- ```
199
-
200
- **Method 3: Install from source (for development)**
201
-
202
- ```bash
203
- npm install
204
- npm run build
205
- npm run start:prod:http
206
- ```
207
-
208
- **CLI Options:**
209
-
210
- ```bash
211
- ankimcp [options]
212
-
213
- Options:
214
- --stdio Run in STDIO mode (for MCP clients)
215
- -p, --port <port> Port to listen on (HTTP mode, default: 3000)
216
- -h, --host <host> Host to bind to (HTTP mode, default: 127.0.0.1)
217
- -a, --anki-connect <url> AnkiConnect URL (default: http://localhost:8765)
218
- --ngrok Start ngrok tunnel (requires global ngrok installation)
219
- --help Show help message
220
-
221
- Usage with npx (no installation needed):
222
- npx @ankimcp/anki-mcp-server # HTTP mode
223
- npx @ankimcp/anki-mcp-server --port 8080 # Custom port
224
- npx @ankimcp/anki-mcp-server --stdio # STDIO mode
225
- npx @ankimcp/anki-mcp-server --ngrok # HTTP mode with ngrok tunnel
226
-
227
- Usage with global installation:
228
- npm install -g @ankimcp/anki-mcp-server # Install once
229
- ankimcp # HTTP mode
230
- ankimcp --port 8080 # Custom port
231
- ankimcp --stdio # STDIO mode
232
- ankimcp --ngrok # HTTP mode with ngrok tunnel
233
- ```
234
-
235
- **Using with ngrok:**
236
-
237
- **Method 1: Integrated (Recommended - One Command)**
238
-
239
- ```bash
240
- # One-time setup (if you haven't already):
241
- npm install -g ngrok
242
- ngrok config add-authtoken <your-token> # Get token from https://dashboard.ngrok.com
243
-
244
- # Start server with ngrok tunnel in one command:
245
- ankimcp --ngrok
246
-
247
- # The tunnel URL will be displayed in the startup banner
248
- # Example output:
249
- # 🌐 Ngrok tunnel: https://abc123.ngrok-free.app
250
- ```
251
-
252
- **Method 2: Manual (Two Terminals)**
253
-
254
- ```bash
255
- # Terminal 1: Start the server
256
- ankimcp
257
-
258
- # Terminal 2: Create tunnel
259
- ngrok http 3000
260
-
261
- # Copy the ngrok URL (looks like: https://abc123.ngrok-free.app)
262
- # Share this URL with your AI assistant
263
- ```
264
-
265
- **Benefits of `--ngrok` flag:**
266
- - One command instead of two terminals
267
- - ✅ Automatic cleanup when you press Ctrl+C
268
- - URL displayed directly in the startup banner
269
- - Works with custom ports: `ankimcp --port 8080 --ngrok`
270
-
271
- **Security note:** Anyone with your ngrok URL can access your Anki, so keep that URL private!
272
-
273
- ### Option 4: Manual Installation from Source (Local Mode)
274
-
275
- For development or advanced usage:
276
-
277
- ```bash
278
- npm install
279
- npm run build
280
- ```
281
-
282
- ## Connect to Claude Desktop (Local Mode)
283
-
284
- You can configure the server in Claude Desktop by either:
285
- - Going to: Settings → Developer → Edit Config
286
- - Or manually editing the config file
287
-
288
- ### Configuration
289
-
290
- Add the following to your Claude Desktop config:
291
-
292
- ```json
293
- {
294
- "mcpServers": {
295
- "anki-mcp": {
296
- "command": "node",
297
- "args": ["/path/to/anki-mcp-server/dist/main-stdio.js"],
298
- "env": {
299
- "ANKI_CONNECT_URL": "http://localhost:8765"
300
- }
301
- }
302
- }
303
- }
304
- ```
305
-
306
- Replace `/path/to/anki-mcp-server` with your actual project path.
307
-
308
- ### Config File Locations
309
-
310
- - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
311
- - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
312
- - **Linux**: `~/.config/Claude/claude_desktop_config.json`
313
-
314
- For more details, see the [official MCP documentation](https://modelcontextprotocol.io/docs/develop/connect-local-servers).
315
-
316
- ## Environment Variables (Optional)
317
-
318
- | Variable | Description | Default |
319
- |----------|-------------|---------|
320
- | `ANKI_CONNECT_URL` | AnkiConnect URL | `http://localhost:8765` |
321
- | `ANKI_CONNECT_API_VERSION` | API version | `6` |
322
- | `ANKI_CONNECT_API_KEY` | API key if configured in AnkiConnect | - |
323
- | `ANKI_CONNECT_TIMEOUT` | Request timeout in ms | `5000` |
324
-
325
- ## Usage Examples
326
-
327
- ### Searching and Updating Notes
328
-
329
- ```
330
- # Search for notes in a specific deck
331
- findNotes(query: "deck:Spanish")
332
-
333
- # Get detailed information about notes
334
- notesInfo(notes: [1234567890, 1234567891])
335
-
336
- # Update a note's fields (HTML content supported)
337
- updateNoteFields(note: {
338
- id: 1234567890,
339
- fields: {
340
- "Front": "<b>¿Cómo estás?</b>",
341
- "Back": "How are you?"
342
- }
343
- })
344
-
345
- # Delete notes (requires confirmation)
346
- deleteNotes(notes: [1234567890], confirmDeletion: true)
347
- ```
348
-
349
- ### Anki Query Syntax Examples
350
-
351
- The `findNotes` tool supports Anki's powerful query syntax:
352
-
353
- - `"deck:DeckName"` - All notes in a specific deck
354
- - `"tag:important"` - Notes with the "important" tag
355
- - `"is:due"` - Cards that are due for review
356
- - `"is:new"` - New cards that haven't been studied
357
- - `"added:7"` - Notes added in the last 7 days
358
- - `"front:hello"` - Notes with "hello" in the front field
359
- - `"flag:1"` - Notes with red flag
360
- - `"prop:due<=2"` - Cards due within 2 days
361
- - `"deck:Spanish tag:verb"` - Spanish deck notes with verb tag (AND)
362
- - `"deck:Spanish OR deck:French"` - Notes from either deck
363
-
364
- ### Important Notes
365
-
366
- #### CSS and HTML Handling
367
- - The `notesInfo` tool returns CSS styling information for proper rendering awareness
368
- - The `updateNoteFields` tool supports HTML content in fields and preserves CSS styling
369
- - Each note model has its own CSS styling - use `modelStyling` to get model-specific CSS
370
-
371
- #### Update Warning
372
- ⚠️ **IMPORTANT**: When using `updateNoteFields`, do NOT view the note in Anki's browser while updating, or the fields will not update properly. Close the browser or switch to a different note before updating. See [Known Issues](#known-issues) for more details.
373
-
374
- #### Deletion Safety
375
- The `deleteNotes` tool requires explicit confirmation (`confirmDeletion: true`) to prevent accidental deletions. Deleting a note removes ALL associated cards permanently.
376
-
377
- ## Known Issues
378
-
379
- For a comprehensive list of known issues and limitations, please visit our documentation:
380
-
381
- **[Known Issues Documentation](https://ankimcp.ai/docs/known-issues/)**
382
-
383
- ### Critical Limitations
384
-
385
- #### Note Updates Fail When Viewed in Browser
386
- ⚠️ **IMPORTANT**: When updating notes using `updateNoteFields`, the update will silently fail if the note is currently being viewed in Anki's browser window. This is an upstream AnkiConnect limitation.
387
-
388
- **Workaround**: Always close the browser or navigate to a different note before updating.
389
-
390
- For more details and other known issues, see the [full documentation](https://ankimcp.ai/docs/known-issues/).
391
-
392
- ## Development
393
-
394
- ### Transport Modes
395
-
396
- This server supports two MCP transport modes via **separate entry points**:
397
-
398
- #### STDIO Mode (Default)
399
- - For local MCP clients like Claude Desktop
400
- - Uses standard input/output for communication
401
- - **Entry point**: `dist/main-stdio.js`
402
- - **Run**: `npm run start:prod:stdio` or `node dist/main-stdio.js`
403
- - **MCPB bundle**: Uses STDIO mode
404
-
405
- #### HTTP Mode (Streamable HTTP)
406
- - For remote MCP clients and web-based integrations
407
- - Uses MCP Streamable HTTP protocol
408
- - **Entry point**: `dist/main-http.js`
409
- - **Run**: `npm run start:prod:http` or `node dist/main-http.js`
410
- - **Default port**: 3000 (configurable via `PORT` env var)
411
- - **Default host**: `127.0.0.1` (configurable via `HOST` env var)
412
- - **MCP endpoint**: `http://127.0.0.1:3000/` (root path)
413
-
414
- #### Building
415
-
416
- ```bash
417
- npm run build # Builds once, creates dist/ with both entry points
418
- ```
419
-
420
- Both `main-stdio.js` and `main-http.js` are in the same `dist/` directory. Choose which to run based on your needs.
421
-
422
- #### HTTP Mode Configuration
423
-
424
- **Environment Variables:**
425
- - `PORT` - HTTP server port (default: 3000)
426
- - `HOST` - Bind address (default: 127.0.0.1 for localhost-only)
427
- - `ALLOWED_ORIGINS` - Comma-separated list of allowed origins for CORS (default: localhost)
428
- - `LOG_LEVEL` - Logging level (default: info)
429
-
430
- **Security:**
431
- - Origin header validation (prevents DNS rebinding attacks)
432
- - Binds to localhost (127.0.0.1) by default
433
- - No authentication in current version (OAuth support planned)
434
-
435
- **Example: Running Modes**
436
- ```bash
437
- # Development - STDIO mode (watch mode with auto-rebuild)
438
- npm run start:dev:stdio
439
-
440
- # Development - HTTP mode (watch mode with auto-rebuild)
441
- npm run start:dev:http
442
-
443
- # Production - STDIO mode
444
- npm run start:prod:stdio
445
- # or
446
- node dist/main-stdio.js
447
-
448
- # Production - HTTP mode
449
- npm run start:prod:http
450
- # or
451
- PORT=8080 HOST=0.0.0.0 node dist/main-http.js
452
- ```
453
-
454
- ### Building an MCPB Bundle
455
-
456
- To create a distributable MCPB bundle:
457
-
458
- ```bash
459
- npm run mcpb:bundle
460
- ```
461
-
462
- This command will:
463
- 1. Sync version from `package.json` to `manifest.json`
464
- 2. Remove old `.mcpb` files
465
- 3. Build the TypeScript project
466
- 4. Package `dist/` and `node_modules/` into an `.mcpb` file
467
- 5. Run `mcpb clean` to remove devDependencies (optimizes bundle from ~47MB to ~10MB)
468
-
469
- The output file will be named `anki-mcp-server-X.X.X.mcpb` and can be distributed for one-click installation.
470
-
471
- #### What Gets Bundled
472
-
473
- The MCPB package includes:
474
- - Compiled JavaScript (`dist/` directory - includes both entry points)
475
- - Production dependencies only (`node_modules/` - devDependencies removed by `mcpb clean`)
476
- - Package metadata (`package.json`)
477
- - Manifest configuration (`manifest.json` - configured to use `main-stdio.js`)
478
- - Icon (`icon.png`)
479
-
480
- Source files, tests, and development configs are automatically excluded via `.mcpbignore`.
481
-
482
- ### Logging in Claude Desktop
483
-
484
- When running as an MCPB extension in Claude Desktop, logs are written to:
485
-
486
- **Log Location**: `~/Library/Logs/Claude/` (macOS)
487
-
488
- The logs are split across multiple files:
489
- - **main.log** - General Claude Desktop application logs
490
- - **mcp-server-Anki MCP Server.log** - MCP protocol messages for this extension
491
- - **mcp.log** - Combined MCP logs from all servers
492
-
493
- **Note**: The pino logger output (INFO, ERROR, WARN messages from the server code) goes to stderr and appears in the MCP-specific log files. Claude Desktop determines which log file receives which messages, but generally:
494
- - Application startup and MCP protocol communication → MCP-specific log
495
- - Server internal logging (pino) → Both MCP-specific log and sometimes main.log
496
-
497
- To view logs in real-time:
498
- ```bash
499
- tail -f ~/Library/Logs/Claude/mcp-server-Anki\ MCP\ Server.log
500
- ```
501
-
502
- ### Debugging the MCP Server
503
-
504
- You can debug the MCP server using the MCP Inspector and attaching a debugger from your IDE (WebStorm, VS Code, etc.).
505
-
506
- **Note for HTTP Mode:** When testing HTTP mode (Streamable HTTP) with MCP Inspector, use "Connection Type: Via Proxy" to avoid CORS errors.
507
-
508
- #### Step 1: Configure Debug Server in MCP Inspector
509
-
510
- The `mcp-inspector-config.json` already includes a debug server configuration:
511
-
512
- ```json
513
- {
514
- "mcpServers": {
515
- "stdio-server-debug": {
516
- "type": "stdio",
517
- "command": "node",
518
- "args": ["--inspect-brk=9229", "dist/main-stdio.js"],
519
- "env": {
520
- "MCP_SERVER_NAME": "anki-mcp-stdio-debug",
521
- "MCP_SERVER_VERSION": "1.0.0",
522
- "LOG_LEVEL": "debug"
523
- },
524
- "note": "Anki MCP server with debugging enabled on port 9229"
525
- }
526
- }
527
- }
528
- ```
529
-
530
- #### Step 2: Start the Debug Server
531
-
532
- Run the MCP Inspector with the debug server:
533
-
534
- ```bash
535
- npm run inspector:debug
536
- ```
537
-
538
- This will start the server with Node.js debugging enabled on port 9229 and pause execution at the first line.
539
-
540
- #### Step 3: Attach Debugger from Your IDE
541
-
542
- ##### WebStorm
543
- 1. Go to **Run Edit Configurations**
544
- 2. Add a new **Attach to Node.js/Chrome** configuration
545
- 3. Set the port to `9229`
546
- 4. Click **Debug** to attach
547
-
548
- ##### VS Code
549
- 1. Open the Debug panel (Ctrl+Shift+D / Cmd+Shift+D)
550
- 2. Select **Debug MCP Server (Attach)** configuration
551
- 3. Press F5 to attach
552
-
553
- #### Step 4: Set Breakpoints and Debug
554
-
555
- Once attached, you can:
556
- - Set breakpoints in your TypeScript source files
557
- - Step through code execution
558
- - Inspect variables and call stack
559
- - Use the debug console for evaluating expressions
560
-
561
- The debugger will work with source maps, allowing you to debug the original TypeScript code rather than the compiled JavaScript.
562
-
563
- ### Debugging with Claude Desktop
564
-
565
- You can also debug the MCP server while it runs inside Claude Desktop by enabling the Node.js debugger and attaching your IDE.
566
-
567
- #### Step 1: Configure Claude Desktop for Debugging
568
-
569
- Update your Claude Desktop config to enable debugging:
570
-
571
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
572
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
573
- **Linux**: `~/.config/Claude/claude_desktop_config.json`
574
-
575
- ```json
576
- {
577
- "mcpServers": {
578
- "anki-mcp": {
579
- "command": "node",
580
- "args": [
581
- "--inspect=9229",
582
- "<path_to_project>/anki-mcp-server/dist/main-stdio.js"
583
- ],
584
- "env": {
585
- "ANKI_CONNECT_URL": "http://localhost:8765"
586
- }
587
- }
588
- }
589
- }
590
- ```
591
-
592
- **Key change**: Add `--inspect=9229` before the path to `dist/main-stdio.js`
593
-
594
- **Debug options**:
595
- - `--inspect=9229` - Start debugger immediately, doesn't block (recommended)
596
- - `--inspect-brk=9229` - Pause execution until debugger attaches (for debugging startup issues)
597
-
598
- #### Step 2: Restart Claude Desktop
599
-
600
- After saving the config, restart Claude Desktop. The MCP server will now run with debugging enabled on port 9229.
601
-
602
- #### Step 3: Attach Debugger from Your IDE
603
-
604
- ##### WebStorm
605
-
606
- 1. Go to **Run → Edit Configurations**
607
- 2. Click the **+** button and select **Attach to Node.js/Chrome**
608
- 3. Configure:
609
- - **Name**: `Attach to Anki MCP (Claude Desktop)`
610
- - **Host**: `localhost`
611
- - **Port**: `9229`
612
- - **Attach to**: `Node.js < 8` or `Chrome or Node.js > 6.3` (depending on WebStorm version)
613
- 4. Click **OK**
614
- 5. Click **Debug** (Shift+F9) to attach
615
-
616
- ##### VS Code
617
-
618
- 1. Add to `.vscode/launch.json`:
619
-
620
- ```json
621
- {
622
- "version": "0.2.0",
623
- "configurations": [
624
- {
625
- "type": "node",
626
- "request": "attach",
627
- "name": "Attach to Anki MCP (Claude Desktop)",
628
- "port": 9229,
629
- "skipFiles": ["<node_internals>/**"],
630
- "sourceMaps": true,
631
- "outFiles": ["${workspaceFolder}/dist/**/*.js"]
632
- }
633
- ]
634
- }
635
- ```
636
-
637
- 2. Open the Debug panel (Ctrl+Shift+D / Cmd+Shift+D)
638
- 3. Select **Attach to Anki MCP (Claude Desktop)**
639
- 4. Press F5 to attach
640
-
641
- #### Step 4: Debug in Real-Time
642
-
643
- Once attached, you can:
644
- - Set breakpoints in your TypeScript source files (e.g., `src/mcp/primitives/essential/tools/create-model.tool.ts`)
645
- - Use Claude Desktop normally - breakpoints will hit when tools are invoked
646
- - Step through code execution
647
- - Inspect variables and call stack
648
- - Use the debug console
649
-
650
- **Example**: Set a breakpoint in `create-model.tool.ts` at line 119, then ask Claude to create a new model. The debugger will pause at your breakpoint!
651
-
652
- **Note**: The debugger stays attached as long as Claude Desktop is running. You can detach/reattach anytime without restarting Claude Desktop.
653
-
654
- ### Build Commands
655
-
656
- ```bash
657
- npm run build # Build the project (compile TypeScript to JavaScript)
658
- npm run start:dev:stdio # STDIO mode with watch (auto-rebuild)
659
- npm run start:dev:http # HTTP mode with watch (auto-rebuild)
660
- npm run type-check # Run TypeScript type checking
661
- npm run lint # Run ESLint
662
- npm run mcpb:bundle # Sync version, clean, build, and create MCPB bundle
663
- ```
664
-
665
- ### NPM Package Testing (Local)
666
-
667
- Test the npm package locally before publishing:
668
-
669
- ```bash
670
- # 1. Create local package
671
- npm run pack:local # Builds and creates @ankimcp/anki-mcp-server-*.tgz
672
-
673
- # 2. Install globally from local package
674
- npm run install:local # Installs from ./@ankimcp/anki-mcp-server-*.tgz
675
-
676
- # 3. Test the command
677
- ankimcp # Runs HTTP server on port 3000
678
-
679
- # 4. Uninstall when done testing
680
- npm run uninstall:local # Removes global installation
681
- ```
682
-
683
- **How it works:**
684
- - `npm pack` creates a `.tgz` file identical to what npm publish would create
685
- - Installing from `.tgz` simulates what users get from `npm install -g ankimcp`
686
- - This lets you test the full user experience before publishing to npm
687
-
688
- ### Testing Commands
689
-
690
- ```bash
691
- npm test # Run all tests
692
- npm run test:unit # Run unit tests only
693
- npm run test:tools # Run tool-specific tests
694
- npm run test:workflows # Run workflow integration tests
695
- npm run test:e2e # Run end-to-end tests
696
- npm run test:cov # Run tests with coverage report
697
- npm run test:watch # Run tests in watch mode
698
- npm run test:debug # Run tests with debugger
699
- npm run test:ci # Run tests for CI (silent, with coverage)
700
- ```
701
-
702
- ### Test Coverage
703
-
704
- The project maintains 70% minimum coverage thresholds for:
705
- - Branches
706
- - Functions
707
- - Lines
708
- - Statements
709
-
710
- Coverage reports are generated in the `coverage/` directory.
711
-
712
- ## Versioning
713
-
714
- This project follows [Semantic Versioning](https://semver.org/) with a pre-1.0 development approach:
715
-
716
- - **0.x.x** - Beta/Development versions (current phase)
717
- - **0.1.x** - Bug fixes and patches
718
- - **0.2.0+** - New features or minor improvements
719
- - **Breaking changes** are acceptable in 0.x versions
720
-
721
- - **1.0.0** - First stable release
722
- - Will be released when the API is stable and tested
723
- - Breaking changes will require major version bumps (2.0.0, etc.)
724
-
725
- **Current Status**: `0.8.0` - Active beta development. New features include integrated ngrok tunneling (`--ngrok` flag), the `twenty_rules` prompt for evidence-based flashcard creation, media file management, and improved prompt system. APIs may change based on feedback and testing.
726
-
727
- ## Similar Projects
728
-
729
- If you're exploring Anki MCP integrations, here are other projects in this space:
730
-
731
- ### [scorzeth/anki-mcp-server](https://github.com/scorzeth/anki-mcp-server)
732
- - **Status**: Appears to be abandoned (no recent updates)
733
- - Early implementation of Anki MCP integration
734
-
735
- ### [nailuoGG/anki-mcp-server](https://github.com/nailuoGG/anki-mcp-server)
736
- - **Approach**: Lightweight, single-file implementation
737
- - **Architecture**: Procedural code structure with all tools in one file
738
- - **Good for**: Simple use cases, minimal dependencies
739
-
740
- **Why this project differs:**
741
- - **Enterprise-grade architecture**: Built on NestJS with dependency injection
742
- - **Modular design**: Each tool is a separate class with clear separation of concerns
743
- - **Maintainability**: Easy to extend with new features without touching existing code
744
- - **Testing**: Comprehensive test suite with 70% coverage requirement
745
- - **Type safety**: Strict TypeScript with Zod validation
746
- - **Error handling**: Robust error handling with helpful user feedback
747
- - **Production-ready**: Proper logging, progress reporting, and MCPB bundle support
748
- - **Scalability**: Can easily grow from basic tools to complex workflows
749
-
750
- **Use case**: If you need a solid foundation for building advanced Anki integrations or plan to extend functionality significantly, this project's architectural approach makes it easier to maintain and scale over time.
751
-
752
- ## Useful Links
753
-
754
- - [Model Context Protocol Documentation](https://modelcontextprotocol.io/docs)
755
- - [AnkiConnect API Documentation](https://git.sr.ht/~foosoft/anki-connect)
756
- - [Claude Desktop Download](https://claude.ai/download)
757
- - [Building Desktop Extensions (Anthropic Blog)](https://www.anthropic.com/engineering/desktop-extensions)
758
- - [MCP Servers Repository](https://github.com/modelcontextprotocol/servers)
759
- - [NestJS Documentation](https://docs.nestjs.com)
760
- - [Anki Official Website](https://apps.ankiweb.net/)
761
-
762
- ## License & Attribution
763
-
764
- This project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later).
765
-
766
- ### Why AGPL-3.0?
767
-
768
- This license was chosen to maintain compatibility with Anki's AGPL-3.0 license for potential future integration scenarios.
769
-
770
- **What this means:**
771
- - **Personal use**: Use the software freely
772
- - **Running as a service for others**: You must provide source code access (AGPL Section 13)
773
- - **Modifying and distributing**: Share your improvements under AGPL-3.0-or-later
774
-
775
- For complete license terms, see the [LICENSE](LICENSE) file.
776
-
777
- ### Third-Party Attributions
778
-
779
- - **Anki®** is a registered trademark of Ankitects Pty Ltd. This project is an unofficial third-party tool and is not affiliated with, endorsed by, or sponsored by Ankitects Pty Ltd. The Anki logo is used under the alternative license for referencing Anki with a link to [https://apps.ankiweb.net](https://apps.ankiweb.net). For the official Anki application, visit [https://apps.ankiweb.net](https://apps.ankiweb.net).
780
-
781
- - **Model Context Protocol (MCP)** is an open standard by Anthropic. The MCP logo is from the official [MCP documentation repository](https://github.com/modelcontextprotocol/docs) and is used under the MIT License. For more information about MCP, visit [https://modelcontextprotocol.io](https://modelcontextprotocol.io).
782
-
1
+ # My Anki MCP
2
+
3
+ A Model Context Protocol (MCP) server for Anki - enables AI assistants to interact with your Anki flashcards.
4
+
5
+ [![npm version](https://badge.fury.io/js/@laomeifun%2Fmy-anki-mcp.svg)](https://www.npmjs.com/package/@laomeifun/my-anki-mcp)
6
+
7
+ <div align="center">
8
+ <img src="./docs/images/ankimcp.png" alt="Anki + MCP Integration" width="600" />
9
+
10
+ <p><strong>Seamlessly integrate <a href="https://apps.ankiweb.net">Anki</a> with AI assistants through the <a href="https://modelcontextprotocol.io">Model Context Protocol</a></strong></p>
11
+ </div>
12
+
13
+ **Beta** - This project is in active development. APIs and features may change.
14
+
15
+ A Model Context Protocol (MCP) server that enables AI assistants to interact with Anki, the spaced repetition flashcard application.
16
+
17
+ Transform your Anki experience with natural language interaction.
18
+
19
+ ## Available Tools
20
+
21
+ ### Review & Study
22
+ - `sync` - Sync with AnkiWeb
23
+ - `get_due_cards` - Get cards for review
24
+ - `present_card` - Show card for review
25
+ - `rate_card` - Rate card performance
26
+
27
+ ### Deck Management
28
+ - `list_decks` - Show available decks
29
+ - `createDeck` - Create new decks
30
+
31
+ ### Note Management
32
+ - `addNote` - Create new notes
33
+ - `findNotes` - Search for notes using Anki query syntax
34
+ - `notesInfo` - Get detailed information about notes (fields, tags, CSS)
35
+ - `updateNoteFields` - Update existing note fields (CSS-aware, supports HTML)
36
+ - `deleteNotes` - Delete notes and their cards
37
+
38
+ ### Media Management
39
+ - `mediaActions` - Manage media files (audio/images)
40
+ - `storeMediaFile` - Upload media from base64 data, file paths, or URLs
41
+ - `retrieveMediaFile` - Download media as base64
42
+ - `getMediaFilesNames` - List media files with optional pattern filtering
43
+ - `deleteMediaFile` - Remove media files
44
+
45
+ **💡 Best Practice for Images:**
46
+ - ✅ **Use file paths** (e.g., `/Users/you/image.png`) - Fast and efficient
47
+ - **Use URLs** (e.g., `https://example.com/image.jpg`) - Direct download
48
+ - **Avoid base64** - Extremely slow and token-inefficient
49
+
50
+ Just tell Claude where the image is, and it will handle the upload automatically using the most efficient method.
51
+
52
+ ### Model/Template Management
53
+ - `modelNames` - List note types
54
+ - `modelFieldNames` - Get fields for a note type
55
+ - `modelStyling` - Get CSS styling for a note type
56
+
57
+ ## Prerequisites
58
+
59
+ - [Anki](https://apps.ankiweb.net/) with [AnkiConnect](https://github.com/FooSoft/anki-connect) plugin installed
60
+ - Node.js 20+
61
+
62
+ ## Installation
63
+
64
+ This server works in two modes:
65
+
66
+ - **Local mode (STDIO)** - For Claude Desktop on your computer (recommended for most users)
67
+ - **Remote mode (HTTP)** - For web-based AI assistants like ChatGPT or Claude.ai
68
+
69
+ ### Option 1: MCPB Bundle (Recommended - Local Mode)
70
+
71
+ The easiest way to install this MCP server for Claude Desktop:
72
+
73
+ 1. Download the latest `.mcpb` bundle from the [Releases](https://github.com/laomeifun/my-anki-mcp/releases) page
74
+ 2. In Claude Desktop, install the extension:
75
+ - **Method 1**: Go to Settings → Extensions, then drag and drop the `.mcpb` file
76
+ - **Method 2**: Go to Settings → Developer → Extensions → Install Extension, then select the `.mcpb` file
77
+ 3. Configure AnkiConnect URL if needed (defaults to `http://localhost:8765`)
78
+ 4. Restart Claude Desktop
79
+
80
+ That's it! The bundle includes everything needed to run the server locally.
81
+
82
+ ### Option 2: NPM Package with STDIO (For Other MCP Clients)
83
+
84
+ Want to use Anki with MCP clients like **Cursor IDE**, **Cline**, or **Zed Editor**? Use the npm package with the `--stdio` flag:
85
+
86
+ **Supported Clients:**
87
+ - [Cursor IDE](https://www.cursor.com/) - AI-powered code editor
88
+ - [Cline](https://github.com/cline/cline) - VS Code extension for AI assistance
89
+ - [Zed Editor](https://zed.dev/) - Fast, modern code editor
90
+ - Other MCP clients that support STDIO transport
91
+
92
+ **Configuration - Choose one method:**
93
+
94
+ **Method 1: Using npx (recommended - no installation needed)**
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "anki-mcp": {
100
+ "command": "npx",
101
+ "args": ["-y", "@laomeifun/my-anki-mcp", "--stdio"],
102
+ "env": {
103
+ "ANKI_CONNECT_URL": "http://localhost:8765"
104
+ }
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ **Method 2: Using global installation**
111
+
112
+ First, install globally:
113
+ ```bash
114
+ npm install -g @laomeifun/my-anki-mcp
115
+ ```
116
+
117
+ Then configure:
118
+ ```json
119
+ {
120
+ "mcpServers": {
121
+ "anki-mcp": {
122
+ "command": "ankimcp",
123
+ "args": ["--stdio"],
124
+ "env": {
125
+ "ANKI_CONNECT_URL": "http://localhost:8765"
126
+ }
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ **Configuration file locations:**
133
+ - **Cursor IDE**: `~/.cursor/mcp.json` (macOS/Linux) or `%USERPROFILE%\.cursor\mcp.json` (Windows)
134
+ - **Cline**: Accessible via settings UI in VS Code
135
+ - **Zed Editor**: Install as MCP extension through extension marketplace
136
+
137
+ For client-specific features and troubleshooting, consult your MCP client's documentation.
138
+
139
+ ### Option 3: HTTP Mode (For Remote AI Assistants)
140
+
141
+ Want to use Anki with ChatGPT or Claude.ai in your browser? This mode lets you connect web-based AI tools to your local Anki.
142
+
143
+ **How it works (simple explanation):**
144
+ 1. You run a small server on your computer (where Anki is installed)
145
+ 2. Use the built-in `--ngrok` flag to automatically create a public tunnel URL
146
+ 3. Share that URL with ChatGPT or Claude.ai
147
+ 4. Now the AI can talk to your Anki through the internet!
148
+
149
+ **New in v0.8.0:** Integrated ngrok support with the `--ngrok` flag - no need to run ngrok separately!
150
+
151
+ **Setup - Choose one method:**
152
+
153
+ **Method 1: Using npx (recommended - no installation needed)**
154
+
155
+ ```bash
156
+ # Quick start
157
+ npx @laomeifun/my-anki-mcp
158
+
159
+ # With ngrok tunnel (recommended for web-based AI)
160
+ npx @laomeifun/my-anki-mcp --ngrok
161
+
162
+ # With custom options
163
+ npx @laomeifun/my-anki-mcp --port 8080 --host 0.0.0.0
164
+ npx @laomeifun/my-anki-mcp --anki-connect http://localhost:8765
165
+ ```
166
+
167
+ **Method 2: Using global installation**
168
+
169
+ ```bash
170
+ # Install once
171
+ npm install -g @laomeifun/my-anki-mcp
172
+
173
+ # Run the server
174
+ ankimcp
175
+
176
+ # With ngrok tunnel (recommended for web-based AI)
177
+ ankimcp --ngrok
178
+
179
+ # With custom options
180
+ ankimcp --port 8080 --host 0.0.0.0
181
+ ankimcp --anki-connect http://localhost:8765
182
+ ```
183
+
184
+ **Method 3: Install from source (for development)**
185
+
186
+ ```bash
187
+ npm install
188
+ npm run build
189
+ npm run start:prod:http
190
+ ```
191
+
192
+ **CLI Options:**
193
+
194
+ ```bash
195
+ ankimcp [options]
196
+
197
+ Options:
198
+ --stdio Run in STDIO mode (for MCP clients)
199
+ -p, --port <port> Port to listen on (HTTP mode, default: 3000)
200
+ -h, --host <host> Host to bind to (HTTP mode, default: 127.0.0.1)
201
+ -a, --anki-connect <url> AnkiConnect URL (default: http://localhost:8765)
202
+ --ngrok Start ngrok tunnel (requires global ngrok installation)
203
+ --help Show help message
204
+
205
+ Usage with npx (no installation needed):
206
+ npx @laomeifun/my-anki-mcp # HTTP mode
207
+ npx @laomeifun/my-anki-mcp --port 8080 # Custom port
208
+ npx @laomeifun/my-anki-mcp --stdio # STDIO mode
209
+ npx @laomeifun/my-anki-mcp --ngrok # HTTP mode with ngrok tunnel
210
+
211
+ Usage with global installation:
212
+ npm install -g @laomeifun/my-anki-mcp # Install once
213
+ ankimcp # HTTP mode
214
+ ankimcp --port 8080 # Custom port
215
+ ankimcp --stdio # STDIO mode
216
+ ankimcp --ngrok # HTTP mode with ngrok tunnel
217
+ ```
218
+
219
+ **Using with ngrok:**
220
+
221
+ **Method 1: Integrated (Recommended - One Command)**
222
+
223
+ ```bash
224
+ # One-time setup (if you haven't already):
225
+ npm install -g ngrok
226
+ ngrok config add-authtoken <your-token> # Get token from https://dashboard.ngrok.com
227
+
228
+ # Start server with ngrok tunnel in one command:
229
+ ankimcp --ngrok
230
+
231
+ # The tunnel URL will be displayed in the startup banner
232
+ # Example output:
233
+ # 🌐 Ngrok tunnel: https://abc123.ngrok-free.app
234
+ ```
235
+
236
+ **Method 2: Manual (Two Terminals)**
237
+
238
+ ```bash
239
+ # Terminal 1: Start the server
240
+ ankimcp
241
+
242
+ # Terminal 2: Create tunnel
243
+ ngrok http 3000
244
+
245
+ # Copy the ngrok URL (looks like: https://abc123.ngrok-free.app)
246
+ # Share this URL with your AI assistant
247
+ ```
248
+
249
+ **Benefits of `--ngrok` flag:**
250
+ - ✅ One command instead of two terminals
251
+ - ✅ Automatic cleanup when you press Ctrl+C
252
+ - URL displayed directly in the startup banner
253
+ - ✅ Works with custom ports: `ankimcp --port 8080 --ngrok`
254
+
255
+ **Security note:** Anyone with your ngrok URL can access your Anki, so keep that URL private!
256
+
257
+ ### Option 4: Manual Installation from Source (Local Mode)
258
+
259
+ For development or advanced usage:
260
+
261
+ ```bash
262
+ npm install
263
+ npm run build
264
+ ```
265
+
266
+ ## Connect to Claude Desktop (Local Mode)
267
+
268
+ You can configure the server in Claude Desktop by either:
269
+ - Going to: Settings Developer Edit Config
270
+ - Or manually editing the config file
271
+
272
+ ### Configuration
273
+
274
+ Add the following to your Claude Desktop config:
275
+
276
+ ```json
277
+ {
278
+ "mcpServers": {
279
+ "anki-mcp": {
280
+ "command": "node",
281
+ "args": ["/path/to/anki-mcp-server/dist/main-stdio.js"],
282
+ "env": {
283
+ "ANKI_CONNECT_URL": "http://localhost:8765"
284
+ }
285
+ }
286
+ }
287
+ }
288
+ ```
289
+
290
+ Replace `/path/to/anki-mcp-server` with your actual project path.
291
+
292
+ ### Config File Locations
293
+
294
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
295
+ - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
296
+ - **Linux**: `~/.config/Claude/claude_desktop_config.json`
297
+
298
+ For more details, see the [official MCP documentation](https://modelcontextprotocol.io/docs/develop/connect-local-servers).
299
+
300
+ ## Environment Variables (Optional)
301
+
302
+ | Variable | Description | Default |
303
+ |----------|-------------|---------|
304
+ | `ANKI_CONNECT_URL` | AnkiConnect URL | `http://localhost:8765` |
305
+ | `ANKI_CONNECT_API_VERSION` | API version | `6` |
306
+ | `ANKI_CONNECT_API_KEY` | API key if configured in AnkiConnect | - |
307
+ | `ANKI_CONNECT_TIMEOUT` | Request timeout in ms | `5000` |
308
+
309
+ ## Usage Examples
310
+
311
+ ### Searching and Updating Notes
312
+
313
+ ```
314
+ # Search for notes in a specific deck
315
+ findNotes(query: "deck:Spanish")
316
+
317
+ # Get detailed information about notes
318
+ notesInfo(notes: [1234567890, 1234567891])
319
+
320
+ # Update a note's fields (HTML content supported)
321
+ updateNoteFields(note: {
322
+ id: 1234567890,
323
+ fields: {
324
+ "Front": "<b>¿Cómo estás?</b>",
325
+ "Back": "How are you?"
326
+ }
327
+ })
328
+
329
+ # Delete notes (requires confirmation)
330
+ deleteNotes(notes: [1234567890], confirmDeletion: true)
331
+ ```
332
+
333
+ ### Anki Query Syntax Examples
334
+
335
+ The `findNotes` tool supports Anki's powerful query syntax:
336
+
337
+ - `"deck:DeckName"` - All notes in a specific deck
338
+ - `"tag:important"` - Notes with the "important" tag
339
+ - `"is:due"` - Cards that are due for review
340
+ - `"is:new"` - New cards that haven't been studied
341
+ - `"added:7"` - Notes added in the last 7 days
342
+ - `"front:hello"` - Notes with "hello" in the front field
343
+ - `"flag:1"` - Notes with red flag
344
+ - `"prop:due<=2"` - Cards due within 2 days
345
+ - `"deck:Spanish tag:verb"` - Spanish deck notes with verb tag (AND)
346
+ - `"deck:Spanish OR deck:French"` - Notes from either deck
347
+
348
+ ### Important Notes
349
+
350
+ #### CSS and HTML Handling
351
+ - The `notesInfo` tool returns CSS styling information for proper rendering awareness
352
+ - The `updateNoteFields` tool supports HTML content in fields and preserves CSS styling
353
+ - Each note model has its own CSS styling - use `modelStyling` to get model-specific CSS
354
+
355
+ #### Update Warning
356
+ ⚠️ **IMPORTANT**: When using `updateNoteFields`, do NOT view the note in Anki's browser while updating, or the fields will not update properly. Close the browser or switch to a different note before updating. See [Known Issues](#known-issues) for more details.
357
+
358
+ #### Deletion Safety
359
+ The `deleteNotes` tool requires explicit confirmation (`confirmDeletion: true`) to prevent accidental deletions. Deleting a note removes ALL associated cards permanently.
360
+
361
+ ## Known Issues
362
+
363
+ ### Critical Limitations
364
+
365
+ #### Note Updates Fail When Viewed in Browser
366
+ ⚠️ **IMPORTANT**: When updating notes using `updateNoteFields`, the update will silently fail if the note is currently being viewed in Anki's browser window. This is an upstream AnkiConnect limitation.
367
+
368
+ **Workaround**: Always close the browser or navigate to a different note before updating.
369
+
370
+ ## Development
371
+
372
+ ### Transport Modes
373
+
374
+ This server supports two MCP transport modes via **separate entry points**:
375
+
376
+ #### STDIO Mode (Default)
377
+ - For local MCP clients like Claude Desktop
378
+ - Uses standard input/output for communication
379
+ - **Entry point**: `dist/main-stdio.js`
380
+ - **Run**: `npm run start:prod:stdio` or `node dist/main-stdio.js`
381
+ - **MCPB bundle**: Uses STDIO mode
382
+
383
+ #### HTTP Mode (Streamable HTTP)
384
+ - For remote MCP clients and web-based integrations
385
+ - Uses MCP Streamable HTTP protocol
386
+ - **Entry point**: `dist/main-http.js`
387
+ - **Run**: `npm run start:prod:http` or `node dist/main-http.js`
388
+ - **Default port**: 3000 (configurable via `PORT` env var)
389
+ - **Default host**: `127.0.0.1` (configurable via `HOST` env var)
390
+ - **MCP endpoint**: `http://127.0.0.1:3000/` (root path)
391
+
392
+ #### Building
393
+
394
+ ```bash
395
+ npm run build # Builds once, creates dist/ with both entry points
396
+ ```
397
+
398
+ Both `main-stdio.js` and `main-http.js` are in the same `dist/` directory. Choose which to run based on your needs.
399
+
400
+ #### HTTP Mode Configuration
401
+
402
+ **Environment Variables:**
403
+ - `PORT` - HTTP server port (default: 3000)
404
+ - `HOST` - Bind address (default: 127.0.0.1 for localhost-only)
405
+ - `ALLOWED_ORIGINS` - Comma-separated list of allowed origins for CORS (default: localhost)
406
+ - `LOG_LEVEL` - Logging level (default: info)
407
+
408
+ **Security:**
409
+ - Origin header validation (prevents DNS rebinding attacks)
410
+ - Binds to localhost (127.0.0.1) by default
411
+ - No authentication in current version (OAuth support planned)
412
+
413
+ **Example: Running Modes**
414
+ ```bash
415
+ # Development - STDIO mode (watch mode with auto-rebuild)
416
+ npm run start:dev:stdio
417
+
418
+ # Development - HTTP mode (watch mode with auto-rebuild)
419
+ npm run start:dev:http
420
+
421
+ # Production - STDIO mode
422
+ npm run start:prod:stdio
423
+ # or
424
+ node dist/main-stdio.js
425
+
426
+ # Production - HTTP mode
427
+ npm run start:prod:http
428
+ # or
429
+ PORT=8080 HOST=0.0.0.0 node dist/main-http.js
430
+ ```
431
+
432
+ ### Building an MCPB Bundle
433
+
434
+ To create a distributable MCPB bundle:
435
+
436
+ ```bash
437
+ npm run mcpb:bundle
438
+ ```
439
+
440
+ This command will:
441
+ 1. Sync version from `package.json` to `manifest.json`
442
+ 2. Remove old `.mcpb` files
443
+ 3. Build the TypeScript project
444
+ 4. Package `dist/` and `node_modules/` into an `.mcpb` file
445
+ 5. Run `mcpb clean` to remove devDependencies (optimizes bundle from ~47MB to ~10MB)
446
+
447
+ The output file will be named `anki-mcp-server-X.X.X.mcpb` and can be distributed for one-click installation.
448
+
449
+ #### What Gets Bundled
450
+
451
+ The MCPB package includes:
452
+ - Compiled JavaScript (`dist/` directory - includes both entry points)
453
+ - Production dependencies only (`node_modules/` - devDependencies removed by `mcpb clean`)
454
+ - Package metadata (`package.json`)
455
+ - Manifest configuration (`manifest.json` - configured to use `main-stdio.js`)
456
+ - Icon (`icon.png`)
457
+
458
+ Source files, tests, and development configs are automatically excluded via `.mcpbignore`.
459
+
460
+ ### Logging in Claude Desktop
461
+
462
+ When running as an MCPB extension in Claude Desktop, logs are written to:
463
+
464
+ **Log Location**: `~/Library/Logs/Claude/` (macOS)
465
+
466
+ The logs are split across multiple files:
467
+ - **main.log** - General Claude Desktop application logs
468
+ - **mcp-server-Anki MCP Server.log** - MCP protocol messages for this extension
469
+ - **mcp.log** - Combined MCP logs from all servers
470
+
471
+ **Note**: The pino logger output (INFO, ERROR, WARN messages from the server code) goes to stderr and appears in the MCP-specific log files. Claude Desktop determines which log file receives which messages, but generally:
472
+ - Application startup and MCP protocol communication → MCP-specific log
473
+ - Server internal logging (pino) → Both MCP-specific log and sometimes main.log
474
+
475
+ To view logs in real-time:
476
+ ```bash
477
+ tail -f ~/Library/Logs/Claude/mcp-server-Anki\ MCP\ Server.log
478
+ ```
479
+
480
+ ### Debugging the MCP Server
481
+
482
+ You can debug the MCP server using the MCP Inspector and attaching a debugger from your IDE (WebStorm, VS Code, etc.).
483
+
484
+ **Note for HTTP Mode:** When testing HTTP mode (Streamable HTTP) with MCP Inspector, use "Connection Type: Via Proxy" to avoid CORS errors.
485
+
486
+ #### Step 1: Configure Debug Server in MCP Inspector
487
+
488
+ The `mcp-inspector-config.json` already includes a debug server configuration:
489
+
490
+ ```json
491
+ {
492
+ "mcpServers": {
493
+ "stdio-server-debug": {
494
+ "type": "stdio",
495
+ "command": "node",
496
+ "args": ["--inspect-brk=9229", "dist/main-stdio.js"],
497
+ "env": {
498
+ "MCP_SERVER_NAME": "anki-mcp-stdio-debug",
499
+ "MCP_SERVER_VERSION": "1.0.0",
500
+ "LOG_LEVEL": "debug"
501
+ },
502
+ "note": "Anki MCP server with debugging enabled on port 9229"
503
+ }
504
+ }
505
+ }
506
+ ```
507
+
508
+ #### Step 2: Start the Debug Server
509
+
510
+ Run the MCP Inspector with the debug server:
511
+
512
+ ```bash
513
+ npm run inspector:debug
514
+ ```
515
+
516
+ This will start the server with Node.js debugging enabled on port 9229 and pause execution at the first line.
517
+
518
+ #### Step 3: Attach Debugger from Your IDE
519
+
520
+ ##### WebStorm
521
+ 1. Go to **Run → Edit Configurations**
522
+ 2. Add a new **Attach to Node.js/Chrome** configuration
523
+ 3. Set the port to `9229`
524
+ 4. Click **Debug** to attach
525
+
526
+ ##### VS Code
527
+ 1. Open the Debug panel (Ctrl+Shift+D / Cmd+Shift+D)
528
+ 2. Select **Debug MCP Server (Attach)** configuration
529
+ 3. Press F5 to attach
530
+
531
+ #### Step 4: Set Breakpoints and Debug
532
+
533
+ Once attached, you can:
534
+ - Set breakpoints in your TypeScript source files
535
+ - Step through code execution
536
+ - Inspect variables and call stack
537
+ - Use the debug console for evaluating expressions
538
+
539
+ The debugger will work with source maps, allowing you to debug the original TypeScript code rather than the compiled JavaScript.
540
+
541
+ ### Debugging with Claude Desktop
542
+
543
+ You can also debug the MCP server while it runs inside Claude Desktop by enabling the Node.js debugger and attaching your IDE.
544
+
545
+ #### Step 1: Configure Claude Desktop for Debugging
546
+
547
+ Update your Claude Desktop config to enable debugging:
548
+
549
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
550
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
551
+ **Linux**: `~/.config/Claude/claude_desktop_config.json`
552
+
553
+ ```json
554
+ {
555
+ "mcpServers": {
556
+ "anki-mcp": {
557
+ "command": "node",
558
+ "args": [
559
+ "--inspect=9229",
560
+ "<path_to_project>/anki-mcp-server/dist/main-stdio.js"
561
+ ],
562
+ "env": {
563
+ "ANKI_CONNECT_URL": "http://localhost:8765"
564
+ }
565
+ }
566
+ }
567
+ }
568
+ ```
569
+
570
+ **Key change**: Add `--inspect=9229` before the path to `dist/main-stdio.js`
571
+
572
+ **Debug options**:
573
+ - `--inspect=9229` - Start debugger immediately, doesn't block (recommended)
574
+ - `--inspect-brk=9229` - Pause execution until debugger attaches (for debugging startup issues)
575
+
576
+ #### Step 2: Restart Claude Desktop
577
+
578
+ After saving the config, restart Claude Desktop. The MCP server will now run with debugging enabled on port 9229.
579
+
580
+ #### Step 3: Attach Debugger from Your IDE
581
+
582
+ ##### WebStorm
583
+
584
+ 1. Go to **Run → Edit Configurations**
585
+ 2. Click the **+** button and select **Attach to Node.js/Chrome**
586
+ 3. Configure:
587
+ - **Name**: `Attach to Anki MCP (Claude Desktop)`
588
+ - **Host**: `localhost`
589
+ - **Port**: `9229`
590
+ - **Attach to**: `Node.js < 8` or `Chrome or Node.js > 6.3` (depending on WebStorm version)
591
+ 4. Click **OK**
592
+ 5. Click **Debug** (Shift+F9) to attach
593
+
594
+ ##### VS Code
595
+
596
+ 1. Add to `.vscode/launch.json`:
597
+
598
+ ```json
599
+ {
600
+ "version": "0.2.0",
601
+ "configurations": [
602
+ {
603
+ "type": "node",
604
+ "request": "attach",
605
+ "name": "Attach to Anki MCP (Claude Desktop)",
606
+ "port": 9229,
607
+ "skipFiles": ["<node_internals>/**"],
608
+ "sourceMaps": true,
609
+ "outFiles": ["${workspaceFolder}/dist/**/*.js"]
610
+ }
611
+ ]
612
+ }
613
+ ```
614
+
615
+ 2. Open the Debug panel (Ctrl+Shift+D / Cmd+Shift+D)
616
+ 3. Select **Attach to Anki MCP (Claude Desktop)**
617
+ 4. Press F5 to attach
618
+
619
+ #### Step 4: Debug in Real-Time
620
+
621
+ Once attached, you can:
622
+ - Set breakpoints in your TypeScript source files (e.g., `src/mcp/primitives/essential/tools/create-model.tool.ts`)
623
+ - Use Claude Desktop normally - breakpoints will hit when tools are invoked
624
+ - Step through code execution
625
+ - Inspect variables and call stack
626
+ - Use the debug console
627
+
628
+ **Example**: Set a breakpoint in `create-model.tool.ts` at line 119, then ask Claude to create a new model. The debugger will pause at your breakpoint!
629
+
630
+ **Note**: The debugger stays attached as long as Claude Desktop is running. You can detach/reattach anytime without restarting Claude Desktop.
631
+
632
+ ### Build Commands
633
+
634
+ ```bash
635
+ npm run build # Build the project (compile TypeScript to JavaScript)
636
+ npm run start:dev:stdio # STDIO mode with watch (auto-rebuild)
637
+ npm run start:dev:http # HTTP mode with watch (auto-rebuild)
638
+ npm run type-check # Run TypeScript type checking
639
+ npm run lint # Run ESLint
640
+ npm run mcpb:bundle # Sync version, clean, build, and create MCPB bundle
641
+ ```
642
+
643
+ ### NPM Package Testing (Local)
644
+
645
+ Test the npm package locally before publishing:
646
+
647
+ ```bash
648
+ # 1. Create local package
649
+ npm run pack:local # Builds and creates @laomeifun/my-anki-mcp-*.tgz
650
+
651
+ # 2. Install globally from local package
652
+ npm run install:local # Installs from ./@laomeifun/my-anki-mcp-*.tgz
653
+
654
+ # 3. Test the command
655
+ ankimcp # Runs HTTP server on port 3000
656
+
657
+ # 4. Uninstall when done testing
658
+ npm run uninstall:local # Removes global installation
659
+ ```
660
+
661
+ **How it works:**
662
+ - `npm pack` creates a `.tgz` file identical to what npm publish would create
663
+ - Installing from `.tgz` simulates what users get from `npm install -g @laomeifun/my-anki-mcp`
664
+ - This lets you test the full user experience before publishing to npm
665
+
666
+ ### Testing Commands
667
+
668
+ ```bash
669
+ npm test # Run all tests
670
+ npm run test:unit # Run unit tests only
671
+ npm run test:tools # Run tool-specific tests
672
+ npm run test:workflows # Run workflow integration tests
673
+ npm run test:e2e # Run end-to-end tests
674
+ npm run test:cov # Run tests with coverage report
675
+ npm run test:watch # Run tests in watch mode
676
+ npm run test:debug # Run tests with debugger
677
+ npm run test:ci # Run tests for CI (silent, with coverage)
678
+ ```
679
+
680
+ ### Test Coverage
681
+
682
+ The project maintains 70% minimum coverage thresholds for:
683
+ - Branches
684
+ - Functions
685
+ - Lines
686
+ - Statements
687
+
688
+ Coverage reports are generated in the `coverage/` directory.
689
+
690
+ ## Versioning
691
+
692
+ This project follows [Semantic Versioning](https://semver.org/) with a pre-1.0 development approach:
693
+
694
+ - **0.x.x** - Beta/Development versions (current phase)
695
+ - **0.1.x** - Bug fixes and patches
696
+ - **0.2.0+** - New features or minor improvements
697
+ - **Breaking changes** are acceptable in 0.x versions
698
+
699
+ - **1.0.0** - First stable release
700
+ - Will be released when the API is stable and tested
701
+ - Breaking changes will require major version bumps (2.0.0, etc.)
702
+
703
+ **Current Status**: `0.8.0` - Active beta development. New features include integrated ngrok tunneling (`--ngrok` flag), the `twenty_rules` prompt for evidence-based flashcard creation, media file management, and improved prompt system. APIs may change based on feedback and testing.
704
+
705
+ ## Similar Projects
706
+
707
+ If you're exploring Anki MCP integrations, here are other projects in this space:
708
+
709
+ ### [scorzeth/anki-mcp-server](https://github.com/scorzeth/anki-mcp-server)
710
+ - **Status**: Appears to be abandoned (no recent updates)
711
+ - Early implementation of Anki MCP integration
712
+
713
+ ### [nailuoGG/anki-mcp-server](https://github.com/nailuoGG/anki-mcp-server)
714
+ - **Approach**: Lightweight, single-file implementation
715
+ - **Architecture**: Procedural code structure with all tools in one file
716
+ - **Good for**: Simple use cases, minimal dependencies
717
+
718
+ **Why this project differs:**
719
+ - **Enterprise-grade architecture**: Built on NestJS with dependency injection
720
+ - **Modular design**: Each tool is a separate class with clear separation of concerns
721
+ - **Maintainability**: Easy to extend with new features without touching existing code
722
+ - **Testing**: Comprehensive test suite with 70% coverage requirement
723
+ - **Type safety**: Strict TypeScript with Zod validation
724
+ - **Error handling**: Robust error handling with helpful user feedback
725
+ - **Production-ready**: Proper logging, progress reporting, and MCPB bundle support
726
+ - **Scalability**: Can easily grow from basic tools to complex workflows
727
+
728
+ **Use case**: If you need a solid foundation for building advanced Anki integrations or plan to extend functionality significantly, this project's architectural approach makes it easier to maintain and scale over time.
729
+
730
+ ## Useful Links
731
+
732
+ - [Model Context Protocol Documentation](https://modelcontextprotocol.io/docs)
733
+ - [AnkiConnect API Documentation](https://git.sr.ht/~foosoft/anki-connect)
734
+ - [Claude Desktop Download](https://claude.ai/download)
735
+ - [Building Desktop Extensions (Anthropic Blog)](https://www.anthropic.com/engineering/desktop-extensions)
736
+ - [MCP Servers Repository](https://github.com/modelcontextprotocol/servers)
737
+ - [NestJS Documentation](https://docs.nestjs.com)
738
+ - [Anki Official Website](https://apps.ankiweb.net/)
739
+
740
+ ## License & Attribution
741
+
742
+ This project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later).
743
+
744
+ ### Why AGPL-3.0?
745
+
746
+ This license was chosen to maintain compatibility with Anki's AGPL-3.0 license for potential future integration scenarios.
747
+
748
+ **What this means:**
749
+ - **Personal use**: Use the software freely
750
+ - **Running as a service for others**: You must provide source code access (AGPL Section 13)
751
+ - **Modifying and distributing**: Share your improvements under AGPL-3.0-or-later
752
+
753
+ For complete license terms, see the [LICENSE](LICENSE) file.
754
+
755
+ ### Third-Party Attributions
756
+
757
+ - **Anki®** is a registered trademark of Ankitects Pty Ltd. This project is an unofficial third-party tool and is not affiliated with, endorsed by, or sponsored by Ankitects Pty Ltd. The Anki logo is used under the alternative license for referencing Anki with a link to [https://apps.ankiweb.net](https://apps.ankiweb.net). For the official Anki application, visit [https://apps.ankiweb.net](https://apps.ankiweb.net).
758
+
759
+ - **Model Context Protocol (MCP)** is an open standard by Anthropic. The MCP logo is from the official [MCP documentation repository](https://github.com/modelcontextprotocol/docs) and is used under the MIT License. For more information about MCP, visit [https://modelcontextprotocol.io](https://modelcontextprotocol.io).
760
+
783
761
  - This is an independent project that bridges Anki and MCP technologies. All trademarks, service marks, trade names, product names, and logos are the property of their respective owners.