adloop 0.40.0__tar.gz → 0.41.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. {adloop-0.40.0 → adloop-0.41.0}/PKG-INFO +48 -1
  2. {adloop-0.40.0 → adloop-0.41.0}/README.md +44 -0
  3. {adloop-0.40.0 → adloop-0.41.0}/pyproject.toml +3 -1
  4. {adloop-0.40.0 → adloop-0.41.0}/pyproject.toml.orig +5 -2
  5. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/__init__.py +34 -1
  6. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/write.py +53 -6
  7. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/auth.py +23 -0
  8. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/config.py +42 -0
  9. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/conversion_setup.py +23 -10
  10. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/gtm/write.py +5 -12
  11. adloop-0.41.0/src/adloop/microsoft_ads/__init__.py +14 -0
  12. adloop-0.41.0/src/adloop/microsoft_ads/auth.py +445 -0
  13. adloop-0.41.0/src/adloop/microsoft_ads/client.py +368 -0
  14. adloop-0.41.0/src/adloop/microsoft_ads/manage/__init__.py +178 -0
  15. adloop-0.41.0/src/adloop/microsoft_ads/manage/_common.py +310 -0
  16. adloop-0.41.0/src/adloop/microsoft_ads/manage/ad_groups.py +400 -0
  17. adloop-0.41.0/src/adloop/microsoft_ads/manage/ads.py +209 -0
  18. adloop-0.41.0/src/adloop/microsoft_ads/manage/campaigns.py +334 -0
  19. adloop-0.41.0/src/adloop/microsoft_ads/manage/extensions.py +698 -0
  20. adloop-0.41.0/src/adloop/microsoft_ads/manage/negatives.py +390 -0
  21. adloop-0.41.0/src/adloop/microsoft_ads/manage/removal.py +196 -0
  22. adloop-0.41.0/src/adloop/microsoft_ads/manage/targeting.py +332 -0
  23. adloop-0.41.0/src/adloop/microsoft_ads/read.py +1315 -0
  24. adloop-0.41.0/src/adloop/microsoft_ads/write.py +345 -0
  25. adloop-0.41.0/src/adloop/oauth_redirect.py +165 -0
  26. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/reddit/write.py +6 -14
  27. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules/adloop.md +51 -2
  28. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/safety/approval.py +6 -0
  29. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/safety/approval_card.html +42 -4
  30. adloop-0.41.0/src/adloop/safety/guards.py +127 -0
  31. adloop-0.41.0/src/adloop/safety/outcomes.py +23 -0
  32. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/safety/preview.py +2 -1
  33. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/server.py +1128 -8
  34. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/uploads.py +2 -1
  35. adloop-0.41.0/src/adloop/views/__init__.py +214 -0
  36. adloop-0.41.0/src/adloop/views/performance.py +389 -0
  37. adloop-0.40.0/src/adloop/safety/guards.py +0 -56
  38. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/__main__.py +0 -0
  39. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/_mcp_patches.py +0 -0
  40. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/__init__.py +0 -0
  41. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/ai_max.py +0 -0
  42. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/assets.py +0 -0
  43. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/audiences.py +0 -0
  44. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/brands.py +0 -0
  45. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/campaign_settings.py +0 -0
  46. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/client.py +0 -0
  47. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/conversion_actions.py +0 -0
  48. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/currency.py +0 -0
  49. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/custom_conversion_goals.py +0 -0
  50. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/enums.py +0 -0
  51. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/forecast.py +0 -0
  52. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/gaql.py +0 -0
  53. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/image_fetch.py +0 -0
  54. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/pmax.py +0 -0
  55. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/read.py +0 -0
  56. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/recommendation_subscriptions.py +0 -0
  57. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/recommendations.py +0 -0
  58. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/shopping.py +0 -0
  59. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/snippet_headers.py +0 -0
  60. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ads/validate_only.py +0 -0
  61. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/cli.py +0 -0
  62. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/crossref.py +0 -0
  63. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/diagnostics.py +0 -0
  64. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/__init__.py +0 -0
  65. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/admin.py +0 -0
  66. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/annotations.py +0 -0
  67. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/attribution.py +0 -0
  68. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/audit.py +0 -0
  69. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/client.py +0 -0
  70. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/definitions.py +0 -0
  71. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/funnels.py +0 -0
  72. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/reports.py +0 -0
  73. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/retention.py +0 -0
  74. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/suggest.py +0 -0
  75. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/tracking.py +0 -0
  76. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/ga4/write.py +0 -0
  77. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/gsc/__init__.py +0 -0
  78. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/gsc/client.py +0 -0
  79. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/gsc/reports.py +0 -0
  80. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/gtm/__init__.py +0 -0
  81. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/gtm/client.py +0 -0
  82. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/gtm/entities.py +0 -0
  83. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/gtm/read.py +0 -0
  84. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/merchant/__init__.py +0 -0
  85. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/merchant/client.py +0 -0
  86. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/merchant/read.py +0 -0
  87. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/pagespeed.py +0 -0
  88. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/reddit/__init__.py +0 -0
  89. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/reddit/auth.py +0 -0
  90. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/reddit/client.py +0 -0
  91. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/reddit/read.py +0 -0
  92. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/reddit/schedule.py +0 -0
  93. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules/__init__.py +0 -0
  94. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules/commands/analyze-performance.md +0 -0
  95. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules/commands/budget-plan.md +0 -0
  96. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules/commands/create-ad.md +0 -0
  97. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules/commands/create-campaign.md +0 -0
  98. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules/commands/diagnose-tracking.md +0 -0
  99. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules/commands/optimize-campaign.md +0 -0
  100. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/rules_install.py +0 -0
  101. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/runtime.py +0 -0
  102. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/safety/__init__.py +0 -0
  103. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/safety/audit.py +0 -0
  104. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/tracking.py +0 -0
  105. {adloop-0.40.0 → adloop-0.41.0}/src/adloop/upload_card.html +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: adloop
3
- Version: 0.40.0
3
+ Version: 0.41.0
4
4
  Summary: Google Ads MCP server for Claude, ChatGPT and Cursor, with Reddit Ads, GA4 and Tag Manager. Every change is previewed first.
5
5
  Keywords: mcp,mcp-server,google-ads,google-ads-mcp,reddit-ads,google-analytics,ga4,claude,chatgpt,cursor,marketing
6
6
  Author: Daniel Klose
@@ -18,12 +18,15 @@ Requires-Dist: pyyaml>=6.0
18
18
  Requires-Dist: requests>=2.31
19
19
  Requires-Dist: pytest>=8.0 ; extra == 'dev'
20
20
  Requires-Dist: pytest-asyncio>=0.23 ; extra == 'dev'
21
+ Requires-Dist: prefab-ui==0.21.1 ; extra == 'dev'
22
+ Requires-Dist: prefab-ui==0.21.1 ; extra == 'views'
21
23
  Requires-Python: >=3.11
22
24
  Project-URL: Homepage, https://github.com/kLOsk/adloop
23
25
  Project-URL: Repository, https://github.com/kLOsk/adloop
24
26
  Project-URL: Issues, https://github.com/kLOsk/adloop/issues
25
27
  Project-URL: Changelog, https://github.com/kLOsk/adloop/releases
26
28
  Provides-Extra: dev
29
+ Provides-Extra: views
27
30
  Description-Content-Type: text/markdown
28
31
 
29
32
  <!-- mcp-name: com.getadloop/adloop -->
@@ -274,6 +277,32 @@ A second ad platform, same safety model. Reddit is a separate connection: its ow
274
277
 
275
278
  > **Setup for Reddit Ads tools** — In Reddit Ads Manager open **Business Manager → Developer Application → Create app** (business admins only; no approval wait). Register the redirect URL exactly as `http://localhost:8765/callback`, then run `adloop init` and complete the Reddit Ads step: it opens Reddit's consent page (scopes `adsread` + `adsedit`, permanent grant), stores the refresh token at `~/.adloop/reddit_token.json`, and lets you pick the default ad account. Reddit rate-limits per user (reporting: 60 requests/min) and requires a descriptive User-Agent, which AdLoop builds from your app id and Reddit username. Reddit has no validate-only mode, so `confirm_and_apply(dry_run=true)` re-reads the target and re-checks the safety caps instead.
276
279
 
280
+ ### Microsoft Advertising Tools
281
+
282
+ Microsoft Advertising (Bing, Yahoo, AOL and DuckDuckGo search ads) through the REST API v13, with the same safety model. `customer_id` is the manager account and `ad_account_id` the default ad account; every tool takes `ad_account_id` to pick another.
283
+
284
+ | Tool | What It Does |
285
+ |------|-------------|
286
+ | `list_microsoft_ads_accounts` | The signed-in user, manager accounts and ad accounts (id, number, currency, time zone, status) |
287
+ | `get_microsoft_campaigns` / `get_microsoft_ad_groups` / `get_microsoft_keywords` / `get_microsoft_ads` | Structure with the status of every parent level, budgets (own or shared), bidding, languages, included and excluded locations and location intent, bids, networks, Audience Network exposure, match types, RSA copy with pins, editorial review |
288
+ | `get_microsoft_performance` | Spend, clicks, CTR, CPC, conversions, CPA, revenue, impression share and share lost to budget and rank per account/campaign/ad group/keyword/ad, optional date or device breakdown, compact mode with insights |
289
+ | `get_microsoft_search_terms` | What people searched, the keyword and match type it matched, and waste candidates |
290
+ | `get_microsoft_location_performance` | Where clicks came from, split into people physically in a place and people searching about it |
291
+ | `get_microsoft_conversion_setup` | Audit of UET tags, conversion goals (tracking status, excluded from bidding), campaign goals and clicks without conversions |
292
+ | `get_microsoft_negative_keywords` / `get_microsoft_ad_extensions` | Direct negatives, shared negative lists with their items and attachments, and sitelinks, callouts, snippets and call extensions per campaign and account, each with a `remove_id` |
293
+ | `search_microsoft_locations` | Location ids (country, state, metro, city, postal code) by name from Microsoft's location file, cached |
294
+ | `update_microsoft_campaign_budget` / `update_microsoft_campaign` / `update_microsoft_campaign_targeting` | Daily budget (capped by `max_daily_budget`), name, bid strategy, tracking template and final URL suffix, included and excluded locations, location intent, ad schedule |
295
+ | `pause_microsoft_entity` / `enable_microsoft_entity` / `remove_microsoft_entity` | Status changes through the preview gate; removal is irreversible and double-confirmed |
296
+ | `draft_microsoft_campaign` / `draft_microsoft_ad_group` / `update_microsoft_ad_group` | New Search campaigns (created **paused**, with languages and locations required) and ad groups with keywords; ad group name, default bid, network and Audience Network adjustment |
297
+ | `draft_microsoft_keywords` / `update_microsoft_keyword_bids` | Add keywords (duplicates skipped) and change keyword bids, capped by `max_bid_increase_pct` including bids inherited from the ad group |
298
+ | `add_microsoft_negative_keywords` / `propose_microsoft_negative_keyword_list` / `add_to_microsoft_negative_keyword_list` / `attach_microsoft_negative_keyword_list` / `detach_microsoft_negative_keyword_list` | Negatives on a campaign or ad group, or in shared lists; every draft names the active keywords a negative would block |
299
+ | `draft_microsoft_responsive_search_ad` / `update_microsoft_responsive_search_ad` | New RSAs (created **paused**) and copy, URL and path changes |
300
+ | `draft_microsoft_sitelinks` / `draft_microsoft_callouts` / `draft_microsoft_structured_snippet` / `draft_microsoft_call_extension` | Create extensions and link them to a campaign or the account |
301
+
302
+ The same management rules as Google Ads apply: broad match is refused unless the campaign uses conversion-based bidding (at the draft and again at apply; Maximize Clicks does not count), moving to any other strategy is refused while active broad keywords exist, and a campaign's first ad schedule needs a double confirmation. MaxConversions is refused while the account has no active conversion goal, because Microsoft refuses such a campaign.
303
+
304
+ > **Setup for Microsoft Advertising tools** — You need a developer token (Microsoft Advertising → **Settings → Developer settings**, or [developers.ads.microsoft.com](https://developers.ads.microsoft.com/Account)) and an app registration in Microsoft Entra ID: allow public client flows, add the delegated `msads.manage` permission of Microsoft Advertising, and add `http://localhost/callback` as a mobile and desktop redirect URI (the sign-in listens on a free port; Entra ignores the port of localhost redirects). Put the token and the app's client id under `microsoft_ads` in `~/.adloop/config.yaml`, then run `adloop microsoft-login` and sign in with the user that has access to the ad accounts. It stores the refresh token at `~/.adloop/microsoft_token.json`. Directories with security defaults block the device-code flow (sign-in error 530035), so `adloop microsoft-login --device-code` is only a fallback. Signing in with a Google identity is not supported yet: if the account's users sign in to Microsoft Advertising with Google, invite a Microsoft account or work (Entra) user to the ad account and sign in as that user. Microsoft has no validate-only mode, so `confirm_and_apply(dry_run=true)` re-reads the target, refuses one that changed since the draft and re-checks the caps; the real apply runs the same checks again first.
305
+
277
306
  ### Image Uploads
278
307
 
279
308
  An image on your computer, or one you attached in the chat, has no public URL, and an AI app cannot hand the file to a tool. `upload_images` gives it a way in.
@@ -570,6 +599,13 @@ All configuration lives in `~/.adloop/config.yaml`. See [`config.yaml.example`](
570
599
  | `reddit` | `ad_account_id` | *(empty)* | Default Reddit ad account for every Reddit tool (picked by `adloop init`) |
571
600
  | `reddit` | `username` | *(empty)* | Your Reddit username, used only in the User-Agent Reddit requires |
572
601
  | `reddit` | `token_path` | `~/.adloop/reddit_token.json` | Where the Reddit refresh token is stored |
602
+ | `microsoft_ads` | `developer_token` | *(empty)* | Microsoft Advertising developer token |
603
+ | `microsoft_ads` | `client_id` | *(empty)* | Client id of your Entra app registration (public client, `msads.manage` permission) |
604
+ | `microsoft_ads` | `client_secret` | *(empty)* | Only for a confidential (web) app; public clients leave it empty |
605
+ | `microsoft_ads` | `tenant` | `common` | Entra tenant for sign-in |
606
+ | `microsoft_ads` | `customer_id` | *(empty)* | Manager account id (the CustomerId header) |
607
+ | `microsoft_ads` | `ad_account_id` | *(empty)* | Default ad account for every Microsoft tool |
608
+ | `microsoft_ads` | `token_path` | `~/.adloop/microsoft_token.json` | Where `adloop microsoft-login` stores the refresh token |
573
609
  | `safety` | `max_daily_budget` | `50.00` | Maximum allowed daily budget per campaign |
574
610
  | `safety` | `require_dry_run` | `true` | Force all writes to dry-run mode |
575
611
  | `safety` | `two_phase_apply` | `false` | Refuse real applies until the plan had a dry-run pass |
@@ -593,6 +629,7 @@ Most MCP clients (claude.ai, ChatGPT, Cursor, …) load **every tool schema into
593
629
  | `web` | PageSpeed / Core Web Vitals |
594
630
  | `merchant` | Merchant Center feed health |
595
631
  | `reddit` | Reddit Ads reads, writes, and planning |
632
+ | `microsoft_ads` | Microsoft Advertising reads and campaign management |
596
633
 
597
634
  Google Ads can be narrowed further. Use one of these instead of `ads`:
598
635
 
@@ -604,6 +641,8 @@ Google Ads can be narrowed further. Use one of these instead of `ads`:
604
641
 
605
642
  `health_check` and `confirm_and_apply` are always included, whatever you select. Unset = the full catalog; unknown names fail at startup with the valid list. The effect is real: `ads:read,ga4` costs about 40% of `ads,ga4` for audits and diagnosis, and an `ads:plan`-only client for keyword research pays about 5% of the full catalog. Toolsets are per *client*, not per install: one AdLoop config can serve a trimmed Cursor and a full-catalog Claude Code side by side.
606
643
 
644
+ Without `ADLOOP_TOOLSETS`, a platform you haven't set up stays out of the list: with no Reddit app in the config, the Reddit Ads tools are hidden (the same goes for Microsoft Advertising), and `health_check` lists them under `hidden_toolsets` with the setup step. Set the platform up and restart the server to get its tools, or name it in `ADLOOP_TOOLSETS` to show them anyway. Google's toolsets are always listed, because Google can sign in through Application Default Credentials with nothing in the config.
645
+
607
646
  On [AdLoop Cloud](https://getadloop.com), the same feature is per API key: pick toolsets when creating a key in the dashboard, and that key's tools/list is trimmed server-side for whichever AI client uses it.
608
647
 
609
648
  ## Project Structure
@@ -636,6 +675,14 @@ src/adloop/
636
675
  │ ├── client.py # Reddit Ads API v3 REST client — bearer refresh, per-user rate limits, pagination
637
676
  │ ├── read.py # Accounts, campaigns, ad groups, ads, performance reports, pixels, targeting lookups
638
677
  │ └── write.py # Draft/preflight/apply for status, budget, bid, targeting, and PAUSED creation
678
+ ├── microsoft_ads/
679
+ │ ├── auth.py # Entra sign-in (browser auth code + PKCE, device-code fallback), refresh tokens
680
+ │ ├── client.py # REST v13 client — Campaign Management, Customer Management, Reporting services
681
+ │ ├── read.py # Accounts, campaigns, ad groups, keywords, ads, reports, search terms, conversion audit
682
+ │ ├── manage/ # Drafts, dry-run checks and applies per area (campaigns, targeting, ad groups, negatives,
683
+ │ │ # ads, extensions, removal), one operation → handler table
684
+ │ └── write.py # Budget and status drafts; routes every microsoft_ plan to its preflight and apply
685
+ ├── oauth_redirect.py # Localhost listener for sign-in redirects (free port, waits for its state)
639
686
  └── safety/
640
687
  ├── guards.py # Budget caps, bid limits, blocked operations, Broad Match safety
641
688
  ├── preview.py # Change plans and previews
@@ -246,6 +246,32 @@ A second ad platform, same safety model. Reddit is a separate connection: its ow
246
246
 
247
247
  > **Setup for Reddit Ads tools** — In Reddit Ads Manager open **Business Manager → Developer Application → Create app** (business admins only; no approval wait). Register the redirect URL exactly as `http://localhost:8765/callback`, then run `adloop init` and complete the Reddit Ads step: it opens Reddit's consent page (scopes `adsread` + `adsedit`, permanent grant), stores the refresh token at `~/.adloop/reddit_token.json`, and lets you pick the default ad account. Reddit rate-limits per user (reporting: 60 requests/min) and requires a descriptive User-Agent, which AdLoop builds from your app id and Reddit username. Reddit has no validate-only mode, so `confirm_and_apply(dry_run=true)` re-reads the target and re-checks the safety caps instead.
248
248
 
249
+ ### Microsoft Advertising Tools
250
+
251
+ Microsoft Advertising (Bing, Yahoo, AOL and DuckDuckGo search ads) through the REST API v13, with the same safety model. `customer_id` is the manager account and `ad_account_id` the default ad account; every tool takes `ad_account_id` to pick another.
252
+
253
+ | Tool | What It Does |
254
+ |------|-------------|
255
+ | `list_microsoft_ads_accounts` | The signed-in user, manager accounts and ad accounts (id, number, currency, time zone, status) |
256
+ | `get_microsoft_campaigns` / `get_microsoft_ad_groups` / `get_microsoft_keywords` / `get_microsoft_ads` | Structure with the status of every parent level, budgets (own or shared), bidding, languages, included and excluded locations and location intent, bids, networks, Audience Network exposure, match types, RSA copy with pins, editorial review |
257
+ | `get_microsoft_performance` | Spend, clicks, CTR, CPC, conversions, CPA, revenue, impression share and share lost to budget and rank per account/campaign/ad group/keyword/ad, optional date or device breakdown, compact mode with insights |
258
+ | `get_microsoft_search_terms` | What people searched, the keyword and match type it matched, and waste candidates |
259
+ | `get_microsoft_location_performance` | Where clicks came from, split into people physically in a place and people searching about it |
260
+ | `get_microsoft_conversion_setup` | Audit of UET tags, conversion goals (tracking status, excluded from bidding), campaign goals and clicks without conversions |
261
+ | `get_microsoft_negative_keywords` / `get_microsoft_ad_extensions` | Direct negatives, shared negative lists with their items and attachments, and sitelinks, callouts, snippets and call extensions per campaign and account, each with a `remove_id` |
262
+ | `search_microsoft_locations` | Location ids (country, state, metro, city, postal code) by name from Microsoft's location file, cached |
263
+ | `update_microsoft_campaign_budget` / `update_microsoft_campaign` / `update_microsoft_campaign_targeting` | Daily budget (capped by `max_daily_budget`), name, bid strategy, tracking template and final URL suffix, included and excluded locations, location intent, ad schedule |
264
+ | `pause_microsoft_entity` / `enable_microsoft_entity` / `remove_microsoft_entity` | Status changes through the preview gate; removal is irreversible and double-confirmed |
265
+ | `draft_microsoft_campaign` / `draft_microsoft_ad_group` / `update_microsoft_ad_group` | New Search campaigns (created **paused**, with languages and locations required) and ad groups with keywords; ad group name, default bid, network and Audience Network adjustment |
266
+ | `draft_microsoft_keywords` / `update_microsoft_keyword_bids` | Add keywords (duplicates skipped) and change keyword bids, capped by `max_bid_increase_pct` including bids inherited from the ad group |
267
+ | `add_microsoft_negative_keywords` / `propose_microsoft_negative_keyword_list` / `add_to_microsoft_negative_keyword_list` / `attach_microsoft_negative_keyword_list` / `detach_microsoft_negative_keyword_list` | Negatives on a campaign or ad group, or in shared lists; every draft names the active keywords a negative would block |
268
+ | `draft_microsoft_responsive_search_ad` / `update_microsoft_responsive_search_ad` | New RSAs (created **paused**) and copy, URL and path changes |
269
+ | `draft_microsoft_sitelinks` / `draft_microsoft_callouts` / `draft_microsoft_structured_snippet` / `draft_microsoft_call_extension` | Create extensions and link them to a campaign or the account |
270
+
271
+ The same management rules as Google Ads apply: broad match is refused unless the campaign uses conversion-based bidding (at the draft and again at apply; Maximize Clicks does not count), moving to any other strategy is refused while active broad keywords exist, and a campaign's first ad schedule needs a double confirmation. MaxConversions is refused while the account has no active conversion goal, because Microsoft refuses such a campaign.
272
+
273
+ > **Setup for Microsoft Advertising tools** — You need a developer token (Microsoft Advertising → **Settings → Developer settings**, or [developers.ads.microsoft.com](https://developers.ads.microsoft.com/Account)) and an app registration in Microsoft Entra ID: allow public client flows, add the delegated `msads.manage` permission of Microsoft Advertising, and add `http://localhost/callback` as a mobile and desktop redirect URI (the sign-in listens on a free port; Entra ignores the port of localhost redirects). Put the token and the app's client id under `microsoft_ads` in `~/.adloop/config.yaml`, then run `adloop microsoft-login` and sign in with the user that has access to the ad accounts. It stores the refresh token at `~/.adloop/microsoft_token.json`. Directories with security defaults block the device-code flow (sign-in error 530035), so `adloop microsoft-login --device-code` is only a fallback. Signing in with a Google identity is not supported yet: if the account's users sign in to Microsoft Advertising with Google, invite a Microsoft account or work (Entra) user to the ad account and sign in as that user. Microsoft has no validate-only mode, so `confirm_and_apply(dry_run=true)` re-reads the target, refuses one that changed since the draft and re-checks the caps; the real apply runs the same checks again first.
274
+
249
275
  ### Image Uploads
250
276
 
251
277
  An image on your computer, or one you attached in the chat, has no public URL, and an AI app cannot hand the file to a tool. `upload_images` gives it a way in.
@@ -542,6 +568,13 @@ All configuration lives in `~/.adloop/config.yaml`. See [`config.yaml.example`](
542
568
  | `reddit` | `ad_account_id` | *(empty)* | Default Reddit ad account for every Reddit tool (picked by `adloop init`) |
543
569
  | `reddit` | `username` | *(empty)* | Your Reddit username, used only in the User-Agent Reddit requires |
544
570
  | `reddit` | `token_path` | `~/.adloop/reddit_token.json` | Where the Reddit refresh token is stored |
571
+ | `microsoft_ads` | `developer_token` | *(empty)* | Microsoft Advertising developer token |
572
+ | `microsoft_ads` | `client_id` | *(empty)* | Client id of your Entra app registration (public client, `msads.manage` permission) |
573
+ | `microsoft_ads` | `client_secret` | *(empty)* | Only for a confidential (web) app; public clients leave it empty |
574
+ | `microsoft_ads` | `tenant` | `common` | Entra tenant for sign-in |
575
+ | `microsoft_ads` | `customer_id` | *(empty)* | Manager account id (the CustomerId header) |
576
+ | `microsoft_ads` | `ad_account_id` | *(empty)* | Default ad account for every Microsoft tool |
577
+ | `microsoft_ads` | `token_path` | `~/.adloop/microsoft_token.json` | Where `adloop microsoft-login` stores the refresh token |
545
578
  | `safety` | `max_daily_budget` | `50.00` | Maximum allowed daily budget per campaign |
546
579
  | `safety` | `require_dry_run` | `true` | Force all writes to dry-run mode |
547
580
  | `safety` | `two_phase_apply` | `false` | Refuse real applies until the plan had a dry-run pass |
@@ -565,6 +598,7 @@ Most MCP clients (claude.ai, ChatGPT, Cursor, …) load **every tool schema into
565
598
  | `web` | PageSpeed / Core Web Vitals |
566
599
  | `merchant` | Merchant Center feed health |
567
600
  | `reddit` | Reddit Ads reads, writes, and planning |
601
+ | `microsoft_ads` | Microsoft Advertising reads and campaign management |
568
602
 
569
603
  Google Ads can be narrowed further. Use one of these instead of `ads`:
570
604
 
@@ -576,6 +610,8 @@ Google Ads can be narrowed further. Use one of these instead of `ads`:
576
610
 
577
611
  `health_check` and `confirm_and_apply` are always included, whatever you select. Unset = the full catalog; unknown names fail at startup with the valid list. The effect is real: `ads:read,ga4` costs about 40% of `ads,ga4` for audits and diagnosis, and an `ads:plan`-only client for keyword research pays about 5% of the full catalog. Toolsets are per *client*, not per install: one AdLoop config can serve a trimmed Cursor and a full-catalog Claude Code side by side.
578
612
 
613
+ Without `ADLOOP_TOOLSETS`, a platform you haven't set up stays out of the list: with no Reddit app in the config, the Reddit Ads tools are hidden (the same goes for Microsoft Advertising), and `health_check` lists them under `hidden_toolsets` with the setup step. Set the platform up and restart the server to get its tools, or name it in `ADLOOP_TOOLSETS` to show them anyway. Google's toolsets are always listed, because Google can sign in through Application Default Credentials with nothing in the config.
614
+
579
615
  On [AdLoop Cloud](https://getadloop.com), the same feature is per API key: pick toolsets when creating a key in the dashboard, and that key's tools/list is trimmed server-side for whichever AI client uses it.
580
616
 
581
617
  ## Project Structure
@@ -608,6 +644,14 @@ src/adloop/
608
644
  │ ├── client.py # Reddit Ads API v3 REST client — bearer refresh, per-user rate limits, pagination
609
645
  │ ├── read.py # Accounts, campaigns, ad groups, ads, performance reports, pixels, targeting lookups
610
646
  │ └── write.py # Draft/preflight/apply for status, budget, bid, targeting, and PAUSED creation
647
+ ├── microsoft_ads/
648
+ │ ├── auth.py # Entra sign-in (browser auth code + PKCE, device-code fallback), refresh tokens
649
+ │ ├── client.py # REST v13 client — Campaign Management, Customer Management, Reporting services
650
+ │ ├── read.py # Accounts, campaigns, ad groups, keywords, ads, reports, search terms, conversion audit
651
+ │ ├── manage/ # Drafts, dry-run checks and applies per area (campaigns, targeting, ad groups, negatives,
652
+ │ │ # ads, extensions, removal), one operation → handler table
653
+ │ └── write.py # Budget and status drafts; routes every microsoft_ plan to its preflight and apply
654
+ ├── oauth_redirect.py # Localhost listener for sign-in redirects (free port, waits for its state)
611
655
  └── safety/
612
656
  ├── guards.py # Budget caps, bid limits, blocked operations, Broad Match safety
613
657
  ├── preview.py # Change plans and previews
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "adloop"
3
- version = "0.40.0"
3
+ version = "0.41.0"
4
4
  description = "Google Ads MCP server for Claude, ChatGPT and Cursor, with Reddit Ads, GA4 and Tag Manager. Every change is previewed first."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -47,9 +47,11 @@ Changelog = "https://github.com/kLOsk/adloop/releases"
47
47
  adloop = "adloop:main"
48
48
 
49
49
  [project.optional-dependencies]
50
+ views = ["prefab-ui==0.21.1"]
50
51
  dev = [
51
52
  "pytest>=8.0",
52
53
  "pytest-asyncio>=0.23",
54
+ "prefab-ui==0.21.1",
53
55
  ]
54
56
 
55
57
  [build-system]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "adloop"
3
- version = "0.40.0"
3
+ version = "0.41.0"
4
4
  description = "Google Ads MCP server for Claude, ChatGPT and Cursor, with Reddit Ads, GA4 and Tag Manager. Every change is previewed first."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -38,4 +38,7 @@ requires = ["uv_build>=0.10.8,<0.11.0"]
38
38
  build-backend = "uv_build"
39
39
 
40
40
  [project.optional-dependencies]
41
- dev = ["pytest>=8.0", "pytest-asyncio>=0.23"]
41
+ # Views (dashboards in apps with MCP Apps). Pinned: the renderer and the
42
+ # component JSON the server sends must come from the same release.
43
+ views = ["prefab-ui==0.21.1"]
44
+ dev = ["pytest>=8.0", "pytest-asyncio>=0.23", "prefab-ui==0.21.1"]
@@ -37,6 +37,9 @@ def main() -> None:
37
37
  adloop install-rules Install Claude orchestration rules globally.
38
38
  adloop update-rules Refresh the installed rules block.
39
39
  adloop uninstall-rules Remove the installed rules block + commands.
40
+ adloop microsoft-login Sign in to Microsoft Advertising in the browser
41
+ (--user <email> preselects the account; --device-code
42
+ for the code-on-another-device flow).
40
43
  adloop --version, -V Print version and exit.
41
44
  """
42
45
  args = sys.argv[1:]
@@ -65,6 +68,26 @@ def main() -> None:
65
68
  sys.exit(130)
66
69
  return
67
70
 
71
+ if args and args[0] == "microsoft-login":
72
+ from adloop.config import load_config
73
+ from adloop.microsoft_ads.auth import MicrosoftAdsAuthError, browser_login, device_code_login
74
+
75
+ options = args[1:]
76
+ hint = next((options[k + 1] for k, a in enumerate(options[:-1]) if a == "--user"), "")
77
+ try:
78
+ if "--device-code" in options:
79
+ path = device_code_login(load_config())
80
+ else:
81
+ path = browser_login(load_config(), login_hint=hint)
82
+ except MicrosoftAdsAuthError as exc:
83
+ print(f"\n {exc}\n")
84
+ sys.exit(1)
85
+ except KeyboardInterrupt:
86
+ print("\n\n Cancelled.\n")
87
+ sys.exit(130)
88
+ print(f"\n Signed in. Token saved to {path}. Restart the MCP server to use it.\n")
89
+ return
90
+
68
91
  # Process-global side effects (signal handlers, heartbeat thread, and
69
92
  # the stdio cancellation-race monkeypatch) are deliberately installed
70
93
  # here — in the stdio entry point — rather than at adloop.server import
@@ -74,6 +97,16 @@ def main() -> None:
74
97
  diagnostics.install()
75
98
  install_runtime_patches()
76
99
 
77
- from adloop.server import mcp
100
+ from adloop.server import hide_unconfigured_platforms, mcp
101
+
102
+ # Also local-only: a platform that isn't set up (Reddit Ads without a
103
+ # Reddit app, say) keeps its tools out of tools/list. A config that fails
104
+ # to load hides nothing; every tool call reports the problem.
105
+ try:
106
+ from adloop.runtime import current_config
107
+
108
+ hide_unconfigured_platforms(current_config())
109
+ except Exception as e: # noqa: BLE001
110
+ print(f"adloop: could not check which platforms are set up: {e}", file=sys.stderr)
78
111
 
79
112
  mcp.run()
@@ -2886,6 +2886,11 @@ def confirm_and_apply(
2886
2886
  "Plans expire when the MCP server restarts.",
2887
2887
  }
2888
2888
 
2889
+ from adloop.safety.guards import blocked_plan_refusal
2890
+
2891
+ if (refusal := blocked_plan_refusal(config, plan, dry_run=dry_run)) is not None:
2892
+ return refusal
2893
+
2889
2894
  forced_by_config = bool(config.safety.require_dry_run) and not dry_run
2890
2895
  if config.safety.require_dry_run:
2891
2896
  dry_run = True
@@ -2893,6 +2898,7 @@ def confirm_and_apply(
2893
2898
  from adloop.ga4.write import GA4_OPERATIONS
2894
2899
 
2895
2900
  is_reddit = plan.operation.startswith("reddit_")
2901
+ is_microsoft = plan.operation.startswith("microsoft_")
2896
2902
  is_gtm = plan.operation.startswith("gtm_")
2897
2903
  is_ga4 = plan.operation in GA4_OPERATIONS
2898
2904
  # Google Ads calls without a validate_only field: the dry run re-reads the
@@ -2904,6 +2910,7 @@ def confirm_and_apply(
2904
2910
  platform_label = (
2905
2911
  "Google Ads and Google Analytics" if is_setup
2906
2912
  else "Reddit Ads" if is_reddit
2913
+ else "Microsoft Advertising" if is_microsoft
2907
2914
  else "Google Tag Manager" if is_gtm
2908
2915
  else "Google Analytics" if is_ga4
2909
2916
  else "Google Ads"
@@ -2918,14 +2925,19 @@ def confirm_and_apply(
2918
2925
  # Either way a failed check leaves dry_run_result unset, so two-phase
2919
2926
  # apply keeps refusing the real write.
2920
2927
  try:
2921
- if is_reddit or is_gtm:
2922
- # Neither Reddit nor Tag Manager has a validate-only mode; the
2923
- # dry run re-reads the target and re-runs the safety checks
2924
- # against live values.
2928
+ if is_reddit or is_gtm or is_microsoft:
2929
+ # Reddit, Microsoft Advertising and Tag Manager have no
2930
+ # validate-only mode for these calls; the dry run re-reads the
2931
+ # target and re-runs the safety checks against live values.
2925
2932
  from adloop.gtm.write import preflight as gtm_preflight
2933
+ from adloop.microsoft_ads.write import preflight as microsoft_preflight
2926
2934
  from adloop.reddit.write import preflight as reddit_preflight
2927
2935
 
2928
- preflight = reddit_preflight if is_reddit else gtm_preflight
2936
+ preflight = (
2937
+ reddit_preflight if is_reddit
2938
+ else microsoft_preflight if is_microsoft
2939
+ else gtm_preflight
2940
+ )
2929
2941
  preflight_checks = preflight(config, plan)
2930
2942
  elif is_ga4:
2931
2943
  # The GA4 Admin API has no validate-only mode either; a
@@ -2982,7 +2994,7 @@ def confirm_and_apply(
2982
2994
  "Analytics by re-reading the property)"
2983
2995
  if is_setup
2984
2996
  else f"re-checked the target against {platform_label}"
2985
- if is_reddit or is_gtm or is_ga4 or is_ads_reread
2997
+ if is_reddit or is_microsoft or is_gtm or is_ga4 or is_ads_reread
2986
2998
  else "sent the change to Google Ads in validate-only mode"
2987
2999
  )
2988
3000
  return {
@@ -3202,6 +3214,35 @@ def confirm_and_apply(
3202
3214
  and not e.sent_total
3203
3215
  and not e.unknown_status
3204
3216
  )
3217
+ from adloop.safety.outcomes import PartialApplyError
3218
+
3219
+ if isinstance(e, PartialApplyError):
3220
+ # Part of the change happened (or may have): replaying the plan
3221
+ # would repeat it. Retire it and say what was done.
3222
+ remove_plan(plan.plan_id)
3223
+ log_mutation(
3224
+ config.safety.log_file,
3225
+ operation=plan.operation,
3226
+ customer_id=plan.customer_id,
3227
+ entity_type=plan.entity_type,
3228
+ entity_id=plan.entity_id,
3229
+ changes=plan.changes,
3230
+ dry_run=False,
3231
+ result="unknown_status" if e.unknown else "partial_apply",
3232
+ error=error_message,
3233
+ )
3234
+ return {
3235
+ "status": "UNKNOWN_OUTCOME" if e.unknown else "PARTIAL_APPLY",
3236
+ "plan_id": plan.plan_id,
3237
+ "operation": plan.operation,
3238
+ "error": error_message,
3239
+ "created": e.created,
3240
+ "message": (
3241
+ "Part of this change may already be in the account, so the plan was retired "
3242
+ "and cannot be applied again. Read the account back, then draft only what is "
3243
+ "still missing."
3244
+ ),
3245
+ }
3205
3246
  if not plan.operation.startswith("upload_") or nothing_written:
3206
3247
  store_plan(plan)
3207
3248
 
@@ -4524,6 +4565,12 @@ def _execute_plan(
4524
4565
 
4525
4566
  return apply_plan(config, plan)
4526
4567
 
4568
+ # Microsoft Advertising plans likewise have their own executor.
4569
+ if plan.operation.startswith("microsoft_"):
4570
+ from adloop.microsoft_ads.write import apply_plan as apply_microsoft_plan
4571
+
4572
+ return apply_microsoft_plan(config, plan)
4573
+
4527
4574
  # Tag Manager plans likewise never touch the Ads client.
4528
4575
  if plan.operation.startswith("gtm_"):
4529
4576
  from adloop.gtm.write import apply_plan as apply_gtm_plan
@@ -19,6 +19,7 @@ if TYPE_CHECKING:
19
19
  from google.auth.credentials import Credentials
20
20
 
21
21
  from adloop.config import AdLoopConfig
22
+ from adloop.microsoft_ads.auth import MicrosoftCredentials
22
23
  from adloop.reddit.auth import RedditCredentials
23
24
 
24
25
  # Request all scopes in a single OAuth flow so one token works for both
@@ -90,6 +91,8 @@ class CredentialsProvider(Protocol):
90
91
 
91
92
  def reddit_credentials(self, config: AdLoopConfig) -> RedditCredentials: ...
92
93
 
94
+ def microsoft_ads_credentials(self, config: AdLoopConfig) -> MicrosoftCredentials: ...
95
+
93
96
 
94
97
  class LocalFileCredentialsProvider:
95
98
  """OSS default: local credential files + interactive OAuth.
@@ -141,6 +144,14 @@ class LocalFileCredentialsProvider:
141
144
 
142
145
  return local_credentials(config)
143
146
 
147
+ def microsoft_ads_credentials(self, config: AdLoopConfig) -> MicrosoftCredentials:
148
+ # Microsoft identity platform: own Entra app, own token file
149
+ # (microsoft_ads.token_path), written by `adloop microsoft-login`.
150
+ self._guard_local_only()
151
+ from adloop.microsoft_ads.auth import local_credentials
152
+
153
+ return local_credentials(config)
154
+
144
155
 
145
156
  _active_provider: CredentialsProvider = LocalFileCredentialsProvider()
146
157
 
@@ -289,6 +300,18 @@ def get_reddit_credentials(config: AdLoopConfig) -> RedditCredentials:
289
300
  return provider.reddit_credentials(config)
290
301
 
291
302
 
303
+ def get_microsoft_ads_credentials(config: AdLoopConfig) -> MicrosoftCredentials:
304
+ """Return refreshable bearer credentials for the Microsoft Advertising API."""
305
+ provider = _active_provider
306
+ if not hasattr(provider, "microsoft_ads_credentials"):
307
+ raise RuntimeError(
308
+ "This deployment's credentials provider does not support "
309
+ "Microsoft Advertising. Microsoft Ads tools are only available where "
310
+ "the provider implements microsoft_ads_credentials()."
311
+ )
312
+ return provider.microsoft_ads_credentials(config)
313
+
314
+
292
315
  def _requested_scopes(config: AdLoopConfig) -> list[str]:
293
316
  """Scopes for the shared local token: the base set, plus GTM write
294
317
  scopes only when the user opted in via ``gtm.write_enabled``."""
@@ -77,6 +77,27 @@ class RedditConfig:
77
77
  token_path: str = "~/.adloop/reddit_token.json"
78
78
 
79
79
 
80
+ @dataclass
81
+ class MicrosoftAdsConfig:
82
+ """Microsoft Advertising (Bing Ads) REST API.
83
+
84
+ Needs a developer token (Microsoft Ads → Settings → Developer settings,
85
+ or developers.ads.microsoft.com) and an Entra app registered as a public
86
+ client with the msads.manage permission (``client_id``). ``adloop
87
+ microsoft-login`` signs in once and stores the refresh token at
88
+ ``token_path``. ``customer_id`` is the manager account (CustomerId
89
+ header); ``ad_account_id`` the default ad account (CustomerAccountId).
90
+ """
91
+
92
+ developer_token: str = ""
93
+ client_id: str = ""
94
+ client_secret: str = "" # only for confidential (web) apps; public clients leave it empty
95
+ tenant: str = "common"
96
+ customer_id: str = ""
97
+ ad_account_id: str = ""
98
+ token_path: str = "~/.adloop/microsoft_token.json"
99
+
100
+
80
101
  @dataclass
81
102
  class SafetyConfig:
82
103
  max_daily_budget: float = 50.0
@@ -98,6 +119,14 @@ class SafetyConfig:
98
119
  blocked_operations: list[str] = field(default_factory=list)
99
120
 
100
121
 
122
+ @dataclass
123
+ class ViewsConfig:
124
+ # Views (MCP Apps): read results also drawn as a dashboard in apps that
125
+ # show them (Claude, ChatGPT, VS Code). The answer the AI reads is the
126
+ # same either way. Needs the optional prefab-ui package.
127
+ enabled: bool = False
128
+
129
+
101
130
  @dataclass
102
131
  class AdLoopConfig:
103
132
  google: GoogleConfig = field(default_factory=GoogleConfig)
@@ -108,7 +137,9 @@ class AdLoopConfig:
108
137
  merchant: MerchantConfig = field(default_factory=MerchantConfig)
109
138
  pagespeed: PageSpeedConfig = field(default_factory=PageSpeedConfig)
110
139
  reddit: RedditConfig = field(default_factory=RedditConfig)
140
+ microsoft_ads: MicrosoftAdsConfig = field(default_factory=MicrosoftAdsConfig)
111
141
  safety: SafetyConfig = field(default_factory=SafetyConfig)
142
+ views: ViewsConfig = field(default_factory=ViewsConfig)
112
143
  # Absolute path the config was resolved from (even if it did not exist
113
144
  # on disk when loaded). Used by the runtime to tell callers exactly
114
145
  # which file to edit when a safety flag overrides their request.
@@ -179,6 +210,7 @@ def load_config(config_path: str | None = None) -> AdLoopConfig:
179
210
  merchant_raw = raw.get("merchant", {}) or {}
180
211
  pagespeed_raw = raw.get("pagespeed", {})
181
212
  reddit_raw = raw.get("reddit", {}) or {}
213
+ microsoft_raw = raw.get("microsoft_ads", {}) or {}
182
214
  safety_raw = raw.get("safety", {})
183
215
 
184
216
  return AdLoopConfig(
@@ -219,6 +251,15 @@ def load_config(config_path: str | None = None) -> AdLoopConfig:
219
251
  user_agent=_text(reddit_raw, "user_agent"),
220
252
  token_path=_text(reddit_raw, "token_path", "~/.adloop/reddit_token.json"),
221
253
  ),
254
+ microsoft_ads=MicrosoftAdsConfig(
255
+ developer_token=_text(microsoft_raw, "developer_token"),
256
+ client_id=_text(microsoft_raw, "client_id"),
257
+ client_secret=_text(microsoft_raw, "client_secret"),
258
+ tenant=_text(microsoft_raw, "tenant", "common"),
259
+ customer_id=_text(microsoft_raw, "customer_id"),
260
+ ad_account_id=_text(microsoft_raw, "ad_account_id"),
261
+ token_path=_text(microsoft_raw, "token_path", "~/.adloop/microsoft_token.json"),
262
+ ),
222
263
  safety=SafetyConfig(
223
264
  max_daily_budget=safety_raw.get("max_daily_budget", 50.0),
224
265
  max_bid_increase_pct=safety_raw.get("max_bid_increase_pct", 100),
@@ -228,5 +269,6 @@ def load_config(config_path: str | None = None) -> AdLoopConfig:
228
269
  log_file=_text(safety_raw, "log_file", "~/.adloop/audit.log"),
229
270
  blocked_operations=safety_raw.get("blocked_operations", []),
230
271
  ),
272
+ views=ViewsConfig(enabled=_flag(raw.get("views") or {}, "enabled")),
231
273
  source_path=resolved,
232
274
  )
@@ -24,6 +24,23 @@ if TYPE_CHECKING:
24
24
 
25
25
  OPERATION = "conversion_tracking_setup"
26
26
 
27
+ # Steps that are operations of their own elsewhere: blocking one of those in
28
+ # safety.blocked_operations blocks the step here too, at the draft and again
29
+ # at apply (the blocklist can grow in between).
30
+ _STEP_OPERATIONS = {
31
+ "key_event": "create_key_event",
32
+ "import": "update_conversion_action",
33
+ "primary": "update_conversion_action",
34
+ }
35
+
36
+
37
+ def step_operations(actions: list[dict]) -> list[str]:
38
+ """The separately blockable operations a setup plan's steps carry out."""
39
+ from adloop.ga4 import retention
40
+
41
+ operations = {**_STEP_OPERATIONS, "retention": retention.OPERATION}
42
+ return sorted({operations[a["kind"]] for a in actions if a.get("kind") in operations})
43
+
27
44
  _EVENT_NAME = re.compile(r"^[A-Za-z][A-Za-z0-9_]{0,39}$")
28
45
  _COUNTING_METHODS = ("ONCE_PER_EVENT", "ONCE_PER_SESSION")
29
46
  _GA4_ACTION_TYPES = ("GOOGLE_ANALYTICS_4_CUSTOM", "GOOGLE_ANALYTICS_4_PURCHASE")
@@ -199,7 +216,7 @@ def draft_conversion_tracking_setup(
199
216
  if skipped:
200
217
  warnings.append(
201
218
  f"Left out because they did not fire in the last 28 days: {', '.join(skipped)}. "
202
- "Pass them in `events` to include them."
219
+ "Ask for them by name to include them anyway."
203
220
  )
204
221
  if counts is None:
205
222
  warnings.append("Could not read the event counts from GA4, so it is unchecked whether the events fire.")
@@ -224,7 +241,7 @@ def draft_conversion_tracking_setup(
224
241
  "with Google Ads."
225
242
  if ads_personalization else
226
243
  "Personalized advertising stays off for the link, so GA4 does not share audiences or "
227
- "remarketing data with Google Ads; pass ads_personalization=true to turn it on."
244
+ "remarketing data with Google Ads. Ask for personalized advertising to turn it on."
228
245
  )
229
246
  )
230
247
 
@@ -322,19 +339,15 @@ def draft_conversion_tracking_setup(
322
339
  if retention.read_settings(config, pid)["event_data_retention"] == "TWO_MONTHS":
323
340
  warnings.append(
324
341
  "GA4 keeps event data for 2 months, its default, which cuts explorations and funnels "
325
- "short. Pass data_retention=14 to include the change (update your privacy policy if it "
326
- "names a period)."
342
+ "short. Ask to include 14 months of retention in this setup (and update your privacy "
343
+ "policy if it names a period)."
327
344
  )
328
345
  except Exception: # noqa: BLE001 - a hint, not part of the plan
329
346
  pass
330
347
 
331
- blocked = {
332
- "key_event": "create_key_event", "import": "update_conversion_action",
333
- "primary": "update_conversion_action", "retention": retention.OPERATION,
334
- }
335
- for kind in {a["kind"] for a in actions} & set(blocked):
348
+ for operation in step_operations(actions):
336
349
  try:
337
- check_blocked_operation(blocked[kind], config.safety)
350
+ check_blocked_operation(operation, config.safety)
338
351
  except SafetyViolation as e:
339
352
  return {"error": str(e)}
340
353
 
@@ -147,13 +147,9 @@ def _custom_html_refusal(what: str) -> dict:
147
147
 
148
148
 
149
149
  def _blocked(operation: str, config: AdLoopConfig) -> dict | None:
150
- from adloop.safety.guards import SafetyViolation, check_blocked_operation
150
+ from adloop.safety.guards import blocked_operation_error
151
151
 
152
- try:
153
- check_blocked_operation(operation, config.safety)
154
- except SafetyViolation as e:
155
- return {"error": str(e)}
156
- return None
152
+ return blocked_operation_error(operation, config.safety)
157
153
 
158
154
 
159
155
  def _client(config: AdLoopConfig):
@@ -278,7 +274,8 @@ def _merge_parameters(existing: list[dict], updates: list[dict]) -> list[dict]:
278
274
  def _store(operation: str, entity_type: str, entity_id: str, changes: dict,
279
275
  *, warnings: list[str] | None = None,
280
276
  double_confirm: bool = False) -> dict:
281
- from adloop.safety.preview import ChangePlan, store_plan
277
+ from adloop.safety.guards import store_draft
278
+ from adloop.safety.preview import ChangePlan
282
279
 
283
280
  plan = ChangePlan(
284
281
  operation=operation,
@@ -289,11 +286,7 @@ def _store(operation: str, entity_type: str, entity_id: str, changes: dict,
289
286
  requires_double_confirm=double_confirm,
290
287
  platform=PLATFORM,
291
288
  )
292
- store_plan(plan)
293
- preview = plan.to_preview()
294
- if warnings:
295
- preview["warnings"] = warnings
296
- return preview
289
+ return store_draft(plan, warnings=warnings)
297
290
 
298
291
 
299
292
  def _workspace_digest(status: dict) -> str:
@@ -0,0 +1,14 @@
1
+ """Microsoft Advertising (Bing Ads) integration — REST API v13.
2
+
3
+ AdLoop's fourth ad platform. Microsoft is retiring the SOAP API on
4
+ 2027-01-31, so this package talks to the REST API directly over
5
+ ``requests`` (no SDK): Campaign Management, Customer Management and
6
+ Reporting. It carries the same layers as the Reddit package: OAuth
7
+ (``auth``), the authenticated HTTP wrapper and report runner (``client``),
8
+ read tools (``read``) and draft/preflight/apply executors (``write``) that
9
+ plug into the shared ``confirm_and_apply`` gate.
10
+
11
+ Every call needs three things: an OAuth access token for a user with access
12
+ to the account (Microsoft identity platform, scope msads.manage), a
13
+ developer token, and the CustomerId / CustomerAccountId headers.
14
+ """