media_retrieveMediaFile
Retrieve base64-encoded contents of a media file from Anki’s collection using the specified filename. Returns the encoded string or false if the file is not found.
Instructions
Retrieves the base64-encoded contents of the specified media file. Returns the base64 string or false if not found.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | The name of the media file in Anki's collection. |
Implementation Reference
- src/anki_mcp/media_service.py:11-21 (handler)The tool handler function for media_retrieveMediaFile, decorated with @media_mcp.tool(name='retrieveMediaFile'). It calls anki_call to invoke AnkiConnect's retrieveMediaFile API.@media_mcp.tool( name="retrieveMediaFile", description="Retrieves the base64-encoded contents of the specified media file. Returns the base64 string or false if not found.", ) async def retrieve_media_file_tool( filename: Annotated[ str, Field(description="The name of the media file in Anki's collection.") ], ) -> Any: return await anki_call("retrieveMediaFile", filename=filename)
- src/anki_mcp/__init__.py:27-27 (registration)Registration of the media service into the main anki_mcp server under the 'media' namespace, which prefixes the tool name to 'media_retrieveMediaFile'.await anki_mcp.import_server("media", media_mcp)
- src/anki_mcp/common.py:8-23 (helper)The helper function 'anki_call' used by the tool handler to communicate with the AnkiConnect server via HTTP POST requests.async def anki_call(action: str, **params: Any) -> Any: async with httpx.AsyncClient() as client: payload = {"action": action, "version": 6, "params": params} result = await client.post(ANKICONNECT_URL, json=payload) result.raise_for_status() result_json = result.json() error = result_json.get("error") if error: raise Exception(f"AnkiConnect error for action '{action}': {error}") response = result_json.get("result") if "result" in result_json: return response return result_json
- src/anki_mcp/media_service.py:16-18 (schema)Pydantic schema definition for the 'filename' input parameter of the tool.filename: Annotated[ str, Field(description="The name of the media file in Anki's collection.") ],