Skip to main content
Glama

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
NameRequiredDescriptionDefault
filenameYesThe name of the media file in Anki's collection.

Implementation Reference

  • 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)
  • 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)
  • 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                                                                        
  • Creates the sub-MCP server 'AnkiMediaService' where the retrieveMediaFile tool is initially registered (before namespacing).
    media_mcp = FastMCP(name="AnkiMediaService")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool retrieves base64-encoded contents and returns false if the file is not found, which is useful behavioral context. However, it lacks details on permissions, rate limits, error handling beyond 'not found', or side effects (e.g., if this logs access). For a retrieval tool with no annotations, this is adequate but not comprehensive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences that are front-loaded with the core action and resource, followed by return value details. Every sentence earns its place by specifying retrieval, encoding, and error handling, with zero waste or redundancy, making it highly efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (single parameter, no output schema, no annotations), the description is mostly complete: it covers purpose, output format, and error case. However, it lacks details on behavioral aspects like permissions or side effects, which would be beneficial for a retrieval tool in a media context. It's sufficient but could be slightly enhanced for full completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the parameter 'filename' documented as 'The name of the media file in Anki's collection.' The description adds no additional parameter semantics beyond what the schema provides, such as file format constraints or path details. With high schema coverage, the baseline score of 3 is appropriate, as the description does not compensate but also doesn't need to.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'retrieves' and the resource 'base64-encoded contents of the specified media file', specifying both the action and the exact output format. It distinguishes from sibling tools like media_getMediaFilesNames (which lists files) and media_storeMediaFile (which uploads files), making the purpose specific and differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by stating 'Returns the base64 string or false if not found', suggesting it's for fetching file contents and handling missing files. However, it does not explicitly state when to use this versus alternatives like media_getMediaFilesNames for listing files or media_storeMediaFile for uploading, nor does it mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ujisati/anki-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server