media_retrieveMediaFile
Retrieve base64-encoded media files from Anki's collection to access and use stored audio, images, or other media content in your flashcards.
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-20 (handler)Handler function executing the tool logic for retrieving Anki media files as base64, proxying to AnkiConnect 'retrieveMediaFile' action.@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)Main registration step that imports the media service tools under the 'media_' namespace, creating the 'media_retrieveMediaFile' tool.await anki_mcp.import_server("media", media_mcp)
- src/anki_mcp/common.py:8-23 (helper)Supporting utility `anki_call` that handles HTTP communication with AnkiConnect API, invoked by the handler with action='retrieveMediaFile'.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:8-8 (registration)Creates the sub-MCP server 'AnkiMediaService' where the retrieveMediaFile tool is initially registered (before namespacing).media_mcp = FastMCP(name="AnkiMediaService")