adloop 0.41.3__tar.gz → 0.41.4__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.41.3 → adloop-0.41.4}/PKG-INFO +1 -1
- {adloop-0.41.3 → adloop-0.41.4}/pyproject.toml +1 -1
- {adloop-0.41.3 → adloop-0.41.4}/pyproject.toml.orig +1 -1
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/currency.py +17 -10
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/image_fetch.py +3 -3
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/write.py +59 -8
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/reddit/read.py +8 -3
- {adloop-0.41.3 → adloop-0.41.4}/README.md +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/__main__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/_mcp_patches.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/ai_max.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/assets.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/audiences.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/brands.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/campaign_settings.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/client.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/conversion_actions.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/custom_conversion_goals.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/enums.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/forecast.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/gaql.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/pmax.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/read.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/recommendation_subscriptions.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/recommendations.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/shopping.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/snippet_headers.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ads/validate_only.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/auth.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/cli.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/config.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/conversion_setup.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/crossref.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/diagnostics.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/admin.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/annotations.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/attribution.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/audit.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/client.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/definitions.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/funnels.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/reports.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/retention.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/suggest.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/tracking.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/ga4/write.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/gsc/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/gsc/client.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/gsc/reports.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/gtm/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/gtm/client.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/gtm/entities.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/gtm/read.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/gtm/write.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/merchant/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/merchant/client.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/merchant/read.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/auth.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/client.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/_common.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/ad_groups.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/ads.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/campaigns.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/extensions.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/negatives.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/removal.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/manage/targeting.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/read.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/microsoft_ads/write.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/oauth_redirect.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/pagespeed.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/reddit/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/reddit/auth.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/reddit/client.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/reddit/schedule.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/reddit/write.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules/adloop.md +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules/commands/analyze-performance.md +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules/commands/budget-plan.md +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules/commands/create-ad.md +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules/commands/create-campaign.md +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules/commands/diagnose-tracking.md +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules/commands/optimize-campaign.md +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/rules_install.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/runtime.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/safety/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/safety/approval.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/safety/approval_card.html +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/safety/audit.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/safety/guards.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/safety/outcomes.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/safety/preview.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/server.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/tracking.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/upload_card.html +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/uploads.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/views/__init__.py +0 -0
- {adloop-0.41.3 → adloop-0.41.4}/src/adloop/views/performance.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: adloop
|
|
3
|
-
Version: 0.41.
|
|
3
|
+
Version: 0.41.4
|
|
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
|
|
@@ -37,21 +37,26 @@ _CURRENCY_SYMBOLS: dict[str, str] = {
|
|
|
37
37
|
"UAH": "\u20b4",
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
# Module-level cache: customer_id -> currency_code (one API call
|
|
41
|
-
|
|
40
|
+
# Module-level cache: (tenant, customer_id) -> currency_code (one API call
|
|
41
|
+
# per session). The tenant is part of the key because a hosted server runs
|
|
42
|
+
# many tenants in one process: what one of them reads, or fails to read,
|
|
43
|
+
# about an account must never be served to another.
|
|
44
|
+
_cache: dict[tuple[str, str], str] = {}
|
|
42
45
|
|
|
43
46
|
|
|
44
47
|
def get_currency_code(config: AdLoopConfig, customer_id: str) -> str:
|
|
45
48
|
"""Detect the account's currency via ``customer.currency_code``.
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
Falls back to ``"EUR"`` on any error
|
|
50
|
+
A successful lookup is cached per tenant and *customer_id* for the
|
|
51
|
+
lifetime of the server process. Falls back to ``"EUR"`` on any error;
|
|
52
|
+
the fallback is not cached, so a passing failure does not stick.
|
|
49
53
|
"""
|
|
50
54
|
from adloop.ads.client import normalize_customer_id
|
|
55
|
+
from adloop.runtime import current_tenant
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
if
|
|
54
|
-
return _cache[
|
|
57
|
+
key = (current_tenant(), normalize_customer_id(customer_id))
|
|
58
|
+
if key in _cache:
|
|
59
|
+
return _cache[key]
|
|
55
60
|
|
|
56
61
|
try:
|
|
57
62
|
from adloop.ads.gaql import execute_query
|
|
@@ -59,11 +64,13 @@ def get_currency_code(config: AdLoopConfig, customer_id: str) -> str:
|
|
|
59
64
|
rows = execute_query(
|
|
60
65
|
config, customer_id, "SELECT customer.currency_code FROM customer LIMIT 1"
|
|
61
66
|
)
|
|
62
|
-
code =
|
|
67
|
+
code = rows[0].get("customer.currency_code") if rows else None
|
|
63
68
|
except Exception:
|
|
64
|
-
code =
|
|
69
|
+
code = None
|
|
70
|
+
if not code:
|
|
71
|
+
return "EUR"
|
|
65
72
|
|
|
66
|
-
_cache[
|
|
73
|
+
_cache[key] = code
|
|
67
74
|
return code
|
|
68
75
|
|
|
69
76
|
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
The fetched bytes are uploaded into the user's Google Ads account, where
|
|
4
4
|
they become visible. A fetch that could be steered at an internal address
|
|
5
5
|
(cloud metadata, a database admin page, a loopback service) would therefore
|
|
6
|
-
be a way to exfiltrate whatever lives there. So
|
|
7
|
-
reachability check for landing pages
|
|
8
|
-
|
|
6
|
+
be a way to exfiltrate whatever lives there. So this fetcher closes the
|
|
7
|
+
DNS-rebinding gap (the reachability check for landing pages reuses its
|
|
8
|
+
pinned connections):
|
|
9
9
|
|
|
10
10
|
* the hostname is resolved exactly once per request, and every resolved
|
|
11
11
|
address must be public;
|
|
@@ -216,12 +216,10 @@ def _ssrf_error(url: str) -> str | None:
|
|
|
216
216
|
pointing at such addresses could never serve anyway. Returns an error
|
|
217
217
|
string, or None if the URL looks safe to fetch.
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
server
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
``adloop.ads.image_fetch``, which pins the connection to the checked
|
|
224
|
-
address.
|
|
219
|
+
This check is the readable refusal. What holds against a hostile DNS
|
|
220
|
+
server (one answer for this check, another for the fetch) is the opener
|
|
221
|
+
from ``_build_public_only_opener``: it resolves the name once more,
|
|
222
|
+
refuses a non-public answer and connects to exactly that address.
|
|
225
223
|
"""
|
|
226
224
|
import ipaddress
|
|
227
225
|
import socket
|
|
@@ -262,8 +260,48 @@ def _ssrf_error(url: str) -> str | None:
|
|
|
262
260
|
return None
|
|
263
261
|
|
|
264
262
|
|
|
263
|
+
def _pinned_connection_factory(scheme: str):
|
|
264
|
+
"""A connection class for urllib that dials only a checked, public address.
|
|
265
|
+
|
|
266
|
+
urllib resolves the hostname when it connects, after any check made
|
|
267
|
+
beforehand, so a DNS server can answer the check with a public address
|
|
268
|
+
and the connection with an internal one (DNS rebinding). This factory
|
|
269
|
+
resolves once, refuses a non-public answer and connects to that very
|
|
270
|
+
address; the request keeps its Host header, and TLS still verifies the
|
|
271
|
+
certificate against the hostname.
|
|
272
|
+
"""
|
|
273
|
+
import urllib.error
|
|
274
|
+
from urllib.parse import urlsplit
|
|
275
|
+
|
|
276
|
+
from adloop.ads import image_fetch
|
|
277
|
+
|
|
278
|
+
def connect(host, timeout=image_fetch.TIMEOUT_SECONDS, **kwargs):
|
|
279
|
+
parts = urlsplit(f"//{host}")
|
|
280
|
+
name = parts.hostname or host
|
|
281
|
+
port = parts.port or (443 if scheme == "https" else 80)
|
|
282
|
+
try:
|
|
283
|
+
pinned_ip = image_fetch.resolve_public_address(name, port)
|
|
284
|
+
except image_fetch.ImageFetchError as e:
|
|
285
|
+
raise urllib.error.URLError(str(e)) from e
|
|
286
|
+
if scheme == "https":
|
|
287
|
+
return image_fetch._PinnedHTTPSConnection(
|
|
288
|
+
name, port, pinned_ip=pinned_ip, timeout=timeout,
|
|
289
|
+
context=kwargs.get("context") or image_fetch._tls_context(),
|
|
290
|
+
)
|
|
291
|
+
return image_fetch._PinnedHTTPConnection(name, port, pinned_ip=pinned_ip, timeout=timeout)
|
|
292
|
+
|
|
293
|
+
return connect
|
|
294
|
+
|
|
295
|
+
|
|
265
296
|
def _build_public_only_opener():
|
|
266
|
-
"""Return a urllib opener that
|
|
297
|
+
"""Return a urllib opener that can only reach public addresses.
|
|
298
|
+
|
|
299
|
+
Every redirect hop is checked, and every connection (the first request
|
|
300
|
+
and each redirect) goes to an address that was resolved once and found
|
|
301
|
+
public, so the check cannot be passed with one DNS answer and the fetch
|
|
302
|
+
made with another. Behind an HTTP proxy the proxy does the resolving,
|
|
303
|
+
so there the stock connections are kept.
|
|
304
|
+
"""
|
|
267
305
|
import urllib.error
|
|
268
306
|
import urllib.request
|
|
269
307
|
|
|
@@ -274,7 +312,20 @@ def _build_public_only_opener():
|
|
|
274
312
|
raise urllib.error.URLError(f"redirect blocked: {err}")
|
|
275
313
|
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
|
276
314
|
|
|
277
|
-
|
|
315
|
+
if urllib.request.getproxies():
|
|
316
|
+
return urllib.request.build_opener(_PublicOnlyRedirectHandler)
|
|
317
|
+
|
|
318
|
+
class _PinnedHTTPHandler(urllib.request.HTTPHandler):
|
|
319
|
+
def http_open(self, req):
|
|
320
|
+
return self.do_open(_pinned_connection_factory("http"), req)
|
|
321
|
+
|
|
322
|
+
class _PinnedHTTPSHandler(urllib.request.HTTPSHandler):
|
|
323
|
+
def https_open(self, req):
|
|
324
|
+
return self.do_open(_pinned_connection_factory("https"), req)
|
|
325
|
+
|
|
326
|
+
return urllib.request.build_opener(
|
|
327
|
+
_PublicOnlyRedirectHandler, _PinnedHTTPHandler, _PinnedHTTPSHandler
|
|
328
|
+
)
|
|
278
329
|
|
|
279
330
|
|
|
280
331
|
# Statuses that say nothing about whether the landing page is any good:
|
|
@@ -91,7 +91,9 @@ _STANDARD_PIXEL_EVENTS = (
|
|
|
91
91
|
"custom",
|
|
92
92
|
)
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
# Keyed by (tenant, ad account): a hosted server runs many tenants in one
|
|
95
|
+
# process, and one tenant must not be served what another's login read.
|
|
96
|
+
_account_meta_cache: dict[tuple[str, str], dict] = {}
|
|
95
97
|
|
|
96
98
|
|
|
97
99
|
# ---------------------------------------------------------------------------
|
|
@@ -116,7 +118,10 @@ def resolve_account(config: AdLoopConfig, ad_account_id: str = "") -> str:
|
|
|
116
118
|
|
|
117
119
|
def account_meta(config: AdLoopConfig, ad_account_id: str) -> dict:
|
|
118
120
|
"""Currency + time zone of an ad account, cached per process."""
|
|
119
|
-
|
|
121
|
+
from adloop.runtime import current_tenant
|
|
122
|
+
|
|
123
|
+
key = (current_tenant(), ad_account_id)
|
|
124
|
+
cached = _account_meta_cache.get(key)
|
|
120
125
|
if cached is not None:
|
|
121
126
|
return cached
|
|
122
127
|
data = data_of(reddit_get(config, f"ad_accounts/{ad_account_id}"))
|
|
@@ -127,7 +132,7 @@ def account_meta(config: AdLoopConfig, ad_account_id: str) -> dict:
|
|
|
127
132
|
"business_id": str(data.get("business_id") or ""),
|
|
128
133
|
"admin_approval": str(data.get("admin_approval") or ""),
|
|
129
134
|
}
|
|
130
|
-
_account_meta_cache[
|
|
135
|
+
_account_meta_cache[key] = meta
|
|
131
136
|
return meta
|
|
132
137
|
|
|
133
138
|
|
|
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
|