@ankimcp/anki-mcp-server 0.8.0

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