@spacholski1225/anki-connect-mcp 1.0.5 → 2.0.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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Szymon Pacholski
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Szymon Pacholski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,245 +1,260 @@
1
- # Anki Connect MCP Server
2
-
3
- A Model Context Protocol (MCP) server that provides seamless integration with Anki through the AnkiConnect add-on. This server enables AI assistants and other MCP clients to interact with your Anki flashcard collection programmatically.
4
-
5
- ## What is Anki Connect?
6
-
7
- [AnkiConnect](https://ankiweb.net/shared/info/2055492159) is a powerful Anki add-on that exposes Anki's functionality through a REST API. It allows external applications to:
8
-
9
- - Create, modify, and delete flashcards
10
- - Manage decks and their configurations
11
- - Control Anki's GUI programmatically
12
- - Search and retrieve card information
13
- - Manage tags and note types
14
- - Perform bulk operations on cards and notes
15
-
16
- ## What is MCP (Model Context Protocol)?
17
-
18
- The Model Context Protocol is a standardized way for AI assistants to connect to external data sources and tools. This MCP server acts as a bridge between MCP clients (like Claude Desktop) and AnkiConnect, allowing AI assistants to help you manage your Anki flashcards naturally through conversation.
19
-
20
- ## Features
21
-
22
- This MCP server provides comprehensive access to AnkiConnect functionality through the following tools:
23
-
24
- ### Flashcard Management
25
- - [`create_flashcard()`](src/index.ts:67) - Create new flashcards with front and back content
26
- - [`add_note()`](src/tools/notes.ts:22) - Add notes with custom fields and tags
27
- - [`add_notes()`](src/tools/notes.ts) - Bulk add multiple notes
28
- - [`update_note_fields()`](src/tools/notes.ts) - Update existing note fields
29
- - [`find_notes()`](src/tools/notes.ts) - Search for notes using Anki's query syntax
30
-
31
- ### Deck Management
32
- - [`deck_names()`](src/tools/decks.ts:19) - Get all deck names
33
- - [`deck_names_and_ids()`](src/tools/decks.ts:30) - Get deck names with their IDs
34
- - [`change_deck()`](src/tools/decks.ts) - Move cards between decks
35
- - [`delete_decks()`](src/tools/decks.ts) - Delete decks and optionally their cards
36
- - [`get_deck_config()`](src/tools/decks.ts) - Retrieve deck configuration settings
37
-
38
- ### Card Operations
39
- - [`find_cards()`](src/tools/cards.ts) - Search for cards
40
- - [`cards_info()`](src/tools/cards.ts) - Get detailed card information
41
- - [`suspend()`](src/tools/cards.ts:18) / [`unsuspend()`](src/tools/cards.ts) - Suspend/unsuspend cards
42
- - [`are_suspended()`](src/tools/cards.ts) / [`are_due()`](src/tools/cards.ts) - Check card status
43
-
44
- ### GUI Control
45
- - [`gui_deck_browser()`](src/index.ts:177) - Open deck browser
46
- - [`gui_deck_review()`](src/index.ts:185) - Start deck review
47
- - [`gui_browse()`](src/index.ts:196) - Open card browser with search
48
- - [`gui_add_cards()`](src/index.ts:207) - Open add cards dialog
49
-
50
- ### Utility Tools
51
- - [`version()`](src/index.ts:98) - Get AnkiConnect version
52
- - [`get_tags()`](src/index.ts:114) - Retrieve all tags
53
- - [`multi()`](src/index.ts:223) - Execute multiple AnkiConnect requests in batch
54
-
55
- ## Prerequisites
56
-
57
- ### 1. Install AnkiConnect Add-on
58
-
59
- 1. Open Anki
60
- 2. Go to **Tools** → **Add-ons**
61
- 3. Click **Get Add-ons...**
62
- 4. Enter the code: `2055492159`
63
- 5. Click **OK** and restart Anki
64
-
65
- ### 2. Configure AnkiConnect (Optional)
66
-
67
- AnkiConnect works out of the box, but you can customize its settings:
68
-
69
- 1. Go to **Tools** → **Add-ons**
70
- 2. Select **AnkiConnect** and click **Config**
71
- 3. Modify settings if needed (default port is 8765)
72
- 4. Restart Anki after making changes
73
-
74
- ## Installation
75
-
76
- 1. Clone this repository:
77
- ```bash
78
- git clone https://github.com/spacholski1225/mcp-server.git
79
- cd mcp-server
80
- ```
81
-
82
- 2. Install dependencies:
83
- ```bash
84
- npm install
85
- ```
86
-
87
- 3. Build the project:
88
- ```bash
89
- npm run build
90
- ```
91
-
92
- ## MCP Client Configuration
93
-
94
- ### Claude Desktop
95
-
96
- To use this MCP server with Claude Desktop, add the following configuration to your MCP settings file:
97
-
98
- **Location of MCP configuration file:**
99
- - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
100
- - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
101
- - **Linux**: `~/.config/Claude/claude_desktop_config.json`
102
-
103
- **Configuration Options:**
104
-
105
- #### Option 1: Using Node.js (Local Installation)
106
- ```json
107
- {
108
- "mcpServers": {
109
- "anki-connect-mcp": {
110
- "command": "node",
111
- "args": [
112
- "dist/index.js"
113
- ],
114
- "env": {},
115
- "disabled": false,
116
- "alwaysAllow": [
117
- "deck_names",
118
- "cards_info",
119
- "deck_names_and_ids",
120
- "gui_deck_browser"
121
- ]
122
- }
123
- }
124
- }
125
- ```
126
-
127
- #### Option 2: Using npx (NPM Package)
128
-
129
- **Then configure your MCP client:**
130
- ```json
131
- {
132
- "mcpServers": {
133
- "anki-connect": {
134
- "command": "npx",
135
- "args": [
136
- "@spacholski1225/anki-connect-mcp"
137
- ],
138
- "env": {},
139
- "disabled": false,
140
- "alwaysAllow": [
141
- "deck_names",
142
- "cards_info",
143
- "deck_names_and_ids",
144
- "gui_deck_browser"
145
- ]
146
- }
147
- }
148
- }
149
- ```
150
-
151
- #### Option 3: Using Docker
152
- ```json
153
- {
154
- "mcpServers": {
155
- "anki-connect": {
156
- "command": "docker",
157
- "args": [
158
- "run",
159
- "--rm",
160
- "-i",
161
- "--network=host",
162
- "-e", "ANKI_CONNECT_URL=http://host.docker.internal:8765",
163
- "spacholski/anki-connect-mcp:latest"
164
- ],
165
- "env": {},
166
- "disabled": false,
167
- "alwaysAllow": [
168
- "deck_names",
169
- "cards_info",
170
- "deck_names_and_ids",
171
- "gui_deck_browser"
172
- ]
173
- }
174
- }
175
- }
176
- ```
177
-
178
- **Docker-Specific AnkiConnect Configuration:**
179
-
180
- When using the Docker option, you **must** configure AnkiConnect with specific settings to allow Docker container access:
181
-
182
- 1. Go to **Tools** → **Add-ons** in Anki
183
- 2. Select **AnkiConnect** and click **Config**
184
- 3. Update the configuration with the following settings:
185
-
186
- ```json
187
- {
188
- "apiKey": null,
189
- "apiLogPath": null,
190
- "ignoreOriginList": [],
191
- "webBindAddress": "0.0.0.0",
192
- "webBindPort": 8765,
193
- "webCorsOriginList": [
194
- "http://localhost",
195
- "http://host.docker.internal",
196
- "http://host.docker.internal:3000"
197
- ]
198
- }
199
- ```
200
-
201
- **Key Docker Configuration Points:**
202
- - **`webBindAddress: "0.0.0.0"`** - Allows AnkiConnect to accept connections from any IP address (required for Docker containers)
203
- - **`webCorsOriginList`** - Must include `"http://host.docker.internal"` and related origins to allow cross-origin requests from Docker containers
204
- - Restart Anki after making these configuration changes
205
-
206
- **Important Notes:**
207
- - **For Node.js option**: Replace the path in `args` with the actual path to your built `index.js` file
208
- - **For npx option**: Uses the published NPM package `@spacholski1225/anki-connect-mcp` - no local installation required
209
- - **For Docker option**: Uses the pre-built Docker image `spacholski/anki-connect-mcp:latest`
210
- - The `alwaysAllow` array contains tools that won't require confirmation each time
211
- - Make sure Anki is running with AnkiConnect enabled before using the MCP server
212
- - For Docker option, the `--network=host` flag allows the container to access AnkiConnect on the host machine
213
-
214
- ## Usage Examples
215
-
216
- Once configured with an MCP client like Claude Desktop, you can interact with your Anki collection naturally:
217
-
218
- - *"Create a flashcard about the capital of France"*
219
- - *"Show me all my deck names"*
220
- - *"Find all cards tagged with 'vocabulary'"*
221
- - *"Suspend all cards in the 'Difficult Words' deck"*
222
- - *"Open the deck browser in Anki"*
223
-
224
- ## Troubleshooting
225
-
226
- ### Common Issues
227
-
228
- 1. **Connection refused**: Make sure Anki is running and AnkiConnect is installed
229
- 2. **Port conflicts**: Check if port 8765 is available or configure AnkiConnect to use a different port
230
- 3. **Permission errors**: Ensure the MCP server has proper file system permissions
231
- 4. **Tool not found**: Verify the MCP client configuration and restart the client
232
-
233
- ## Contributing
234
-
235
- Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
236
-
237
- ## License
238
-
239
- ISC License
240
-
241
- ## References
242
-
243
- - [AnkiConnect Documentation](https://foosoft.net/projects/anki-connect/)
244
- - [Model Context Protocol Specification](https://modelcontextprotocol.io/)
245
- - [MCP SDK Documentation](https://github.com/modelcontextprotocol/typescript-sdk)
1
+ # Anki Connect MCP Server
2
+
3
+ A Model Context Protocol (MCP) server that provides seamless integration with Anki through the AnkiConnect add-on. This server enables AI assistants and other MCP clients to interact with your Anki flashcard collection programmatically.
4
+
5
+ ![Project](assets/anki-connect-mcp.gif)
6
+
7
+ ## What is Anki Connect?
8
+
9
+ [AnkiConnect](https://ankiweb.net/shared/info/2055492159) is a powerful Anki add-on that exposes Anki's functionality through a REST API. It allows external applications to:
10
+
11
+ - Create, modify, and delete flashcards
12
+ - Manage decks and their configurations
13
+ - Control Anki's GUI programmatically
14
+ - Search and retrieve card information
15
+ - Manage tags and note types
16
+ - Perform bulk operations on cards and notes
17
+
18
+ ## What is MCP (Model Context Protocol)?
19
+
20
+ The Model Context Protocol is a standardized way for AI assistants to connect to external data sources and tools. This MCP server acts as a bridge between MCP clients (like Claude Desktop) and AnkiConnect, allowing AI assistants to help you manage your Anki flashcards naturally through conversation.
21
+
22
+ ## Features
23
+
24
+ Every tool comes with a description, a title and MCP annotations (`readOnlyHint` / `destructiveHint`), so clients can auto-approve read-only tools and ask before destructive ones. On connect the server also sends instructions for the agent: Anki search syntax, note IDs vs card IDs, and the recommended flow for adding cards.
25
+
26
+ Errors are reported as tool errors (`isError: true`): `AnkiConnect error: ...` when Anki rejects a request, and `Could not reach AnkiConnect at <url>...` when Anki is not running.
27
+
28
+ ### Default tools
29
+
30
+ - **Notes:** `add_note`, `add_notes`, `can_add_notes`, `update_note_fields`, `add_tags`, `remove_tags`, `find_notes`, `notes_info`
31
+ - **Cards:** `find_cards`, `cards_info`, `cards_to_notes`, `suspend`, `unsuspend`, `are_suspended`, `are_due`, `get_intervals`
32
+ - **Decks:** `deck_names`, `deck_names_and_ids`, `get_decks`, `change_deck`, `delete_decks`, `get_deck_config`
33
+ - **Models:** `model_names`, `model_names_and_ids`, `model_field_names`, `model_fields_on_templates`
34
+ - **Misc:** `version`, `get_tags`
35
+
36
+ `find_notes` and `find_cards` return `{ ids, total, truncated }` and accept an optional `limit` (default 100). `cards_info` strips the card CSS from the question and answer.
37
+
38
+ ### Optional tool groups
39
+
40
+ | Group | Enabled by | Tools |
41
+ |-------|-----------|-------|
42
+ | GUI | `ANKI_MCP_ENABLE_GUI=1` | `gui_browse`, `gui_add_cards`, `gui_current_card`, `gui_start_card_timer`, `gui_show_question`, `gui_show_answer`, `gui_answer_card`, `gui_deck_overview`, `gui_deck_browser`, `gui_deck_review`, `gui_exit_anki` |
43
+ | Advanced | `ANKI_MCP_ENABLE_ADVANCED=1` | `multi`, `upgrade`, `save_deck_config`, `set_deck_config_id`, `clone_deck_config_id`, `remove_deck_config_id` |
44
+
45
+ ## Configuration
46
+
47
+ | Variable | Default | Purpose |
48
+ |----------|---------|---------|
49
+ | `ANKI_CONNECT_URL` | `http://localhost:8765` | AnkiConnect address |
50
+ | `ANKI_CONNECT_API_KEY` | – | Sent as `key` with every request; set it when AnkiConnect has `apiKey` configured |
51
+ | `ANKI_MCP_ENABLE_GUI` | off | `1` or `true` enables the GUI tools |
52
+ | `ANKI_MCP_ENABLE_ADVANCED` | off | `1` or `true` enables the advanced tools |
53
+
54
+ ### Upgrading from 1.x
55
+
56
+ - `create_flashcard` was removed; use `add_note` with `deckName`, `modelName` and `fields`.
57
+ - GUI tools, `multi`, `upgrade` and deck-config editing tools are hidden unless their group is enabled.
58
+ - Tool results contain only AnkiConnect's `result` (no `{result, error}` envelope); errors come back as tool errors.
59
+ - `find_notes` / `find_cards` return `{ ids, total, truncated }` instead of a plain array.
60
+ - Node.js 20 or newer is required.
61
+
62
+ ## Prerequisites
63
+
64
+ ### 1. Install AnkiConnect Add-on
65
+
66
+ 1. Open Anki
67
+ 2. Go to **Tools** → **Add-ons**
68
+ 3. Click **Get Add-ons...**
69
+ 4. Enter the code: `2055492159`
70
+ 5. Click **OK** and restart Anki
71
+
72
+ ### 2. Configure AnkiConnect (Optional)
73
+
74
+ AnkiConnect works out of the box, but you can customize its settings:
75
+
76
+ 1. Go to **Tools** → **Add-ons**
77
+ 2. Select **AnkiConnect** and click **Config**
78
+ 3. Modify settings if needed (default port is 8765)
79
+ 4. Restart Anki after making changes
80
+
81
+ ## Installation
82
+
83
+ 1. Clone this repository:
84
+ ```bash
85
+ git clone https://github.com/spacholski1225/anki-connect-mcp.git
86
+ cd anki-connect-mcp
87
+ ```
88
+
89
+ 2. Install dependencies:
90
+ ```bash
91
+ npm install
92
+ ```
93
+
94
+ 3. Build the project:
95
+ ```bash
96
+ npm run build
97
+ ```
98
+
99
+ ## MCP Client Configuration
100
+
101
+ ### Claude Desktop
102
+
103
+ To use this MCP server with Claude Desktop, add the following configuration to your MCP settings file:
104
+
105
+ **Location of MCP configuration file:**
106
+ - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
107
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
108
+ - **Linux**: `~/.config/Claude/claude_desktop_config.json`
109
+
110
+ **Configuration Options:**
111
+
112
+ #### Option 1: Using Node.js (Local Installation)
113
+ ```json
114
+ {
115
+ "mcpServers": {
116
+ "anki-connect-mcp": {
117
+ "command": "node",
118
+ "args": [
119
+ "dist/index.js"
120
+ ],
121
+ "env": {},
122
+ "disabled": false,
123
+ "alwaysAllow": [
124
+ "deck_names",
125
+ "cards_info",
126
+ "deck_names_and_ids",
127
+ "find_notes"
128
+ ]
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ #### Option 2: Using npx (NPM Package)
135
+
136
+ **Then configure your MCP client:**
137
+ ```json
138
+ {
139
+ "mcpServers": {
140
+ "anki-connect": {
141
+ "command": "npx",
142
+ "args": [
143
+ "@spacholski1225/anki-connect-mcp"
144
+ ],
145
+ "env": {},
146
+ "disabled": false,
147
+ "alwaysAllow": [
148
+ "deck_names",
149
+ "cards_info",
150
+ "deck_names_and_ids",
151
+ "find_notes"
152
+ ]
153
+ }
154
+ }
155
+ }
156
+ ```
157
+
158
+ #### Option 3: Using Docker
159
+ ```json
160
+ {
161
+ "mcpServers": {
162
+ "anki-connect": {
163
+ "command": "docker",
164
+ "args": [
165
+ "run",
166
+ "--rm",
167
+ "-i",
168
+ "--network=host",
169
+ "-e", "ANKI_CONNECT_URL=http://host.docker.internal:8765",
170
+ "spacholski/anki-connect-mcp:latest"
171
+ ],
172
+ "env": {},
173
+ "disabled": false,
174
+ "alwaysAllow": [
175
+ "deck_names",
176
+ "cards_info",
177
+ "deck_names_and_ids",
178
+ "find_notes"
179
+ ]
180
+ }
181
+ }
182
+ }
183
+ ```
184
+
185
+ **Docker-Specific AnkiConnect Configuration:**
186
+
187
+ When using the Docker option, you **must** configure AnkiConnect with specific settings to allow Docker container access:
188
+
189
+ 1. Go to **Tools** → **Add-ons** in Anki
190
+ 2. Select **AnkiConnect** and click **Config**
191
+ 3. Update the configuration with the following settings:
192
+
193
+ ```json
194
+ {
195
+ "apiKey": null,
196
+ "apiLogPath": null,
197
+ "ignoreOriginList": [],
198
+ "webBindAddress": "0.0.0.0",
199
+ "webBindPort": 8765,
200
+ "webCorsOriginList": [
201
+ "http://localhost",
202
+ "http://host.docker.internal",
203
+ "http://host.docker.internal:3000"
204
+ ]
205
+ }
206
+ ```
207
+
208
+ **Key Docker Configuration Points:**
209
+ - **`webBindAddress: "0.0.0.0"`** - Allows AnkiConnect to accept connections from any IP address (required for Docker containers)
210
+ - **`webCorsOriginList`** - Must include `"http://host.docker.internal"` and related origins to allow cross-origin requests from Docker containers
211
+ - Restart Anki after making these configuration changes
212
+
213
+ **Important Notes:**
214
+ - **For Node.js option**: Replace the path in `args` with the actual path to your built `index.js` file
215
+ - **For npx option**: Uses the published NPM package `@spacholski1225/anki-connect-mcp` - no local installation required
216
+ - **For Docker option**: Uses the pre-built Docker image `spacholski/anki-connect-mcp:latest`
217
+ - The `alwaysAllow` array contains tools that won't require confirmation each time
218
+ - Make sure Anki is running with AnkiConnect enabled before using the MCP server
219
+ - For Docker option, the `--network=host` flag allows the container to access AnkiConnect on the host machine
220
+
221
+ ## Usage Examples
222
+
223
+ Once configured with an MCP client like Claude Desktop, you can interact with your Anki collection naturally:
224
+
225
+ - *"Create a flashcard about the capital of France in my Geography deck"*
226
+ - *"Show me all my deck names"*
227
+ - *"Find all cards tagged with 'vocabulary'"*
228
+ - *"Suspend all cards in the 'Difficult Words' deck"*
229
+ - *"Open the deck browser in Anki"* (needs `ANKI_MCP_ENABLE_GUI=1`)
230
+
231
+ ## Troubleshooting
232
+
233
+ ### Common Issues
234
+
235
+ 1. **Connection refused**: Make sure Anki is running and AnkiConnect is installed
236
+ 2. **Port conflicts**: Check if port 8765 is available or configure AnkiConnect to use a different port
237
+ 3. **Permission errors**: Ensure the MCP server has proper file system permissions
238
+ 4. **Tool not found**: Verify the MCP client configuration and restart the client
239
+
240
+ ## Development
241
+
242
+ ```bash
243
+ npm run typecheck # type-check sources and tests
244
+ npm test # protocol-level tests against a fake AnkiConnect
245
+ npm run build
246
+ ```
247
+
248
+ ## Contributing
249
+
250
+ Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
251
+
252
+ ## License
253
+
254
+ MIT License
255
+
256
+ ## References
257
+
258
+ - [AnkiConnect Documentation](https://foosoft.net/projects/anki-connect/)
259
+ - [Model Context Protocol Specification](https://modelcontextprotocol.io/)
260
+ - [MCP SDK Documentation](https://github.com/modelcontextprotocol/typescript-sdk)