Skip to main content
Glama

media_storeMediaFile

Store media files in Anki's media folder using base64 data, local paths, or URLs to enhance flashcards with images, audio, or other multimedia content.

Instructions

Stores a media file in Anki's media folder. Provide one of 'data' (base64), 'path', or 'url'. Returns the stored filename or false on error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYesThe desired filename in Anki's media collection.
dataNoBase64-encoded file content.
pathNoAbsolute local path to the file.
urlNoURL to download the file from.
deleteExistingNoWhether to delete an existing file with the same name. Default is true.

Implementation Reference

  • The main handler function `store_media_file_tool` that implements the `media_storeMediaFile` tool logic. It validates that exactly one source (data, path, or url) is provided, constructs parameters, and delegates to AnkiConnect's `storeMediaFile` via `anki_call`.
    @media_mcp.tool(
        name="storeMediaFile",
        description="Stores a media file in Anki's media folder. Provide one of 'data' (base64), 'path', or 'url'. Returns the stored filename or false on error.",
    )
    async def store_media_file_tool(
        filename: Annotated[
            str, Field(description="The desired filename in Anki's media collection.")
        ],
        data: Annotated[
            Optional[str], Field(description="Base64-encoded file content.")
        ] = None,
        path: Annotated[
            Optional[str], Field(description="Absolute local path to the file.")
        ] = None,
        url: Annotated[
            Optional[str], Field(description="URL to download the file from.")
        ] = None,
        deleteExisting: Annotated[                                                            
            Optional[bool],
            Field(
                description="Whether to delete an existing file with the same name. Default is true."
            ),
        ] = True,
    ) -> Any:                                            
        params: Dict[str, Any] = {"filename": filename}
        source_count = sum(1 for src in (data, path, url) if src is not None)
        if source_count != 1:
            raise ValueError(
                "Exactly one of 'data', 'path', or 'url' must be provided for storeMediaFile."
            )
    
        if data:
            params["data"] = data
        elif path:
            params["path"] = path
        elif url:
            params["url"] = url
    
        if (
            deleteExisting is not None
        ):                                                                
            params["deleteExisting"] = deleteExisting
    
        return await anki_call("storeMediaFile", **params)
  • Registers the `media_mcp` FastMCP instance (containing the `storeMediaFile` tool) into the main `anki_mcp` server under the 'media' namespace, resulting in the tool name `media_storeMediaFile`.
    await anki_mcp.import_server("media", media_mcp)
  • Shared helper `anki_call` that performs HTTP POST requests to AnkiConnect API (localhost:8765), used by the handler to invoke the underlying `storeMediaFile` 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                                                                        
  • Pydantic schema definitions for the tool parameters using Annotated and Field for input validation and descriptions.
        filename: Annotated[
            str, Field(description="The desired filename in Anki's media collection.")
        ],
        data: Annotated[
            Optional[str], Field(description="Base64-encoded file content.")
        ] = None,
        path: Annotated[
            Optional[str], Field(description="Absolute local path to the file.")
        ] = None,
        url: Annotated[
            Optional[str], Field(description="URL to download the file from.")
        ] = None,
        deleteExisting: Annotated[                                                            
            Optional[bool],
            Field(
                description="Whether to delete an existing file with the same name. Default is true."
            ),
        ] = True,
    ) -> Any:                                            
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses key behavioral traits: the tool can accept multiple input types (data, path, url), returns either a filename or false on error, and operates on Anki's media folder. However, it doesn't mention permissions needed, rate limits, side effects beyond storage, or what happens with duplicate filenames beyond the deleteExisting parameter.

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 perfectly concise with two sentences that each earn their place: the first states the purpose and input options, the second states the return behavior. There's zero wasted language, and it's front-loaded with the core functionality.

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 moderate complexity (5 parameters, mutation operation), no annotations, and no output schema, the description does a reasonably complete job. It covers the core operation, input alternatives, and return values. However, it could better address error conditions, permissions, or interaction with sibling tools like media_deleteMediaFile for a more complete picture.

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?

Schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly. The description adds minimal value beyond the schema by mentioning the three alternative input sources (data, path, url) but doesn't provide additional syntax, format details, or constraints beyond what's in the parameter descriptions. This meets the baseline for high schema coverage.

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 specific action ('Stores a media file'), target location ('in Anki's media folder'), and distinguishes from siblings like media_deleteMediaFile and media_retrieveMediaFile by focusing on storage rather than deletion or retrieval. It uses precise verbs and specifies the resource being manipulated.

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 clear context for when to use this tool ('Provide one of 'data', 'path', or 'url'') which helps differentiate it from alternatives, but it doesn't explicitly state when NOT to use it or name specific sibling alternatives. The guidance is helpful but not exhaustive about 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