media_getMediaFilesNames
Retrieve media file names from Anki flashcards using a glob pattern to locate specific files in your collection.
Instructions
Gets the names of media files matching the glob pattern. Returns a list of filenames.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | A glob pattern to match filenames (e.g., '*.jpg'). |
Implementation Reference
- src/anki_mcp/media_service.py:23-32 (handler)Handler function implementing the tool logic for 'media_getMediaFilesNames'. Takes a glob pattern as input, calls AnkiConnect's 'getMediaFilesNames' via anki_call helper, returns list of filenames. Includes inline schema and description.@media_mcp.tool( name="getMediaFilesNames", description="Gets the names of media files matching the glob pattern. Returns a list of filenames.", ) async def list_media_files_names_tool( pattern: Annotated[ str, Field(description="A glob pattern to match filenames (e.g., '*.jpg').") ], ) -> List[str]: return await anki_call("getMediaFilesNames", pattern=pattern)
- src/anki_mcp/__init__.py:27-27 (registration)Registers the media_mcp server (containing the tool) into the main anki_mcp with 'media' prefix, exposing the tool as 'media_getMediaFilesNames'.await anki_mcp.import_server("media", media_mcp)
- src/anki_mcp/__init__.py:7-7 (registration)Imports the media_mcp instance which defines and registers the local tool.from .media_service import media_mcp
- src/anki_mcp/common.py:8-24 (helper)Shared utility function that performs HTTP calls to AnkiConnect API, used by the handler to invoke 'getMediaFilesNames' action.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