Skip to main content
Glama
KaiQin04
by KaiQin04

download_instagram_post

Download Instagram posts, reels, and videos to your local filesystem with optional metadata and caption extraction. Save media files from Instagram URLs for offline access.

Instructions

Download an Instagram post's media files to the local filesystem.

Args: url: Instagram post/reel/tv URL. include_videos: Whether to download videos alongside pictures. save_metadata: Save JSON metadata files when available. save_caption: Save caption into a text file when available. username: Optional Instagram username for authenticated access. password: Optional Instagram password for authenticated access. download_root: Optional override for download directory.

Returns: A JSON-serializable dict containing download results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
include_videosNo
save_metadataNo
save_captionNo
usernameNo
passwordNo
download_rootNo

Implementation Reference

  • The @mcp.tool()-decorated function implementing the core logic of the 'download_instagram_post' tool. It extracts the shortcode from the URL, sets up Instaloader, handles login, downloads the post media, and returns paths to downloaded files.
    @mcp.tool() def download_instagram_post( url: str, include_videos: bool = True, save_metadata: bool = True, save_caption: bool = True, username: str | None = None, password: str | None = None, download_root: str | None = None, ) -> dict[str, Any]: """Download an Instagram post's media files to the local filesystem. Args: url: Instagram post/reel/tv URL. include_videos: Whether to download videos alongside pictures. save_metadata: Save JSON metadata files when available. save_caption: Save caption into a text file when available. username: Optional Instagram username for authenticated access. password: Optional Instagram password for authenticated access. download_root: Optional override for download directory. Returns: A JSON-serializable dict containing download results. """ try: shortcode = extract_shortcode(url) target_root = _resolve_download_root(download_root) loader = _build_instaloader( target_root, download_pictures=True, download_videos=include_videos, save_metadata=save_metadata, save_caption=save_caption, ) user, pwd = _resolve_credentials(username, password) _login_if_needed(loader, user, pwd) download_dir, downloaded_files = _download_post_for_shortcode( loader, shortcode, target_root, ) image_files = _collect_paths_by_suffixes( downloaded_files, {".jpg", ".jpeg", ".png", ".webp"}, ) video_files = _collect_paths_by_suffixes(downloaded_files, {".mp4"}) metadata_files = _collect_paths_by_suffixes( downloaded_files, {".json"}, ) caption_files = _collect_paths_by_suffixes( downloaded_files, {".txt"}, ) return { "success": True, "shortcode": shortcode, "download_dir": str(download_dir), "image_files": image_files, "video_files": video_files, "metadata_files": metadata_files, "caption_files": caption_files, } except instaloader.exceptions.InstaloaderException as exc: return { "success": False, "error": f"Instaloader error: {exc.__class__.__name__}: {exc}", } except Exception as exc: return {"success": False, "error": str(exc)}

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/KaiQin04/ig-download-mcp'

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