Skip to main content
Glama

get_ad_image

Retrieve ad image metadata and URL by image hash to access dimensions, name, and other details for ad management.

Instructions

Retrieve metadata and URL for an uploaded ad image by hash.

Returns the image URL, dimensions, name, and other metadata.

Args: account_id: Ad account ID (e.g., 'act_123456789'). image_hash: Image hash from upload_ad_image.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idYes
image_hashYes

Implementation Reference

  • The main handler function for the get_ad_image tool. Decorated with @mcp.tool(), it retrieves metadata and URL for an uploaded ad image by hash using the Meta Graph API. Validates input, strips the image_hash, ensures account_id format, calls /{account_id}/adimages with the image hash, and returns image metadata (url, dimensions, name, status, etc.) or an error.
    @mcp.tool()
    def get_ad_image(
        account_id: str,
        image_hash: str,
    ) -> dict:
        """
        Retrieve metadata and URL for an uploaded ad image by hash.
    
        Returns the image URL, dimensions, name, and other metadata.
    
        Args:
            account_id: Ad account ID (e.g., 'act_123456789').
            image_hash: Image hash from upload_ad_image.
        """
        if not image_hash or not image_hash.strip():
            return {"error": "image_hash is required.", "blocked_at": "input_validation"}
    
        account_id = ensure_account_id_format(account_id)
        image_hash = image_hash.strip()
    
        api_client._ensure_initialized()
    
        try:
            result = api_client.graph_get(
                f"/{account_id}/adimages",
                fields=["hash", "name", "url", "url_128", "width", "height", "status", "created_time"],
                params={"hashes": f'["{image_hash}"]'},
            )
        except MetaAPIError as e:
            return {"error": f"Meta API error: {e}", "blocked_at": "api_call"}
    
        images = result.get("data", [])
        if not images:
            return {
                "error": f"No image found for hash '{image_hash}'.",
                "blocked_at": "not_found",
            }
    
        img = images[0]
        return {
            "account_id": account_id,
            "image_hash": img.get("hash", image_hash),
            "name": img.get("name"),
            "url": img.get("url"),
            "url_128": img.get("url_128"),
            "width": img.get("width"),
            "height": img.get("height"),
            "status": img.get("status"),
            "created_time": img.get("created_time"),
            "rate_limit_usage_pct": api_client.rate_limits.max_usage_pct,
        }
  • Test class for get_ad_image. Verifies the function is callable, registered with @mcp.tool(), and that empty input returns an error.
    class TestGetAdImage:
    
        def test_function_exists(self):
            from meta_ads_mcp.core.images import get_ad_image
            assert callable(get_ad_image)
    
        def test_tool_is_registered(self):
            import inspect
            from meta_ads_mcp.core import images
            source = inspect.getsource(images)
            lines = source.split("\n")
            for i, line in enumerate(lines):
                if "def get_ad_image(" in line:
                    for j in range(max(0, i - 3), i):
                        if "@mcp.tool()" in lines[j] and not lines[j].strip().startswith("#"):
                            return
                    pytest.fail("get_ad_image not registered")
    
        def test_empty_hash_returns_error(self):
            from meta_ads_mcp.core.images import get_ad_image
            result = get_ad_image(account_id="act_123", image_hash="")
            assert "error" in result
            assert result["blocked_at"] == "input_validation"
Behavior3/5

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

Although no annotations are provided, the description outlines the returned data (URL, dimensions, name, metadata) but lacks details on side effects, authentication needs, or error handling.

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?

Concise two-sentence description plus arg details, front-loaded with purpose. Every sentence adds value, no fluff.

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?

Simple tool with 2 params; description covers returned fields (URL, dimensions, name, metadata) adequately. Lacks output schema but provides enough context for basic usage.

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

Parameters4/5

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

Input schema has 0% description coverage, but the description adds meaning by specifying account_id format (e.g., 'act_123456789') and linking image_hash to upload_ad_image, compensating for schema gaps.

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 tool retrieves metadata and URL for an ad image by hash, using specific verb and resource. It effectively distinguishes from sibling tools like upload_ad_image.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool vs alternatives (e.g., get_ad_creatives, upload_ad_image). Missing prerequisites or context for invocation.

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/brandu-mos/konquest-meta-ads-mcp'

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