get_attachment_content
Retrieve or download supplementary files attached to videos, such as PDFs or presentation slides, by specifying the attachment ID. Use to access and extract document content or obtain download links for attached materials.
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
| Name | Required | Description | Default |
|---|---|---|---|
| attachment_asset_id | Yes | Attachment ID from list_attachment_assets (format: '1_xyz789') |
Implementation Reference
- src/kaltura_mcp/tools/assets.py:263-363 (handler)The core handler function implementing the get_attachment_content tool. It retrieves attachment asset details from Kaltura, generates download URL, downloads the content, base64 encodes it, and returns JSON with details 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, )
- src/kaltura_mcp/server.py:476-489 (registration)Registers the get_attachment_content tool with the MCP server in list_tools(), including 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"], }, ),
- src/kaltura_mcp/server.py:527-528 (registration)Dispatches the tool call in the server's call_tool handler by invoking the get_attachment_content function.elif name == "get_attachment_content": result = await get_attachment_content(kaltura_manager, **arguments)