Skip to main content
Glama

store_media_file

Store an image or media file in Anki's media folder for use in flashcard fields. Accepts a local file path, URL, or base64 data to make media available for note creation or card updates.

Instructions

Store an image or media file in Anki's media folder.

Use this tool to store images that can be referenced in flashcard fields using
HTML img tags: <img src="filename">

This is useful when you need to:
- Store an image before creating a note (e.g. to reference it in multiple notes)
- Add an image to an existing card's field

Provide exactly one of url, data, or path:
- path: Absolute path to a local file. PREFERRED when the user shares an image file or screenshot.
- url: A URL to download the image from (e.g. "https://example.com/photo.jpg")
- data: Base64-encoded file content (for small images only)

IMPORTANT: When a user shares an image file or screenshot, prefer using "path" with the absolute
file path. AnkiConnect reads the file directly from disk, which avoids needing to base64-encode
large image files.

Args:
    filename: str - The filename to store the media as (e.g. "diagram.png").
    url: str - Optional URL to download the image from.
    data: str - Optional base64-encoded image data.
    path: str - Optional absolute path to a local file. Preferred for user-shared files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
urlNo
dataNo
pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for store_media_file. Decorated with @mcp.tool() and @handle_anki_connection_error. Accepts filename and one of url/data/path, delegates to the AnkiConnect client, and returns a success/error message.
    @mcp.tool()
    @handle_anki_connection_error
    async def store_media_file(
        filename: str,
        url: str | None = None,
        data: str | None = None,
        path: str | None = None,
    ) -> str:
        """Store an image or media file in Anki's media folder.
    
        Use this tool to store images that can be referenced in flashcard fields using
        HTML img tags: <img src="filename">
    
        This is useful when you need to:
        - Store an image before creating a note (e.g. to reference it in multiple notes)
        - Add an image to an existing card's field
    
        Provide exactly one of url, data, or path:
        - path: Absolute path to a local file. PREFERRED when the user shares an image file or screenshot.
        - url: A URL to download the image from (e.g. "https://example.com/photo.jpg")
        - data: Base64-encoded file content (for small images only)
    
        IMPORTANT: When a user shares an image file or screenshot, prefer using "path" with the absolute
        file path. AnkiConnect reads the file directly from disk, which avoids needing to base64-encode
        large image files.
    
        Args:
            filename: str - The filename to store the media as (e.g. "diagram.png").
            url: str - Optional URL to download the image from.
            data: str - Optional base64-encoded image data.
            path: str - Optional absolute path to a local file. Preferred for user-shared files.
        """
        if not url and not data and not path:
            return "SYSTEM_ERROR: Must provide either 'url', 'data', or 'path' for the media file."
    
        source = "path" if path else ("url" if url else "base64 data")
        async with get_anki_client() as anki:
            logger.info(f"Storing media file '{filename}' via {source}.")
    
            stored_filename = await anki.store_media_file(
                filename=filename,
                url=url,
                data=data,
                path=path,
            )
    
            if stored_filename:
                return (
                    f"Successfully stored media file as '{stored_filename}'. "
                    f'Reference it in card fields with: <img src="{stored_filename}">'
                )
            else:
                return f"SYSTEM_ERROR: Failed to store media file '{filename}'."
  • Input parameters for store_media_file tool: filename (required), url/data/path (optional, exactly one required).
        filename: str,
        url: str | None = None,
        data: str | None = None,
        path: str | None = None,
    ) -> str:
        """Store an image or media file in Anki's media folder.
    
        Use this tool to store images that can be referenced in flashcard fields using
        HTML img tags: <img src="filename">
    
        This is useful when you need to:
        - Store an image before creating a note (e.g. to reference it in multiple notes)
        - Add an image to an existing card's field
    
        Provide exactly one of url, data, or path:
        - path: Absolute path to a local file. PREFERRED when the user shares an image file or screenshot.
        - url: A URL to download the image from (e.g. "https://example.com/photo.jpg")
        - data: Base64-encoded file content (for small images only)
    
        IMPORTANT: When a user shares an image file or screenshot, prefer using "path" with the absolute
        file path. AnkiConnect reads the file directly from disk, which avoids needing to base64-encode
        large image files.
    
        Args:
            filename: str - The filename to store the media as (e.g. "diagram.png").
            url: str - Optional URL to download the image from.
            data: str - Optional base64-encoded image data.
            path: str - Optional absolute path to a local file. Preferred for user-shared files.
        """
  • Registration of store_media_file as an MCP tool via the @mcp.tool() decorator on the FastMCP instance.
    @mcp.tool()
    @handle_anki_connection_error
    async def store_media_file(
  • The AnkiConnectClient method that sends the storeMediaFile action to the AnkiConnect API. Builds the params dict and invokes via the generic invoke() method.
    async def store_media_file(
        self,
        filename: str,
        data: Optional[str] = None,
        url: Optional[str] = None,
        path: Optional[str] = None,
    ) -> str:
        """Store a media file in Anki's media folder.
    
        Provide exactly one of data, url, or path. If multiple are provided,
        AnkiConnect prioritizes: data > path > url.
    
        Returns the filename as stored by Anki.
        """
        params: dict[str, Any] = {"filename": filename}
        if data is not None:
            params["data"] = data
        if url is not None:
            params["url"] = url
        if path is not None:
            params["path"] = path
        return await self.invoke(AnkiAction.STORE_MEDIA_FILE, **params)
  • Enum value mapping the 'storeMediaFile' AnkiConnect action string.
    STORE_MEDIA_FILE = "storeMediaFile"
Behavior3/5

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

With no annotations, the description must cover behavioral traits. It explains that files are stored in Anki's media folder and recommends using 'path' for user-shared files. However, it omits details about overwriting, error handling, or permissions.

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

Conciseness4/5

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

The description is well-structured with a clear purpose statement, bulleted scenarios, and parameter details. It is front-loaded with key information, though some repetition and the 'IMPORTANT' note could be condensed.

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

Completeness3/5

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

Given the tool has an output schema, return value explanation is not needed. The description adequately covers usage and parameters, but lacks behavioral details like what happens if the filename already exists or if the file path is invalid, which are important for completeness.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It explains each parameter: filename, url, data, path, and the rule to provide exactly one of url/data/path. It adds value beyond the schema, but could be more precise about format requirements.

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 and resource: 'Store an image or media file in Anki's media folder.' It also explains use cases like referencing in flashcard fields, which distinguishes it from sibling tools that handle note creation or review.

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 provides specific scenarios for when to use the tool, such as storing an image before creating a note or adding to an existing card. However, it does not explicitly exclude use for other purposes or compare directly with sibling tools.

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/samefarrar/mcp-ankiconnect'

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