Skip to main content
Glama

upload_asset

Upload a local photo or video file to your Immich library. Optionally assign the new asset to an album.

Instructions

Upload a local photo or video file to Immich. Use this to ingest new media into the library. Constraints: max 25MB, allowed types: jpg, jpeg, png, heic, mp4, mov, gif, webp. Symlinks are rejected for security. The original file is NOT modified or deleted. Side effect: creates a new asset in Immich.

Args:
    file_path: Absolute path to the local file (e.g. '/tmp/photo.jpg'). Must exist.
    album_id: Optional album UUID to add the uploaded asset to immediately.

Returns: JSON with new asset id, filename, size_mb, and album assignment status if applicable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
album_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'upload_asset' — validates the file path, checks extension/size, calls the client's upload_asset, and optionally adds the uploaded asset to an album.
    @mcp.tool()
    async def upload_asset(ctx: Context, file_path: str, album_id: str = "") -> str:
        """Upload a local photo or video file to Immich. Use this to ingest new media into
        the library. Constraints: max 25MB, allowed types: jpg, jpeg, png, heic, mp4, mov,
        gif, webp. Symlinks are rejected for security. The original file is NOT modified or
        deleted. Side effect: creates a new asset in Immich.
    
        Args:
            file_path: Absolute path to the local file (e.g. '/tmp/photo.jpg'). Must exist.
            album_id: Optional album UUID to add the uploaded asset to immediately.
    
        Returns: JSON with new asset id, filename, size_mb, and album assignment status if applicable.
        """
        import os
    
        if not os.path.isfile(file_path):
            return json.dumps({"error": f"File not found: {file_path}"})
    
        # Resolve symlinks and verify real path
        real_path = os.path.realpath(file_path)
        if real_path != file_path and os.path.islink(file_path):
            return json.dumps({"error": "Symlinks are not allowed for security."})
        file_path = real_path
    
        ext = os.path.splitext(file_path)[1].lower()
        if ext not in ALLOWED_UPLOAD_EXTENSIONS:
            return json.dumps({"error": f"Unsupported file type: {ext}. Allowed: {', '.join(sorted(ALLOWED_UPLOAD_EXTENSIONS))}"})
    
        size = os.path.getsize(file_path)
        if size > MAX_UPLOAD_SIZE:
            return json.dumps({"error": f"File too large: {size / 1024 / 1024:.1f}MB. Max: 25MB."})
    
        client = _client(ctx)
        try:
            result = await client.upload_asset(file_path)
        except httpx.HTTPStatusError as e:
            return json.dumps({"error": f"Immich API error: {e.response.status_code}", "detail": e.response.text[:200]})
    
        if album_id and result.get("id"):
            try:
                await client.add_assets_to_album(album_id, [result["id"]])
                result["added_to_album"] = album_id
            except Exception as e:
                result["album_error"] = str(e)
    
        result["uploaded_file"] = os.path.basename(file_path)
        result["size_mb"] = round(size / 1024 / 1024, 2)
        return json.dumps(result, default=str)
  • ImmichClient.upload_asset — the actual HTTP client method that POSTs the file to Immich's /api/assets endpoint with multipart form data.
    async def upload_asset(self, file_path: str) -> dict:
        """Upload a file to Immich."""
        from datetime import datetime, timezone
    
        stat = os.stat(file_path)
        filename = os.path.basename(file_path)
        birth = getattr(stat, 'st_birthtime', stat.st_mtime)
        created = datetime.fromtimestamp(birth, tz=timezone.utc).isoformat()
        modified = datetime.fromtimestamp(stat.st_mtime, tz=timezone.utc).isoformat()
    
        url = f"{self.base_url}/api/assets"
        with open(file_path, "rb") as f:
            files = {"assetData": (filename, f, "application/octet-stream")}
            data = {
                "deviceAssetId": f"{filename}-{stat.st_size}-{int(stat.st_mtime)}",
                "deviceId": "MCP Upload",
                "fileCreatedAt": created,
                "fileModifiedAt": modified,
                "isFavorite": "false",
            }
            async with httpx.AsyncClient(timeout=60.0) as client:
                response = await client.post(
                    url, headers={"x-api-key": self.api_key},
                    files=files, data=data,
                )
                response.raise_for_status()
                return response.json()
  • Tool registration via @mcp.tool() decorator on the upload_asset function.
    @mcp.tool()
  • Constants defining allowed upload extensions and max file size (25MB).
    ALLOWED_UPLOAD_EXTENSIONS = {".jpg", ".jpeg", ".png", ".heic", ".mp4", ".mov", ".gif", ".webp"}
Behavior5/5

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

With no annotations, the description carries the full burden and delivers thoroughly. It explains side effects (creates new asset), security restrictions (symlinks rejected), and that the original file is untouched. The return format is also described.

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 well-organized, starting with a clear purpose, followed by constraints in a bullet-like format, and parameter details. Every sentence adds value with no redundancy.

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

Completeness5/5

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

Given the tool's complexity, the description covers all necessary aspects: purpose, usage context, behavioral details, parameter semantics, and return value. No gaps are evident.

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

Parameters5/5

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

Despite the input schema having no parameter descriptions (0% coverage), the description adds rich meaning: file_path is an absolute path that must exist, and album_id is an optional UUID for immediate album assignment. This fully compensates for the schema's lack of detail.

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 'Upload' and the resource 'local photo or video file to Immich', and specifies its use for ingesting new media. It distinguishes itself from sibling tools which perform other operations like album management or search.

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?

It provides explicit constraints (max 25MB, allowed types, symlinks rejected) and context for when to use the tool. However, it does not explicitly mention when not to use it or suggest alternatives, though the context of siblings makes it clear.

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/drolosoft/immich-photo-manager'

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