Skip to main content
Glama

fetch

Retrieve complete record data by ID from Meta Ads campaigns, including account, campaign, ad, and page information with metadata.

Instructions

Fetch complete record data by ID.
It retrieves the full data for a specific record identified by its ID.

Args:
    id: The record ID to fetch (format: "type:id", e.g., "account:act_123456")
    
Returns:
    JSON response with complete record data including id, title, text, and metadata
    
Example Usage:
    fetch(id="account:act_123456789")
    fetch(id="campaign:23842588888640185")
    fetch(id="ad:23842614006130185")
    fetch(id="page:123456789")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'fetch' tool handler: async function that takes an 'id' parameter, retrieves the corresponding record from the cache using _data_manager.fetch_record(id), and returns formatted JSON with id, title, text, metadata.
    @mcp_server.tool()
    async def fetch(
        id: str
    ) -> str:
        """
        Fetch complete record data by ID.
        It retrieves the full data for a specific record identified by its ID.
        
        Args:
            id: The record ID to fetch (format: "type:id", e.g., "account:act_123456")
            
        Returns:
            JSON response with complete record data including id, title, text, and metadata
            
        Example Usage:
            fetch(id="account:act_123456789")
            fetch(id="campaign:23842588888640185")
            fetch(id="ad:23842614006130185")
            fetch(id="page:123456789")
        """
        if not id:
            return json.dumps({
                "error": "id parameter is required"
            }, indent=2)
        
        try:
            # Use the data manager to fetch the record
            record = _data_manager.fetch_record(id)
            
            if record:
                logger.info(f"Record fetched successfully: {id}")
                return json.dumps(record, indent=2)
            else:
                logger.warning(f"Record not found: {id}")
                return json.dumps({
                    "error": f"Record not found: {id}",
                    "id": id
                }, indent=2)
                
        except Exception as e:
            error_msg = str(e)
            logger.error(f"Error in fetch tool: {error_msg}")
            
            return json.dumps({
                "error": "Failed to fetch record",
                "details": error_msg,
                "id": id
            }, indent=2) 
  • Helper method in MetaAdsDataManager class that implements the core fetch logic by retrieving records from the internal cache populated during search operations.
    def fetch_record(self, record_id: str) -> Optional[Dict[str, Any]]:
        """Fetch a cached record by ID
        
        Args:
            record_id: The record ID to fetch
            
        Returns:
            Record data or None if not found
        """
        logger.info(f"Fetching record: {record_id}")
        
        record = self._cache.get(record_id)
        if record:
            logger.debug(f"Record found in cache: {record['type']}")
            return record
        else:
            logger.warning(f"Record not found in cache: {record_id}")
            return None
  • Tool registration via the @mcp_server.tool() decorator on the fetch function, which registers it with the MCP server under the name 'fetch'.
    @mcp_server.tool()
    async def fetch(
        id: str
    ) -> str:
        """
        Fetch complete record data by ID.
        It retrieves the full data for a specific record identified by its ID.
        
        Args:
            id: The record ID to fetch (format: "type:id", e.g., "account:act_123456")
            
        Returns:
            JSON response with complete record data including id, title, text, and metadata
            
        Example Usage:
            fetch(id="account:act_123456789")
            fetch(id="campaign:23842588888640185")
            fetch(id="ad:23842614006130185")
            fetch(id="page:123456789")
        """
        if not id:
            return json.dumps({
                "error": "id parameter is required"
            }, indent=2)
        
        try:
            # Use the data manager to fetch the record
            record = _data_manager.fetch_record(id)
            
            if record:
                logger.info(f"Record fetched successfully: {id}")
                return json.dumps(record, indent=2)
            else:
                logger.warning(f"Record not found: {id}")
                return json.dumps({
                    "error": f"Record not found: {id}",
                    "id": id
                }, indent=2)
                
        except Exception as e:
            error_msg = str(e)
            logger.error(f"Error in fetch tool: {error_msg}")
            
            return json.dumps({
                "error": "Failed to fetch record",
                "details": error_msg,
                "id": id
            }, indent=2) 
  • Global instance of MetaAdsDataManager used by both search and fetch tools to manage cached data.
    _data_manager = MetaAdsDataManager()
  • Import statement in server.py that loads the openai_deep_research module, triggering registration of the 'fetch' tool via its decorators.
    from . import accounts, campaigns, adsets, ads, insights, authentication
    from . import ads_library, budget_schedules, reports, openai_deep_research
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It clearly indicates this is a read operation ('retrieves'), but lacks details on permissions, rate limits, error handling, or response structure beyond basic return values. The example usage helps but doesn't cover behavioral traits comprehensively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, args, returns, examples) and front-loaded key information. While slightly verbose with repetitive phrasing ('fetch complete record data' then 'retrieves the full data'), every sentence adds value and the example usage is particularly helpful.

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?

Given the tool's simplicity (single parameter, read-only operation) and the presence of an output schema, the description is reasonably complete. It explains the parameter thoroughly and indicates the return format, though it could benefit from more behavioral context given the lack of annotations.

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?

The schema description coverage is 0%, so the description must fully compensate. It provides excellent parameter semantics: it explains the 'id' parameter's purpose, format requirements with concrete examples, and clarifies the colon-separated 'type:id' structure. This adds significant value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('fetch') and resource ('complete record data by ID'), distinguishing it from siblings like 'get_account_info' or 'search' which handle different retrieval patterns. However, it doesn't explicitly differentiate from similar 'get_' tools that might also retrieve records by ID.

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?

The description provides no guidance on when to use this tool versus alternatives like 'get_ad_details' or 'search', nor does it mention prerequisites or exclusions. It simply describes what the tool does without contextual usage information.

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/pipeboard-co/meta-ads-mcp'

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