adloop 0.45.0__tar.gz → 0.46.1__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.
- {adloop-0.45.0 → adloop-0.46.1}/PKG-INFO +2 -2
- {adloop-0.45.0 → adloop-0.46.1}/README.md +1 -1
- {adloop-0.45.0 → adloop-0.46.1}/pyproject.toml +1 -1
- {adloop-0.45.0 → adloop-0.46.1}/pyproject.toml.orig +1 -1
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/merchant/read.py +226 -42
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/server.py +11 -4
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/__main__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/_mcp_patches.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/ai_max.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/assets.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/audiences.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/brands.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/campaign_settings.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/client.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/conversion_actions.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/currency.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/custom_conversion_goals.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/enums.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/forecast.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/gaql.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/image_fetch.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/pmax.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/read.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/recommendation_subscriptions.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/recommendations.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/shopping.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/snippet_headers.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/validate_only.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ads/write.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/auth.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/cli.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/config.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/conversion_setup.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/crossref.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/diagnostics.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/admin.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/annotations.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/attribution.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/audiences.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/audit.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/client.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/definitions.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/funnels.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/reports.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/retention.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/suggest.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/tracking.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/ga4/write.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/gsc/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/gsc/client.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/gsc/reports.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/gtm/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/gtm/client.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/gtm/entities.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/gtm/read.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/gtm/write.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/merchant/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/merchant/client.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/auth.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/client.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/_common.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/ad_groups.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/ads.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/campaigns.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/extensions.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/negatives.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/removal.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/manage/targeting.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/read.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/microsoft_ads/write.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/oauth_redirect.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/pagespeed.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/reddit/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/reddit/auth.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/reddit/client.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/reddit/read.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/reddit/schedule.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/reddit/write.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules/adloop.md +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules/commands/analyze-performance.md +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules/commands/budget-plan.md +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules/commands/create-ad.md +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules/commands/create-campaign.md +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules/commands/diagnose-tracking.md +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules/commands/optimize-campaign.md +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/rules_install.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/runtime.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/safety/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/safety/approval.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/safety/approval_card.html +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/safety/audit.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/safety/guards.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/safety/outcomes.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/safety/preview.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/tracking.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/upload_card.html +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/uploads.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/views/__init__.py +0 -0
- {adloop-0.45.0 → adloop-0.46.1}/src/adloop/views/performance.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: adloop
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.46.1
|
|
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
|
|
@@ -248,7 +248,7 @@ The Google account also needs **Edit** permission on the container (and **Publis
|
|
|
248
248
|
| Tool | What It Does |
|
|
249
249
|
|------|-------------|
|
|
250
250
|
| `list_merchant_accounts` | Discover accessible Merchant Center accounts |
|
|
251
|
-
| `get_merchant_feed_health` | Feed health — approved/pending/disapproved counts per reporting context, top product issues with docs, account-level issues. Disapprovals silently starve Shopping/PMax. |
|
|
251
|
+
| `get_merchant_feed_health` | Feed health — approved/pending/disapproved counts per reporting context, paid surfaces kept apart from free listings, top product issues with docs, account-level issues. Disapprovals silently starve Shopping/PMax. |
|
|
252
252
|
| `get_merchant_product_issues` | The products behind the feed-health counts: which are disapproved, limited or pending, and each issue with its attribute and affected countries |
|
|
253
253
|
|
|
254
254
|
> **Setup for Merchant Center tools** — Enable the **Merchant API** in your GCP project (the Content API for Shopping is deprecated). The Merchant API has no read-only scope; AdLoop uses it strictly read-only. Upgrading OAuth users re-authorize once.
|
|
@@ -216,7 +216,7 @@ The Google account also needs **Edit** permission on the container (and **Publis
|
|
|
216
216
|
| Tool | What It Does |
|
|
217
217
|
|------|-------------|
|
|
218
218
|
| `list_merchant_accounts` | Discover accessible Merchant Center accounts |
|
|
219
|
-
| `get_merchant_feed_health` | Feed health — approved/pending/disapproved counts per reporting context, top product issues with docs, account-level issues. Disapprovals silently starve Shopping/PMax. |
|
|
219
|
+
| `get_merchant_feed_health` | Feed health — approved/pending/disapproved counts per reporting context, paid surfaces kept apart from free listings, top product issues with docs, account-level issues. Disapprovals silently starve Shopping/PMax. |
|
|
220
220
|
| `get_merchant_product_issues` | The products behind the feed-health counts: which are disapproved, limited or pending, and each issue with its attribute and affected countries |
|
|
221
221
|
|
|
222
222
|
> **Setup for Merchant Center tools** — Enable the **Merchant API** in your GCP project (the Content API for Shopping is deprecated). The Merchant API has no read-only scope; AdLoop uses it strictly read-only. Upgrading OAuth users re-authorize once.
|
|
@@ -106,6 +106,130 @@ def list_merchant_accounts(config: AdLoopConfig) -> dict:
|
|
|
106
106
|
return {"accounts": accounts, "total": len(accounts), "insights": insights}
|
|
107
107
|
|
|
108
108
|
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
# Feed health (issueresolution/v1 aggregateProductStatuses)
|
|
111
|
+
# ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
# Stats counters of an AggregateProductStatus row, as output key -> API
|
|
114
|
+
# field. The API calls serving products "active"; the output keeps
|
|
115
|
+
# "approved". An expiring product is still active, so "expiring" is
|
|
116
|
+
# reported but never added into a total or a percentage.
|
|
117
|
+
_STAT_FIELDS = (
|
|
118
|
+
("approved", "activeCount"),
|
|
119
|
+
("pending", "pendingCount"),
|
|
120
|
+
("disapproved", "disapprovedCount"),
|
|
121
|
+
("expiring", "expiringCount"),
|
|
122
|
+
)
|
|
123
|
+
_LISTED_FIELDS = ("approved", "pending", "disapproved")
|
|
124
|
+
|
|
125
|
+
# Reporting contexts in which products are advertised for money. A
|
|
126
|
+
# disapproval there costs Shopping / Performance Max reach; one in a free
|
|
127
|
+
# context (FREE_LISTINGS, FREE_LOCAL_LISTINGS, ...) costs organic exposure
|
|
128
|
+
# only. Everything else (YouTube, reviews, cloud retail) is "other".
|
|
129
|
+
_PAID_CONTEXTS = frozenset({
|
|
130
|
+
"SHOPPING_ADS",
|
|
131
|
+
"DISPLAY_ADS",
|
|
132
|
+
"VIDEO_ADS",
|
|
133
|
+
"DEMAND_GEN_ADS",
|
|
134
|
+
"DEMAND_GEN_ADS_DISCOVER_SURFACE",
|
|
135
|
+
"DISCOVERY_ADS",
|
|
136
|
+
"LOCAL_INVENTORY_ADS",
|
|
137
|
+
"VEHICLE_INVENTORY_ADS",
|
|
138
|
+
"RENTAL_ADS",
|
|
139
|
+
})
|
|
140
|
+
_UNSPECIFIED_CONTEXT = "REPORTING_CONTEXT_ENUM_UNSPECIFIED"
|
|
141
|
+
_SURFACE_ORDER = {"paid": 0, "free": 1, "other": 2, "unspecified": 3}
|
|
142
|
+
_SEVERITY_ORDER = {"DISAPPROVED": 0, "DEMOTED": 1, "NOT_IMPACTED": 2}
|
|
143
|
+
_SERVING_IMPACT = ("DISAPPROVED", "DEMOTED")
|
|
144
|
+
|
|
145
|
+
# The API returns 25 rows per page by default and at most 250. An account
|
|
146
|
+
# with a few target countries already spans several reporting contexts per
|
|
147
|
+
# country, so the first page alone undercounts.
|
|
148
|
+
_AGGREGATE_PAGE_SIZE = 250
|
|
149
|
+
|
|
150
|
+
_FEED_HEALTH_NOTE = (
|
|
151
|
+
"A product is counted once per reporting context and target country, "
|
|
152
|
+
"so never add reporting contexts together: read the counts per "
|
|
153
|
+
"context. affected_products on an item issue is its largest single "
|
|
154
|
+
"context, a floor on the products it hits. Product-status data lags "
|
|
155
|
+
"feed changes by about 30 minutes."
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _surface(context: str) -> str:
|
|
160
|
+
"""paid / free / other / unspecified for a reporting context."""
|
|
161
|
+
if context in _PAID_CONTEXTS:
|
|
162
|
+
return "paid"
|
|
163
|
+
if context.startswith("FREE_"):
|
|
164
|
+
return "free"
|
|
165
|
+
if context == _UNSPECIFIED_CONTEXT:
|
|
166
|
+
return "unspecified"
|
|
167
|
+
return "other"
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _row_context(row: dict) -> str:
|
|
171
|
+
"""Reporting context of an aggregate row.
|
|
172
|
+
|
|
173
|
+
Google leaves reportingContext out on some rows. The resource name of
|
|
174
|
+
such a row still ends in ``{context}~{country}``, so fall back to it;
|
|
175
|
+
a row that names no context either is unspecified.
|
|
176
|
+
"""
|
|
177
|
+
context = row.get("reportingContext") or ""
|
|
178
|
+
if context:
|
|
179
|
+
return context
|
|
180
|
+
tail = (row.get("name") or "").rsplit("/", 1)[-1]
|
|
181
|
+
candidate = tail.split("~", 1)[0] if "~" in tail else ""
|
|
182
|
+
if candidate and candidate.replace("_", "").isalpha() and candidate.isupper():
|
|
183
|
+
return candidate
|
|
184
|
+
return _UNSPECIFIED_CONTEXT
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _fetch_aggregate_statuses(config: AdLoopConfig, account_id: str) -> list[dict]:
|
|
188
|
+
"""Every aggregateProductStatuses row, across all pages.
|
|
189
|
+
|
|
190
|
+
Google can return the same row on more than one page; a row is one
|
|
191
|
+
(reporting context, country) pair with a unique resource name, so rows
|
|
192
|
+
whose name was already seen are dropped instead of being counted twice.
|
|
193
|
+
"""
|
|
194
|
+
from adloop.merchant.client import API_ISSUE_RESOLUTION, merchant_get
|
|
195
|
+
|
|
196
|
+
rows: list[dict] = []
|
|
197
|
+
seen_names: set[str] = set()
|
|
198
|
+
seen_tokens: set[str] = set()
|
|
199
|
+
page_token = ""
|
|
200
|
+
while True:
|
|
201
|
+
params: dict = {"pageSize": _AGGREGATE_PAGE_SIZE}
|
|
202
|
+
if page_token:
|
|
203
|
+
params["pageToken"] = page_token
|
|
204
|
+
# Product-status aggregation is served by the issueresolution
|
|
205
|
+
# sub-API, not accounts — the wrong prefix 404s.
|
|
206
|
+
payload = merchant_get(
|
|
207
|
+
config,
|
|
208
|
+
f"accounts/{account_id}/aggregateProductStatuses",
|
|
209
|
+
params,
|
|
210
|
+
api=API_ISSUE_RESOLUTION,
|
|
211
|
+
)
|
|
212
|
+
for row in payload.get("aggregateProductStatuses") or []:
|
|
213
|
+
name = row.get("name") or ""
|
|
214
|
+
if name:
|
|
215
|
+
if name in seen_names:
|
|
216
|
+
continue
|
|
217
|
+
seen_names.add(name)
|
|
218
|
+
rows.append(row)
|
|
219
|
+
page_token = payload.get("nextPageToken") or ""
|
|
220
|
+
# A token handed out twice would loop forever.
|
|
221
|
+
if not page_token or page_token in seen_tokens:
|
|
222
|
+
break
|
|
223
|
+
seen_tokens.add(page_token)
|
|
224
|
+
return rows
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _disapproval_share(context: str, counts: dict) -> str:
|
|
228
|
+
listed = sum(counts[key] for key in _LISTED_FIELDS)
|
|
229
|
+
pct = round(counts["disapproved"] / listed * 100, 1) if listed else 0.0
|
|
230
|
+
return f"{context} {counts['disapproved']:,} of {listed:,} ({pct}%)"
|
|
231
|
+
|
|
232
|
+
|
|
109
233
|
def get_merchant_feed_health(
|
|
110
234
|
config: AdLoopConfig,
|
|
111
235
|
*,
|
|
@@ -113,12 +237,14 @@ def get_merchant_feed_health(
|
|
|
113
237
|
) -> dict:
|
|
114
238
|
"""Feed health for a Merchant Center account — disapprovals + issues.
|
|
115
239
|
|
|
116
|
-
Combines aggregateProductStatuses (per reporting
|
|
117
|
-
approved/pending/disapproved products plus the
|
|
118
|
-
them) with account-level issues that can suspend the whole
|
|
240
|
+
Combines aggregateProductStatuses (per reporting context and country:
|
|
241
|
+
approved/pending/disapproved/expiring products plus the item issues
|
|
242
|
+
behind them) with account-level issues that can suspend the whole
|
|
243
|
+
account. Paid reporting contexts (Shopping, display, video, ...) are
|
|
244
|
+
reported apart from free listings: only the former starve Shopping and
|
|
245
|
+
Performance Max campaigns.
|
|
119
246
|
"""
|
|
120
247
|
from adloop.merchant.client import (
|
|
121
|
-
API_ISSUE_RESOLUTION,
|
|
122
248
|
MerchantNotRegistered,
|
|
123
249
|
merchant_get,
|
|
124
250
|
register_gcp,
|
|
@@ -128,15 +254,9 @@ def get_merchant_feed_health(
|
|
|
128
254
|
if error:
|
|
129
255
|
return error
|
|
130
256
|
|
|
131
|
-
def _fetch() -> tuple[dict, dict]:
|
|
257
|
+
def _fetch() -> tuple[list[dict], dict]:
|
|
132
258
|
return (
|
|
133
|
-
|
|
134
|
-
# sub-API, not accounts — the wrong prefix 404s.
|
|
135
|
-
merchant_get(
|
|
136
|
-
config,
|
|
137
|
-
f"accounts/{account_id}/aggregateProductStatuses",
|
|
138
|
-
api=API_ISSUE_RESOLUTION,
|
|
139
|
-
),
|
|
259
|
+
_fetch_aggregate_statuses(config, account_id),
|
|
140
260
|
merchant_get(config, f"accounts/{account_id}/issues"),
|
|
141
261
|
)
|
|
142
262
|
|
|
@@ -170,42 +290,103 @@ def get_merchant_feed_health(
|
|
|
170
290
|
for issue in issues_payload.get("accountIssues", [])
|
|
171
291
|
]
|
|
172
292
|
|
|
173
|
-
contexts = []
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
for status in statuses
|
|
177
|
-
|
|
293
|
+
contexts: list[dict] = []
|
|
294
|
+
totals: dict[str, dict] = {}
|
|
295
|
+
by_code: dict[str, dict] = {}
|
|
296
|
+
for status in statuses:
|
|
297
|
+
context = _row_context(status)
|
|
298
|
+
surface = _surface(context)
|
|
299
|
+
stats = status.get("stats") or {}
|
|
178
300
|
entry = {
|
|
179
|
-
"reporting_context":
|
|
180
|
-
"
|
|
181
|
-
"
|
|
182
|
-
"pending": int(stats.get("pendingCount", 0) or 0),
|
|
183
|
-
"disapproved": int(stats.get("disapprovedCount", 0) or 0),
|
|
301
|
+
"reporting_context": context,
|
|
302
|
+
"surface": surface,
|
|
303
|
+
"country": status.get("country", ""),
|
|
184
304
|
}
|
|
305
|
+
for key, field in _STAT_FIELDS:
|
|
306
|
+
entry[key] = int(stats.get(field, 0) or 0)
|
|
185
307
|
contexts.append(entry)
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
308
|
+
|
|
309
|
+
total = totals.setdefault(
|
|
310
|
+
context, {"surface": surface, **{key: 0 for key, _ in _STAT_FIELDS}}
|
|
311
|
+
)
|
|
312
|
+
for key, _ in _STAT_FIELDS:
|
|
313
|
+
total[key] += entry[key]
|
|
314
|
+
|
|
315
|
+
# The same issue code repeats for every context and country it
|
|
316
|
+
# touches; one entry per code, sized by its largest single row,
|
|
317
|
+
# because summing rows would count a product once per context.
|
|
318
|
+
for issue in status.get("itemLevelIssues") or []:
|
|
319
|
+
code = issue.get("code", "")
|
|
320
|
+
severity = issue.get("severity", "")
|
|
321
|
+
record = by_code.setdefault(code, {
|
|
322
|
+
"issue": code,
|
|
323
|
+
"description": issue.get("description", ""),
|
|
324
|
+
"severity": severity,
|
|
325
|
+
"resolution": issue.get("resolution", ""),
|
|
326
|
+
"attribute": issue.get("attribute", ""),
|
|
327
|
+
"affected_products": 0,
|
|
328
|
+
"hits_paid_surface": False,
|
|
329
|
+
"reporting_contexts": set(),
|
|
196
330
|
"documentation": issue.get("documentationUri", ""),
|
|
197
331
|
})
|
|
198
|
-
|
|
332
|
+
record["affected_products"] = max(
|
|
333
|
+
record["affected_products"], int(issue.get("productCount", 0) or 0)
|
|
334
|
+
)
|
|
335
|
+
if _SEVERITY_ORDER.get(severity, 9) < _SEVERITY_ORDER.get(record["severity"], 9):
|
|
336
|
+
record["severity"] = severity
|
|
337
|
+
record["reporting_contexts"].add(context)
|
|
338
|
+
if surface == "paid" and severity in _SERVING_IMPACT:
|
|
339
|
+
record["hits_paid_surface"] = True
|
|
340
|
+
|
|
341
|
+
contexts.sort(key=lambda c: (
|
|
342
|
+
_SURFACE_ORDER[c["surface"]], c["reporting_context"], c["country"],
|
|
343
|
+
))
|
|
344
|
+
totals = dict(sorted(
|
|
345
|
+
totals.items(), key=lambda kv: (_SURFACE_ORDER[kv[1]["surface"]], kv[0])
|
|
346
|
+
))
|
|
347
|
+
top_item_issues = sorted(
|
|
348
|
+
by_code.values(),
|
|
349
|
+
key=lambda i: (
|
|
350
|
+
_SEVERITY_ORDER.get(i["severity"], 9),
|
|
351
|
+
not i["hits_paid_surface"],
|
|
352
|
+
-i["affected_products"],
|
|
353
|
+
),
|
|
354
|
+
)
|
|
355
|
+
for issue in top_item_issues:
|
|
356
|
+
issue["reporting_contexts"] = sorted(issue["reporting_contexts"])
|
|
199
357
|
|
|
200
358
|
insights = []
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
359
|
+
paid = {c: t for c, t in totals.items() if t["surface"] == "paid"}
|
|
360
|
+
free = {c: t for c, t in totals.items() if t["surface"] == "free"}
|
|
361
|
+
paid_hit = [c for c, t in paid.items() if t["disapproved"]]
|
|
362
|
+
free_hit = [c for c, t in free.items() if t["disapproved"]]
|
|
363
|
+
if paid_hit:
|
|
364
|
+
insights.append(
|
|
365
|
+
"Paid surfaces: "
|
|
366
|
+
+ "; ".join(_disapproval_share(c, paid[c]) for c in paid_hit)
|
|
367
|
+
+ " products DISAPPROVED and not serving — this directly starves "
|
|
368
|
+
"Shopping and Performance Max campaigns. Fix the top issues "
|
|
369
|
+
"below before touching bids or budgets."
|
|
370
|
+
)
|
|
371
|
+
elif paid:
|
|
372
|
+
insights.append(
|
|
373
|
+
"Paid surfaces (" + ", ".join(paid) + ") have no disapproved "
|
|
374
|
+
"products — disapprovals are not what holds Shopping or "
|
|
375
|
+
"Performance Max back."
|
|
376
|
+
)
|
|
377
|
+
if free_hit:
|
|
378
|
+
insights.append(
|
|
379
|
+
"Free listings: "
|
|
380
|
+
+ "; ".join(_disapproval_share(c, free[c]) for c in free_hit)
|
|
381
|
+
+ " products disapproved — this costs organic exposure only, "
|
|
382
|
+
"not Shopping or Performance Max reach."
|
|
383
|
+
)
|
|
384
|
+
unspecified = [c for c in contexts if c["surface"] == "unspecified"]
|
|
385
|
+
if unspecified:
|
|
204
386
|
insights.append(
|
|
205
|
-
f"{
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
f"touching bids or budgets."
|
|
387
|
+
f"{len(unspecified)} row(s) came back without a reporting "
|
|
388
|
+
"context; they are listed in by_reporting_context but left out "
|
|
389
|
+
"of the paid / free split."
|
|
209
390
|
)
|
|
210
391
|
critical = [
|
|
211
392
|
i for i in account_issues if i["severity"] in ("CRITICAL", "ERROR")
|
|
@@ -216,7 +397,9 @@ def get_merchant_feed_health(
|
|
|
216
397
|
f"severity — CRITICAL means offers stop serving entirely: "
|
|
217
398
|
+ "; ".join(i["title"] for i in critical[:3])
|
|
218
399
|
)
|
|
219
|
-
|
|
400
|
+
any_products = any(c[key] for c in contexts for key in _LISTED_FIELDS)
|
|
401
|
+
any_disapproved = any(c["disapproved"] for c in contexts)
|
|
402
|
+
if not any_products:
|
|
220
403
|
# Zero products is not a healthy feed: Shopping and Performance Max
|
|
221
404
|
# have nothing to advertise.
|
|
222
405
|
insights.append(
|
|
@@ -226,7 +409,7 @@ def get_merchant_feed_health(
|
|
|
226
409
|
"products were added in the last ~30 minutes (status lags), or "
|
|
227
410
|
"the products live in another Merchant Center account."
|
|
228
411
|
)
|
|
229
|
-
elif not account_issues and not
|
|
412
|
+
elif not account_issues and not any_disapproved:
|
|
230
413
|
insights.append("No disapprovals or account issues — feed is healthy.")
|
|
231
414
|
|
|
232
415
|
return {
|
|
@@ -236,6 +419,7 @@ def get_merchant_feed_health(
|
|
|
236
419
|
"account_issues": account_issues,
|
|
237
420
|
"top_item_issues": top_item_issues[:15],
|
|
238
421
|
"insights": insights,
|
|
422
|
+
"note": _FEED_HEALTH_NOTE,
|
|
239
423
|
}
|
|
240
424
|
|
|
241
425
|
|
|
@@ -220,9 +220,12 @@ mcp = FastMCP(
|
|
|
220
220
|
|
|
221
221
|
|
|
222
222
|
|
|
223
|
+
# "core": ADLOOP_TOOLSETS enables components by tag (only=True), and an
|
|
224
|
+
# untagged resource would be switched off while tools still point at it.
|
|
223
225
|
@mcp.resource(
|
|
224
226
|
CARD_URI,
|
|
225
227
|
name="approval_card",
|
|
228
|
+
tags={"core"},
|
|
226
229
|
title="AdLoop approval card",
|
|
227
230
|
description="Renders a change preview with Test run and Apply buttons.",
|
|
228
231
|
mime_type=CARD_MIME_TYPE,
|
|
@@ -235,6 +238,7 @@ def approval_card() -> str:
|
|
|
235
238
|
@mcp.resource(
|
|
236
239
|
UPLOAD_CARD_URI,
|
|
237
240
|
name="upload_card",
|
|
241
|
+
tags={"core"},
|
|
238
242
|
title="AdLoop image upload",
|
|
239
243
|
description="A drop zone that uploads images to AdLoop for use as ad assets.",
|
|
240
244
|
mime_type=CARD_MIME_TYPE,
|
|
@@ -249,6 +253,7 @@ def upload_card() -> str:
|
|
|
249
253
|
@mcp.resource(
|
|
250
254
|
VIEW_URI,
|
|
251
255
|
name="adloop_view",
|
|
256
|
+
tags={"core"},
|
|
252
257
|
title="AdLoop view",
|
|
253
258
|
description="Draws a read result as a dashboard (charts and tables).",
|
|
254
259
|
mime_type=VIEW_MIME_TYPE,
|
|
@@ -1707,10 +1712,12 @@ def get_merchant_feed_health(account_id: str = "") -> dict:
|
|
|
1707
1712
|
"""Merchant Center feed health — disapproved products + account issues.
|
|
1708
1713
|
|
|
1709
1714
|
Disapproved feed items silently starve Shopping and Performance Max
|
|
1710
|
-
campaigns; this reports approved/pending/disapproved counts
|
|
1711
|
-
reporting context
|
|
1712
|
-
|
|
1713
|
-
|
|
1715
|
+
campaigns; this reports approved/pending/disapproved/expiring counts
|
|
1716
|
+
per reporting context and country, each context marked paid (Shopping,
|
|
1717
|
+
display, video ads, ...) or free (free listings), the top item issues
|
|
1718
|
+
by affected products (with documentation links), and account-level
|
|
1719
|
+
issues — CRITICAL ones stop offers serving entirely. A product counts
|
|
1720
|
+
once per reporting context, so contexts are never added together.
|
|
1714
1721
|
Product-status data lags reality by ~30 minutes.
|
|
1715
1722
|
|
|
1716
1723
|
Args:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|