Google Ads MCP Server

repository·main·Indexed 20 days ago

https://github.com/googleads/google-ads-mcp

An implementation of the Model Context Protocol (MCP) that provides an interface for LLMs and AI agents to interact with the Google Ads API. It enables automated querying, metadata discovery, and reporting through tools like search, get_resource_metadata, and list_accessible_customers, as well as resources for metrics, segments, and release notes.

Tokens
3.8K
Snippets
6
Records
17
Agent score
61%

What's inside google-ads-mcp

  1. Overview of Google Ads MCP Server

    main
    The Google Ads MCP Server is an implementation of the Model Context Protocol (MCP) that allows LLMs and AI agents to interact with the Google Ads API. It provides a set of Tools and Resources that enable agents to search for account information, retrieve metadata about API resources, and access discovery documents or metrics.
  2. Identify Lost Opportunities via Impression Share

    main

    To find opportunities lost due to ad rank, bids, or budgets, analyze impression share metrics using the search tool:

    1. Query Impression Share:
      • Resource: campaign.
      • Fields: campaign.name, metrics.search_impression_share, metrics.search_rank_lost_impression_share, and metrics.search_budget_lost_impression_share.
    2. Analyze Results:
      • Budget Issues: High search_budget_lost_impression_share suggests the budget is too low.
      • Rank Issues: High search_rank_lost_impression_share suggests issues with bids or ad quality.
  3. Configure Credentials using Application Default Credentials (ADC)

    main

    You can use gcloud to set up Application Default Credentials. Ensure the credentials include the Google Ads API scope: https://www.googleapis.com/auth/adwords.

    Set up ADC with user credentials:

    gcloud auth application-default login \
      --scopes https://www.googleapis.com/auth/adwords,https://www.googleapis.com/auth/cloud-platform \
      --client-id-file=YOUR_CLIENT_JSON_FILE

    Set up ADC with service account impersonation:

    gcloud auth application-default login \
      --impersonate-service-account=SERVICE_ACCOUNT_EMAIL \
      --scopes=https://www.googleapis.com/auth/adwords,https://www.googleapis.com/auth/cloud-platform

    After running the command, note the PATH_TO_CREDENTIALS_JSON provided in the output for use in your MCP client configuration.

    gcloud auth application-default login \
      --scopes https://www.googleapis.com/auth/adwords,https://www.googleapis.com/auth/cloud-platform \
      --client-id-file=YOUR_CLIENT_JSON_FILE
  4. Install Agent Skills for Google Ads

    main

    This repository provides specialized workflows called Agent Skills. The available skill is:

    • account-performance-diagnostics: Located in ads_mcp/skills/account-performance-diagnostics. It diagnoses issues like conversion loss, low lead flow, and lost opportunities.

    To use these skills, point your skills-compatible AI agent (such as Claude Code, Cursor, or Antigravity CLI) to the skill directory. For Antigravity CLI, you can copy the folder to your skills directory or reference it.

  5. Deploy Google Ads MCP Server to Google Cloud Run

    main

    You can host the Google Ads MCP server on Google Cloud Run to share it across different agents or run it as a web service. This deployment method requires authentication via an OAuth Client ID and Client Secret pair through an OAuth proxy.

    Prerequisites

    • A Google Cloud project.
    • gcloud CLI installed, authenticated, and the active project set using gcloud config set project YOUR_PROJECT_ID.

    Deployment Steps

    1. Build and Push Docker Image

    Use Cloud Build to push the image to Artifact Registry:

    1. Create a repository:
      gcloud artifacts repositories create mcp-servers --repository-format=docker --location=us-central1
    2. Submit the build:
      gcloud builds submit --tag us-central1-docker.pkg.dev/YOUR_PROJECT_ID/mcp-servers/google-ads-mcp:latest .

    2. Deploy to Cloud Run

    Deploy the image using gcloud run deploy. You must provide several environment variables for the server to function correctly.

    3. Configure MCP Client

    Update your MCP client configuration to point to the newly assigned Cloud Run URL.

    gcloud run deploy google-ads-mcp \
      --image us-central1-docker.pkg.dev/YOUR_PROJECT_ID/mcp-servers/google-ads-mcp:latest \
      --platform managed \
      --region us-central1 \
      --allow-unauthenticated \
      --set-env-vars="GOOGLE_PROJECT_ID=YOUR_PROJECT_ID,GOOGLE_ADS_DEVELOPER_TOKEN=YOUR_DEVELOPER_TOKEN,GOOGLE_ADS_MCP_OAUTH_CLIENT_ID=YOUR_CLIENT_ID,GOOGLE_ADS_MCP_OAUTH_CLIENT_SECRET=YOUR_CLIENT_SECRET,GOOGLE_ADS_MCP_BASE_URL=YOUR_BASE_URL,GOOGLE_ADS_MCP_JWT_SIGNING_KEY=YOUR_JWT_SIGNING_KEY,FASTMCP_HOST=0.0.0.0"
  6. Setup Google Ads MCP Server

    main

    To set up the server, follow these high-level steps:

    1. Configure Python: Install pipx.
    2. Configure Developer Token: Obtain a Google Ads Developer Token with at least Explorer access.
    3. Enable APIs: Enable the Google Ads API in your Google Cloud project.
    4. Configure Credentials: Choose one of three methods:
      • FastMCP OAuth Proxy: For web service deployments using dynamic user authentication.
      • Application Default Credentials (ADC): Using gcloud to authenticate locally or via service account impersonation.
      • Google Ads API Python Client Library: Reusing an existing google-ads.yaml configuration.
    5. Configure MCP Client: Add the server to your client (e.g., Claude Code, Cursor, VS Code) using the appropriate configuration format.
  7. Diagnose Conversion and Conversion Value Loss

    main

    When conversions or conversion value decline, follow these steps using the Google Ads MCP server:

    1. Discover Fields: Use get_resource_metadata with the campaign or ad_group resource to verify correct field names.
    2. Query Performance: Use the search tool to retrieve data.
      • Resource: campaign or ad_group.
      • Fields: Use campaign.name, metrics.conversions, metrics.conversion_value, and metrics.cost_micros.
      • Segments: Include segments.date, segments.device, or segments.conversion_action to isolate the cause.
      • Conditions: Use date filters (e.g., segments.date >= 'YYYY-MM-DD') to compare periods.
    3. Analyze: Determine if the loss is isolated to specific devices or conversion actions.
    4. Check Uploads: If using offline conversions, inspect offline_conversion_upload_conversion_action_summary for upload errors.
  8. Diagnose Low Lead Flow

    main

    If lead flow has dropped, follow this systematic diagnostic approach:

    1. Confirm the Drop: Query conversions segmented by segments.date for the recent period versus the previous period.
    2. Isolate the Cause:
      • Traffic Drop: If clicks or impressions decreased, check Impression Share metrics (Budget vs. Rank) or general search volume trends.
      • Conversion Rate Drop: If the ratio of conversions to clicks decreased, check breakdowns by segments.device or segments.conversion_action.
    3. Check Account Changes: Query the change_event resource to identify recent modifications to bids, budgets, or targeting that coincide with the performance drop.

    Important Constraint: Queries to the change_event resource must include a LIMIT of 10,000 or less.

  9. Configure MCP Client (Antigravity / Claude / Cursor)

    main

    Add the server to your MCP client configuration. The mcpServers block format is standard across clients like Claude Code, Cursor, and VS Code.

    Example: Using Application Default Credentials (ADC) Replace PATH_TO_CREDENTIALS_JSON and YOUR_PROJECT_ID with your actual values.

    {
      "mcpServers": {
        "google-ads-mcp": {
          "command": "pipx",
          "args": [
            "run",
            "--spec",
            "git+https://github.com/googleads/google-ads-mcp.git",
            "google-ads-mcp"
          ],
          "env": {
            "GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",
            "GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID",
            "GOOGLE_ADS_DEVELOPER_TOKEN": "YOUR_DEVELOPER_TOKEN"
          }
        }
      }
    }

    Example: Using FastMCP OAuth Proxy (SSE/HTTP) If running as a separate process via HTTP:

    {
      "mcpServers": {
        "google-ads-mcp": {
          "httpUrl":"http://localhost:8080/mcp",
          "env": {
            "GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID",
            "GOOGLE_ADS_DEVELOPER_TOKEN": "YOUR_DEVELOPER_TOKEN"                        
          }
        }
      }
    }

    Note on Manager Accounts: If accessing accounts through a manager account, add GOOGLE_ADS_LOGIN_CUSTOMER_ID to your env object with your manager customer ID.

    {
      "mcpServers": {
        "google-ads-mcp": {
          "command": "pipx",
          "args": [
            "run",
            "--spec",
            "git+https://github.com/googleads/google-ads-mcp.git",
            "google-ads-mcp"
          ],
          "env": {
            "GOOGLE_APPLICATION_CREDENTIALS": "PATH_TO_CREDENTIALS_JSON",
            "GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID",
            "GOOGLE_ADS_DEVELOPER_TOKEN": "YOUR_DEVELOPER_TOKEN",
            "GOOGLE_ADS_LOGIN_CUSTOMER_ID": "YOUR_MANAGER_CUSTOMER_ID"
          }
        }
      }
    }
  10. Environment variables for Google Ads MCP Cloud Run deployment

    main

    When deploying to Google Cloud Run, the following environment variables must be configured:

    VariableDescription
    GOOGLE_PROJECT_IDYour Google Cloud project ID
    GOOGLE_ADS_DEVELOPER_TOKENThe Google Ads developer token
    GOOGLE_ADS_MCP_OAUTH_CLIENT_IDThe OAuth Client ID
    GOOGLE_ADS_MCP_OAUTH_CLIENT_SECRETThe OAuth Client secret
    GOOGLE_ADS_MCP_BASE_URLThe base URL where the MCP server is accessible (assigned by Cloud Run)
    GOOGLE_ADS_MCP_JWT_SIGNING_KEY(Recommended) Persistent JWT signing key across instances
    GOOGLE_ADS_MCP_STORAGE_TYPE(Recommended) Storage backend (e.g., redis) to persist OAuth tokens
    GOOGLE_ADS_MCP_STORAGE_REDIS_URL(Recommended) URL for the Redis storage backend
    FASTMCP_HOSTSet to 0.0.0.0 to allow FastMCP to accept connections from all IP addresses
  11. Configure Credentials using FastMCP OAuth Proxy

    main

    When running the server as a web service, you can use FastMCP's OAuth proxy for dynamic authentication. Setting these variables automatically switches the server from stdio transport to streamable-http (SSE/HTTP).

    Required Environment Variables:

    • GOOGLE_ADS_MCP_OAUTH_CLIENT_ID: Your Google Cloud OAuth 2.0 Client ID.
    • GOOGLE_ADS_MCP_OAUTH_CLIENT_SECRET: Your Google Cloud OAuth 2.0 Client Secret.
    • GOOGLE_ADS_MCP_BASE_URL: (Optional) Base URL (defaults to http://localhost:8080).

    Other optional variables:

    • GOOGLE_ADS_MCP_JWT_SIGNING_KEY: Secret key for signing FastMCP JWT tokens.
    • GOOGLE_ADS_MCP_STORAGE_TYPE: Storage backend (filetree, redis, or memory).
    • GOOGLE_ADS_MCP_STORAGE_PATH: Path for filetree storage.
    • GOOGLE_ADS_MCP_STORAGE_REDIS_URL: URL for redis storage.
    • GOOGLE_ADS_MCP_STORAGE_ENCRYPTION_KEY: Encryption key for stored tokens.
    • GOOGLE_ADS_MCP_STORAGE_DISABLE_ENCRYPTION: Set to true to disable encryption.
  12. Configure and Namespace Tools via tools_config.yaml

    main

    You can selectively enable/disable tools or entire categories (namespaces) and customize their prefixes using a tools_config.yaml file.

    Resolution order for configuration:

    1. Path specified by GOOGLE_ADS_MCP_TOOLS_CONFIG environment variable.
    2. tools_config.yaml in the current working directory.
    3. Default tools_config.yaml bundled with the package.

    If an explicitly requested file is missing or invalid, the server will fail to start.

    namespaces:
      # Enable category 'customers' with default prefix -> "customers_list_accessible_customers"
      customers: true
    
      # Enable category 'search' with a custom prefix -> "query_search"
      search: "query"
    
      # Fine-grained control over tools in a category
      metadata:
        enabled: true
        prefix: "metadata"
        enabled_tools:
          - get_resource_metadata: true