Skip to main content
Glama
johnoconnor0

Google Ads MCP Server

by johnoconnor0

google_ads_custom_query

Execute custom Google Ads Query Language (GAQL) queries to extract specific performance data. Write your own query to retrieve metrics, keywords, or campaign details.

Instructions

Execute a custom Google Ads Query Language (GAQL) query.

For advanced users who want to write their own GAQL queries. Use the Google Ads Query Builder to construct queries: https://developers.google.com/google-ads/api/fields/latest/overview_query_builder

Args: customer_id: Customer ID (without hyphens) query: GAQL query string response_format: Output format ('json' or 'markdown')

Returns: Query results in specified format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
customer_idYes
queryYes
response_formatNojson

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The tool is registered using the @mcp.tool() decorator on FastMCP instance.
    @mcp.tool()
  • The handler function that executes a custom GAQL query against the Google Ads API via GoogleAdsService.search(), supporting JSON and markdown output formats.
    def google_ads_custom_query(
        customer_id: str,
        query: str,
        response_format: str = "json",
    ) -> str:
        """
        Execute a custom Google Ads Query Language (GAQL) query.
    
        For advanced users who want to write their own GAQL queries. Use the
        Google Ads Query Builder to construct queries:
        https://developers.google.com/google-ads/api/fields/latest/overview_query_builder
    
        Args:
            customer_id: Customer ID (without hyphens)
            query: GAQL query string
            response_format: Output format ('json' or 'markdown')
    
        Returns:
            Query results in specified format
        """
        try:
            client = get_auth_manager().get_client()
            ga_service = client.get_service("GoogleAdsService")
            clean_id = customer_id.replace("-", "")
    
            response = ga_service.search(customer_id=clean_id, query=query)
    
            results = []
            for row in response:
                row_dict = {}
                for field_name in type(row).meta.fields.keys():
                    value = getattr(row, field_name, None)
                    if value:
                        row_dict[field_name] = str(value)
                results.append(row_dict)
    
            header = f"# Custom Query Results\n\n**Query**: {query}\n\n**Result Count**: {len(results)}\n\n"
    
            if response_format == "json":
                return header + json.dumps(results, indent=2, default=str)
    
            if not results:
                return header + "No results found."
    
            keys = list(results[0].keys())
            table = "| " + " | ".join(keys) + " |\n"
            table += "| " + " | ".join("---" for _ in keys) + " |\n"
            for r in results:
                table += "| " + " | ".join(str(r.get(k, ""))[:60] for k in keys) + " |\n"
            return header + table
    
        except Exception as exc:
            return f"❌ Custom query failed: {exc}"
  • Function signature defines parameters: customer_id (str), query (str), response_format (str, default='json') with defaults and docstring acting as schema.
    def google_ads_custom_query(
        customer_id: str,
        query: str,
        response_format: str = "json",
    ) -> str:
Behavior2/5

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

No annotations are provided, so the description must disclose behavioral traits. It does not mention whether the query is read-only, potential side effects, error handling, or rate limits. The tool could be used for mutating data via GAQL, but the description is silent on this, posing a risk for agents.

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?

The description is concise: a one-sentence purpose, a contextual note with a link, and a brief parameter list. Every sentence adds value with no redundancy or 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?

Given the complexity of custom GAQL queries and the presence of an output schema, the description adequately introduces the tool's purpose and parameters. It could be enhanced with a note on typical use cases or safety (e.g., read-only constraint), but it is otherwise sufficient for selection.

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?

With 0% schema description coverage, the description adds meaning beyond the schema by explaining that customer_id should be without hyphens, query is a GAQL string, and response_format accepts 'json' or 'markdown'. This helps agents correctly populate parameters.

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 executes a custom GAQL query, distinguishing it from the many specific Google Ads tools in the sibling list. The verb 'Execute' and resource 'GAQL query' are specific and unambiguous.

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

Usage Guidelines4/5

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

The description explicitly targets 'advanced users who want to write their own GAQL queries,' providing a clear use case. It also includes a link to the query builder. However, it does not explicitly state when not to use this tool or mention alternatives, which would be helpful given the many siblings.

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/johnoconnor0/google-ads-mcp'

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