Skip to main content
Glama

get_attachment_content

Retrieve attached files from Kaltura videos to access supplementary materials like PDFs, presentation slides, or documents. Returns file content or download URLs for specific attachment IDs.

Instructions

Download or read ATTACHED FILES from videos. USE WHEN: Accessing supplementary materials, downloading PDFs, getting presentation slides, reading attached documents. RETURNS: File content (if text) or download URL. EXAMPLE: 'Download the PDF slides', 'Read the attached notes'. Use after list_attachment_assets to get specific attachment ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
attachment_asset_idYesAttachment ID from list_attachment_assets (format: '1_xyz789')

Implementation Reference

  • The core handler function implementing get_attachment_content tool. It retrieves attachment asset details using Kaltura API, generates download URL, downloads the content, base64 encodes it, and returns structured JSON with metadata and content.
    async def get_attachment_content(
        manager: KalturaClientManager,
        attachment_asset_id: str,
    ) -> str:
        """Get download URL and details for an attachment asset."""
    
        if not ATTACHMENT_AVAILABLE:
            return json.dumps(
                {
                    "error": "Attachment functionality is not available. The Attachment plugin is not installed.",
                    "attachmentAssetId": attachment_asset_id,
                },
                indent=2,
            )
    
        client = manager.get_client()
    
        try:
            # Get attachment asset details
            attachment_asset = client.attachment.attachmentAsset.get(attachment_asset_id)
    
            # Get the attachment download URL
            download_url = client.attachment.attachmentAsset.getUrl(attachment_asset_id)
    
            # Validate URL before making request
            if not download_url or not isinstance(download_url, str):
                return json.dumps(
                    {
                        "error": "Invalid or missing attachment download URL",
                        "attachmentAssetId": attachment_asset_id,
                    },
                    indent=2,
                )
            elif not download_url.startswith(("http://", "https://")):
                return json.dumps(
                    {
                        "error": "Attachment URL must use HTTP or HTTPS protocol",
                        "attachmentAssetId": attachment_asset_id,
                    },
                    indent=2,
                )
    
            # Download the actual attachment content
            attachment_content = None
            download_error = None
    
            try:
                # Create a session for downloading
                session = requests.Session()
    
                # Set headers
                headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}
    
                # Download the attachment content with timeout
                response = session.get(download_url, headers=headers, timeout=30)
                response.raise_for_status()
    
                # Encode content as base64
                import base64
    
                attachment_content = base64.b64encode(response.content).decode("utf-8")
    
            except requests.exceptions.RequestException as e:
                download_error = f"Failed to download attachment content: {str(e)}"
            except Exception as e:
                download_error = f"Error processing attachment content: {str(e)}"
    
            result = {
                "attachmentAssetId": attachment_asset_id,
                "entryId": attachment_asset.entryId,
                "filename": attachment_asset.filename,
                "title": attachment_asset.title,
                "format": attachment_asset.format.value
                if hasattr(attachment_asset.format, "value")
                else str(attachment_asset.format),
                "downloadUrl": download_url,
                "size": attachment_asset.size,
                "description": attachment_asset.description,
                "tags": attachment_asset.tags,
            }
    
            if download_error:
                result["downloadError"] = download_error
                result[
                    "note"
                ] = "Failed to download content automatically. You can try the downloadUrl manually."
            else:
                result["content"] = attachment_content
                result["contentEncoding"] = "base64"
                result["note"] = "Content downloaded and encoded as base64"
    
            return json.dumps(result, indent=2)
    
        except Exception as e:
            return json.dumps(
                {
                    "error": f"Failed to get attachment content: {str(e)}",
                    "attachmentAssetId": attachment_asset_id,
                },
                indent=2,
            )
  • Tool registration in MCP server's list_tools() function, defining name, description, and input schema.
        types.Tool(
            name="get_attachment_content",
            description="Download or read ATTACHED FILES from videos. USE WHEN: Accessing supplementary materials, downloading PDFs, getting presentation slides, reading attached documents. RETURNS: File content (if text) or download URL. EXAMPLE: 'Download the PDF slides', 'Read the attached notes'. Use after list_attachment_assets to get specific attachment ID.",
            inputSchema={
                "type": "object",
                "properties": {
                    "attachment_asset_id": {
                        "type": "string",
                        "description": "Attachment ID from list_attachment_assets (format: '1_xyz789')",
                    },
                },
                "required": ["attachment_asset_id"],
            },
        ),
    ]
  • Input schema definition for the get_attachment_content tool, specifying the required attachment_asset_id parameter.
    inputSchema={
        "type": "object",
        "properties": {
            "attachment_asset_id": {
                "type": "string",
                "description": "Attachment ID from list_attachment_assets (format: '1_xyz789')",
            },
        },
        "required": ["attachment_asset_id"],
    },
  • Dispatch/execution routing in the server's call_tool() method for invoking the get_attachment_content handler.
    elif name == "get_attachment_content":
        result = await get_attachment_content(kaltura_manager, **arguments)
  • Import and export of the get_attachment_content function in the tools module __init__.py for easy access.
        get_attachment_content,
        get_caption_content,
        list_attachment_assets,
        list_caption_assets,
    )
    
    # Import by domain for clear organization
    from .media import (
        get_download_url,
        get_media_entry,
        get_thumbnail_url,
        list_media_entries,
    )
    from .search import (
        esearch_entries,
        list_categories,
        search_entries,
        search_entries_intelligent,
    )
    from .utils import (
        handle_kaltura_error,
        safe_serialize_kaltura_field,
        validate_entry_id,
    )
    
    # Export all tools
    __all__ = [
        # Utilities
        "handle_kaltura_error",
        "safe_serialize_kaltura_field",
        "validate_entry_id",
        # Media operations
        "get_download_url",
        "get_media_entry",
        "get_thumbnail_url",
        "list_media_entries",
        # Analytics operations
        "get_analytics",
        "get_analytics_timeseries",
        "get_video_retention",
        "get_realtime_metrics",
        "get_quality_metrics",
        "get_geographic_breakdown",
        "list_analytics_capabilities",
        # Search operations
        "esearch_entries",
        "list_categories",
        "search_entries",
        "search_entries_intelligent",
        # Asset operations
        "get_attachment_content",

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/zoharbabin/kaltura-mcp'

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