Google Ads with Claude: changing campaigns through the API, without MCP
The official Google Ads MCP server only reads. To let Claude change campaigns, skip MCP and have it write small Python scripts on the official google-ads library. Every change first runs with validate_only=True, so Google checks the request without applying it; it's applied only after an explicit yes, and the campaign is read back afterwards. Access needs a Google Cloud project with the Google Ads API enabled, a Desktop OAuth client and a refresh token; developer tokens were sunset in September 2026.
Claude
Google Ads
Python
The setup is simple: Claude Code on my laptop, the official Python library google-ads, and one config file with OAuth credentials. Every task is a small script that Claude writes and runs. Below is how it’s set up, the loop that keeps it safe, ready scripts, rules for Claude, and the API pitfalls I hit.
Three ways to connect Claude to Google Ads
| Official Google Ads MCP | Third-party MCP with write access | Scripts on the google-ads library | |
|---|---|---|---|
| Reads data (GAQL) | Yes | Yes | Yes |
| Changes campaigns | No | Yes | Yes |
| Dry run before applying | Not needed | Depends on the server | Yes, validate_only |
| What you review | The query | The tool call | The script: exact fields and update mask |
| Trace of changes | None | The server’s logs, if any | A script file per change |
| Who holds your OAuth tokens | You | Often the vendor | You |
| Cost | Free | Often a subscription | Free |
For reporting the official MCP is enough. For changes I prefer scripts:
- A script is reviewable. I see the exact fields and the update mask before anything runs.
- Dry runs come for free. Google checks the request and returns real errors, but changes nothing.
- It stays as a log. Every applied change is a file with a name, so a month later it’s clear what was done and why.
Access, set up once
You need three things:
- A Google Cloud project with the Google Ads API enabled. Since September 9, 2026 the API access level belongs to the project, not to a developer token. Check the level on the Google Ads API overview page of the project in Cloud console.
- An OAuth client of the Desktop type in that project, with the
https://www.googleapis.com/auth/adwordsscope on the consent screen. If the consent screen stays in Testing, refresh tokens expire after a week, so publish it to production. - A refresh token. A short
auth.pygets it once:InstalledAppFlow.run_local_server(port=0, prompt="consent", access_type="offline"), you sign in with an account that has access to the manager account (MCC), and the script writes the token into the config.
Install the library with pip install google-ads. On Windows run scripts with PYTHONIOENCODING=utf-8, otherwise non-Latin campaign names crash the output.
The config is google-ads.yaml next to the scripts. Every script loads it with GoogleAdsClient.load_from_storage(...):
client_id: ...
client_secret: ...
refresh_token: ...
login_customer_id: "1234567890" # the MCC, without dashes
use_proto_plus: true
This file holds secrets. Claude must never print it to the chat or commit it: add it to .gitignore and say so in the rules below.
The loop: read, propose, dry run, apply, read again
This part matters more than code. Claude follows it for every change:
- Read. Before touching anything, pull the current state: campaign type, bidding, budget, locations, languages, what it optimizes for, recent conversions.
- Propose. Write in plain words what will change and wait for an explicit “yes”.
- Write a script with an
--applyflag. Without the flag it sends the request withvalidate_only=True. - Dry run. Run without the flag and make sure Google returns no errors.
- Apply. Run with
--apply. - Read again. Confirm the change is there and that budget and bids didn’t move.
Step 1: read the campaign
SELECT campaign.id, campaign.name, campaign.status,
campaign.advertising_channel_type, campaign.bidding_strategy_type,
campaign.target_cpa.target_cpa_micros, campaign_budget.amount_micros,
campaign.app_campaign_setting.app_id,
campaign.selective_optimization.conversion_actions,
campaign.contains_eu_political_advertising
FROM campaign
WHERE campaign.id = 1234567890
Locations and languages live in a separate resource:
SELECT campaign_criterion.type, campaign_criterion.location.geo_target_constant,
campaign_criterion.language.language_constant, campaign_criterion.negative
FROM campaign_criterion
WHERE campaign.id = 1234567890
AND campaign_criterion.type IN ('LOCATION', 'LANGUAGE')
Amounts come in micros: divide by 1,000,000 to get the currency value.
Step 2: a change with a dry run
The skeleton every change script follows. This one switches the conversions an App campaign optimizes for:
import argparse
from google.ads.googleads.client import GoogleAdsClient
from google.api_core import protobuf_helpers
p = argparse.ArgumentParser()
p.add_argument("customer_id")
p.add_argument("campaign_id")
p.add_argument("--apply", action="store_true")
args = p.parse_args()
client = GoogleAdsClient.load_from_storage("google-ads.yaml")
svc = client.get_service("CampaignService")
conv = client.get_service("ConversionActionService")
op = client.get_type("CampaignOperation")
c = op.update
c.resource_name = svc.campaign_path(args.customer_id, args.campaign_id)
c.selective_optimization.conversion_actions.extend([
conv.conversion_action_path(args.customer_id, "111"), # e.g. first_open
conv.conversion_action_path(args.customer_id, "222"), # e.g. trial_started
])
client.copy_from(op.update_mask, protobuf_helpers.field_mask(None, c._pb))
req = client.get_type("MutateCampaignsRequest")
req.customer_id = args.customer_id
req.operations.append(op)
req.validate_only = not args.apply
svc.mutate_campaigns(request=req)
print("applied" if args.apply else "dry run OK, nothing changed")
validate_only isn’t a keyword argument of the method in the Python library: build the request object, set the field on it and pass it as request=.
Step 3: several changes at once, atomically
When changes depend on each other, send them in one GoogleAdsService.mutate call: either everything applies or nothing does. Example: add Germany, France and English to a campaign. For existing campaigns Google requires the EU political ads declaration before location targeting changes, so it goes into the same request:
from google.ads.googleads.client import GoogleAdsClient
from google.api_core import protobuf_helpers
client = GoogleAdsClient.load_from_storage("google-ads.yaml")
cid, camp_id, apply = "1234567890", "9876543210", False
camp_path = client.get_service("CampaignService").campaign_path(cid, camp_id)
geo = client.get_service("GeoTargetConstantService")
ops = []
op = client.get_type("MutateOperation")
c = op.campaign_operation.update
c.resource_name = camp_path
c.contains_eu_political_advertising = (
client.enums.EuPoliticalAdvertisingStatusEnum.DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING
)
client.copy_from(op.campaign_operation.update_mask, protobuf_helpers.field_mask(None, c._pb))
ops.append(op)
for geo_id in ("2276", "2250"): # Germany, France
op = client.get_type("MutateOperation")
cc = op.campaign_criterion_operation.create
cc.campaign = camp_path
cc.location.geo_target_constant = geo.geo_target_constant_path(geo_id)
ops.append(op)
op = client.get_type("MutateOperation")
cc = op.campaign_criterion_operation.create
cc.campaign = camp_path
cc.language.language_constant = "languageConstants/1000" # English
ops.append(op)
req = client.get_type("MutateGoogleAdsRequest")
req.customer_id = cid
req.mutate_operations.extend(ops)
req.validate_only = not apply
client.get_service("GoogleAdsService").mutate(request=req)
Rules for Claude
I keep these in CLAUDE.md in the scripts folder, so every session starts with them:
# Google Ads work rules
- Never print or commit google-ads.yaml. It holds secrets.
- Before any change, read the campaign: type, bidding, budget, locations, languages, optimization goals, conversions.
- Describe the change in plain words and wait for an explicit "yes". No yes, no apply.
- Every change script has an --apply flag. Without it, the request goes with validate_only=True.
- Run without --apply first. Apply only after a clean dry run.
- Never touch budgets, bids or campaign status unless the task says so.
- After applying, read the campaign again and confirm nothing else moved.
- Related changes go into one GoogleAdsService.mutate call.
- At the end of the session, update HANDOFF.md: what changed, campaign IDs, what to check next.
Common errors
| Error | What it means | Fix |
|---|---|---|
CriterionError.MISSING_EU_POLITICAL_ADVERTISING_SELF_DECLARATION |
The campaign has no EU political ads declaration, so location targeting can’t change | Set contains_eu_political_advertising in the same mutate |
MutateError.EU_POLITICAL_ADVERTISING_DECLARATION_REQUIRED |
The account has undeclared campaigns, so campaign management mutates fail | Declare those campaigns first; find them with campaign.missing_eu_political_advertising_declaration = true |
FieldError.REQUIRED on campaign creation |
A new campaign was sent without the EU declaration | Set the field when creating the campaign |
CLOUD_PROJECT_NOT_APPROVED_FOR_PRODUCTION |
The Cloud project only has test account access | Apply for a higher access level for the project |
USER_PERMISSION_DENIED |
Usually login_customer_id is missing or wrong when working through an MCC |
Set the manager account ID, digits only |
A query error about segments.conversion_action |
The segment is used but missing from SELECT | Add it to SELECT |
Pitfalls
login_customer_idwithout dashes. With dashes the requests fail.- Not every country is a Country. Some geo target constants have
target_typeRegion, Taiwan (2158) for example. When checking locations, accept both. - English is
languageConstants/1000. - App campaign optimization lives in
campaign.selective_optimization.conversion_actions. Use the same path in the update mask. - Check the events before switching optimization. If an in-app event fires a few times a month, the campaign effectively stops learning.
- Fields move between API versions. In recent versions
campaign.start_datebecamecampaign.start_date_time, and there’s no simple installs metric. When a field isn’t found, ask Claude to check the current reference instead of guessing. - Installs. Query
metrics.all_conversionssegmented bysegments.conversion_action, and that segment has to be in the SELECT. Cost can’t be segmented by conversion action, so CPI takes two queries: cost per campaign and installs per campaign, joined in the script.
SELECT campaign.id, campaign.name, segments.conversion_action, metrics.all_conversions
FROM campaign
WHERE segments.date DURING LAST_30_DAYS
AND campaign.advertising_channel_type = 'MULTI_CHANNEL'
A handoff file for the next session
The trick I like most: at the end, Claude writes a markdown handoff. How access is set up (without secrets), which accounts exist, the loop, the scripts and what each does, the pitfalls above, a log of applied changes with campaign IDs, and what to check in three or four days.
The next session reads that file and continues where the previous one stopped, without me explaining everything again. This guide is basically a cleaned-up version of that file.
Reading the numbers
Installs in Google Ads come from Google’s own attribution, so they’re usually higher than in AppsFlyer or Adjust. I use Google’s numbers to see what the campaign is optimizing on, and the MMP for budget decisions. When the data from all sources is in one place, as in Ensight, the comparison takes a minute.
Questions and answers
Can Claude change Google Ads campaigns?
Not through Google's official MCP server, which is read-only. Claude can change campaigns by writing and running scripts on the official google-ads Python library, for example in Claude Code. The safe way is a fixed loop: read the current state, propose the change, wait for approval, dry run with validate_only, apply, read again.
Why not use an MCP server for Google Ads?
Google's official MCP server runs GAQL queries but doesn't change campaigns. Third-party servers with write access exist, but a script per task is easier to review: you see exactly which fields change, and validate_only lets Google check the request before anything is applied.
What does validate_only do in the Google Ads API?
Google validates the whole request (permissions, fields, policies) and returns the same errors a real call would, but changes nothing. It's available on most mutate requests. In the Python library it isn't a keyword argument: build the request object, set validate_only on it and pass it as request=.
Do I still need a Google Ads developer token?
No. Google sunset developer tokens on September 9, 2026: the API access level now belongs to the Google Cloud project behind your OAuth client. Recent client library versions work without a token; if an older config still has one, the API ignores it.
Why does adding EU countries to a campaign fail?
Existing campaigns must have the EU political ads self-declaration (contains_eu_political_advertising) set before location targeting can change; otherwise the criteria mutate fails with MISSING_EU_POLITICAL_ADVERTISING_SELF_DECLARATION. Set DOES_NOT_CONTAIN_EU_POLITICAL_ADVERTISING in the same atomic mutate as the new locations.
How do I change what an App campaign optimizes for through the API?
Update campaign.selective_optimization.conversion_actions with the resource names of the conversion actions, and use the same path in the update mask. Check that those events actually fire often enough first, or the campaign stops learning.
How do I get app installs per campaign from the Google Ads API?
Query metrics.all_conversions segmented by segments.conversion_action, and include that segment in the SELECT. Cost can't be segmented by conversion action, so for CPI run a second query for cost per campaign and join the two.
Can Claude change bids and budgets on its own this way?
Technically yes, which is why the process matters more than the code. Write the rules into CLAUDE.md: never apply without an explicit yes, dry run first, never touch budgets or bids unless asked, read the campaign again after every change.
Why do installs in Google Ads differ from AppsFlyer or Adjust?
Google Ads counts installs with its own attribution, which usually gives more credit to Google than an MMP does. Use Google's numbers to see what the campaign optimizes on, and the MMP for budget decisions.
On this site
Sources
- Google Ads API: client library for Python (googleads/google-ads-python)
- Google Ads API: optional request headers (validate_only in Python)
- Google Ads API: testing best practices, request validation
- Google Ads API: EU political advertising self-declaration
- Google Ads API: API policy and developer token sunset
- Google Ads Developer Blog: a new onboarding experience for Google Ads API developers (September 2026)
- GitHub: googleads/google-ads-mcp