@spacholski1225/anki-connect-mcp 1.0.6 → 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,247 +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
- ![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
- This MCP server provides comprehensive access to AnkiConnect functionality through the following tools:
25
-
26
- ### Flashcard Management
27
- - `create_flashcard()` - Create new flashcards with front and back content
28
- - `add_note()` - Add notes with custom fields and tags
29
- - `add_notes()` - Bulk add multiple notes
30
- - `update_note_fields()` - Update existing note fields
31
- - `find_notes()` - Search for notes using Anki's query syntax
32
-
33
- ### Deck Management
34
- - `deck_names()` - Get all deck names
35
- - `deck_names_and_ids()` - Get deck names with their IDs
36
- - `change_deck()` - Move cards between decks
37
- - `delete_decks()` - Delete decks and optionally their cards
38
- - `get_deck_config()` - Retrieve deck configuration settings
39
-
40
- ### Card Operations
41
- - `find_cards()` - Search for cards
42
- - `cards_info()` - Get detailed card information
43
- - `suspend()` / `unsuspend()` - Suspend/unsuspend cards
44
- - `are_suspended()` / `are_due()` - Check card status
45
-
46
- ### GUI Control
47
- - `gui_deck_browser()` - Open deck browser
48
- - `gui_deck_review()` - Start deck review
49
- - `gui_browse()` - Open card browser with search
50
- - `gui_add_cards()` - Open add cards dialog
51
-
52
- ### Utility Tools
53
- - `version()` - Get AnkiConnect version
54
- - `get_tags()` - Retrieve all tags
55
- - `multi()` - Execute multiple AnkiConnect requests in batch
56
-
57
- ## Prerequisites
58
-
59
- ### 1. Install AnkiConnect Add-on
60
-
61
- 1. Open Anki
62
- 2. Go to **Tools** → **Add-ons**
63
- 3. Click **Get Add-ons...**
64
- 4. Enter the code: `2055492159`
65
- 5. Click **OK** and restart Anki
66
-
67
- ### 2. Configure AnkiConnect (Optional)
68
-
69
- AnkiConnect works out of the box, but you can customize its settings:
70
-
71
- 1. Go to **Tools** → **Add-ons**
72
- 2. Select **AnkiConnect** and click **Config**
73
- 3. Modify settings if needed (default port is 8765)
74
- 4. Restart Anki after making changes
75
-
76
- ## Installation
77
-
78
- 1. Clone this repository:
79
- ```bash
80
- git clone https://github.com/spacholski1225/mcp-server.git
81
- cd mcp-server
82
- ```
83
-
84
- 2. Install dependencies:
85
- ```bash
86
- npm install
87
- ```
88
-
89
- 3. Build the project:
90
- ```bash
91
- npm run build
92
- ```
93
-
94
- ## MCP Client Configuration
95
-
96
- ### Claude Desktop
97
-
98
- To use this MCP server with Claude Desktop, add the following configuration to your MCP settings file:
99
-
100
- **Location of MCP configuration file:**
101
- - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
102
- - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
103
- - **Linux**: `~/.config/Claude/claude_desktop_config.json`
104
-
105
- **Configuration Options:**
106
-
107
- #### Option 1: Using Node.js (Local Installation)
108
- ```json
109
- {
110
- "mcpServers": {
111
- "anki-connect-mcp": {
112
- "command": "node",
113
- "args": [
114
- "dist/index.js"
115
- ],
116
- "env": {},
117
- "disabled": false,
118
- "alwaysAllow": [
119
- "deck_names",
120
- "cards_info",
121
- "deck_names_and_ids",
122
- "gui_deck_browser"
123
- ]
124
- }
125
- }
126
- }
127
- ```
128
-
129
- #### Option 2: Using npx (NPM Package)
130
-
131
- **Then configure your MCP client:**
132
- ```json
133
- {
134
- "mcpServers": {
135
- "anki-connect": {
136
- "command": "npx",
137
- "args": [
138
- "@spacholski1225/anki-connect-mcp"
139
- ],
140
- "env": {},
141
- "disabled": false,
142
- "alwaysAllow": [
143
- "deck_names",
144
- "cards_info",
145
- "deck_names_and_ids",
146
- "gui_deck_browser"
147
- ]
148
- }
149
- }
150
- }
151
- ```
152
-
153
- #### Option 3: Using Docker
154
- ```json
155
- {
156
- "mcpServers": {
157
- "anki-connect": {
158
- "command": "docker",
159
- "args": [
160
- "run",
161
- "--rm",
162
- "-i",
163
- "--network=host",
164
- "-e", "ANKI_CONNECT_URL=http://host.docker.internal:8765",
165
- "spacholski/anki-connect-mcp:latest"
166
- ],
167
- "env": {},
168
- "disabled": false,
169
- "alwaysAllow": [
170
- "deck_names",
171
- "cards_info",
172
- "deck_names_and_ids",
173
- "gui_deck_browser"
174
- ]
175
- }
176
- }
177
- }
178
- ```
179
-
180
- **Docker-Specific AnkiConnect Configuration:**
181
-
182
- When using the Docker option, you **must** configure AnkiConnect with specific settings to allow Docker container access:
183
-
184
- 1. Go to **Tools** → **Add-ons** in Anki
185
- 2. Select **AnkiConnect** and click **Config**
186
- 3. Update the configuration with the following settings:
187
-
188
- ```json
189
- {
190
- "apiKey": null,
191
- "apiLogPath": null,
192
- "ignoreOriginList": [],
193
- "webBindAddress": "0.0.0.0",
194
- "webBindPort": 8765,
195
- "webCorsOriginList": [
196
- "http://localhost",
197
- "http://host.docker.internal",
198
- "http://host.docker.internal:3000"
199
- ]
200
- }
201
- ```
202
-
203
- **Key Docker Configuration Points:**
204
- - **`webBindAddress: "0.0.0.0"`** - Allows AnkiConnect to accept connections from any IP address (required for Docker containers)
205
- - **`webCorsOriginList`** - Must include `"http://host.docker.internal"` and related origins to allow cross-origin requests from Docker containers
206
- - Restart Anki after making these configuration changes
207
-
208
- **Important Notes:**
209
- - **For Node.js option**: Replace the path in `args` with the actual path to your built `index.js` file
210
- - **For npx option**: Uses the published NPM package `@spacholski1225/anki-connect-mcp` - no local installation required
211
- - **For Docker option**: Uses the pre-built Docker image `spacholski/anki-connect-mcp:latest`
212
- - The `alwaysAllow` array contains tools that won't require confirmation each time
213
- - Make sure Anki is running with AnkiConnect enabled before using the MCP server
214
- - For Docker option, the `--network=host` flag allows the container to access AnkiConnect on the host machine
215
-
216
- ## Usage Examples
217
-
218
- Once configured with an MCP client like Claude Desktop, you can interact with your Anki collection naturally:
219
-
220
- - *"Create a flashcard about the capital of France"*
221
- - *"Show me all my deck names"*
222
- - *"Find all cards tagged with 'vocabulary'"*
223
- - *"Suspend all cards in the 'Difficult Words' deck"*
224
- - *"Open the deck browser in Anki"*
225
-
226
- ## Troubleshooting
227
-
228
- ### Common Issues
229
-
230
- 1. **Connection refused**: Make sure Anki is running and AnkiConnect is installed
231
- 2. **Port conflicts**: Check if port 8765 is available or configure AnkiConnect to use a different port
232
- 3. **Permission errors**: Ensure the MCP server has proper file system permissions
233
- 4. **Tool not found**: Verify the MCP client configuration and restart the client
234
-
235
- ## Contributing
236
-
237
- Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
238
-
239
- ## License
240
-
241
- ISC License
242
-
243
- ## References
244
-
245
- - [AnkiConnect Documentation](https://foosoft.net/projects/anki-connect/)
246
- - [Model Context Protocol Specification](https://modelcontextprotocol.io/)
247
- - [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)