ads-mcp-for-snapchat 0.6.0 → 0.9.0
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.
- package/.env.example +4 -0
- package/ARCHITECTURE.md +8 -2
- package/CHANGELOG.md +51 -0
- package/PRIVACY.md +28 -0
- package/README.md +35 -1
- package/SECURITY.md +13 -0
- package/broker/README.md +43 -0
- package/broker/worker.js +171 -0
- package/broker/wrangler.toml +10 -0
- package/package.json +5 -2
- package/src/advice.js +178 -0
- package/src/audit-log.js +4 -3
- package/src/broker.js +109 -0
- package/src/catalog-ads.js +152 -0
- package/src/changes.js +26 -1
- package/src/checks.js +229 -0
- package/src/controls.js +101 -0
- package/src/create.js +24 -7
- package/src/env.js +11 -0
- package/src/hybrid.js +70 -0
- package/src/hygiene.js +239 -0
- package/src/index.js +1 -1
- package/src/intel.js +139 -0
- package/src/policy.js +9 -0
- package/src/portfolio.js +82 -0
- package/src/prompts.js +64 -2
- package/src/report.js +1 -1
- package/src/setup.js +75 -44
- package/src/snap.js +57 -1
- package/src/tools.js +399 -18
- package/src/toolsets.js +26 -0
package/.env.example
CHANGED
|
@@ -17,6 +17,10 @@ SNAP_DEFAULT_PHONE_CODE=
|
|
|
17
17
|
SNAP_REPORT_UTC_OFFSET=+00:00
|
|
18
18
|
# Optional: where the change/audit log goes (default: changes.log.jsonl, or <SNAP_ENV_FILE>.log.jsonl when that is set)
|
|
19
19
|
# SNAP_LOG_FILE=
|
|
20
|
+
# Optional: SNAP_BROKER_URL=https://login.example.com (the shared login service; a refresh token is sent there, so use only one you trust)
|
|
21
|
+
# Optional: SNAP_HOME=/some/folder (where settings, the change log and exports live; default ~/.ads-mcp-for-snapchat for an npm install)
|
|
22
|
+
# Optional: SNAP_PORTFOLIO_FILES=/abs/path/.env,/abs/path/.env.account2 (accounts shown side by side by snap_portfolio_summary)
|
|
23
|
+
# Optional: SNAP_TOOLSETS=setup,reports,checks (show only these tool groups: setup, read, reports, checks, changes, create; default all)
|
|
20
24
|
# Optional: SNAP_MAX_LIFETIME_BUDGET, SNAP_MAX_ACTIVATION_DAILY_BUDGET, SNAP_MAX_ADDED_DAILY_BUDGET_24H, SNAP_ACCOUNT_CURRENCY=USD,
|
|
21
25
|
# SNAP_READ_ONLY=1, SNAP_HUMAN_APPROVAL=elicit (see README "Safety settings")
|
|
22
26
|
# Only needed once, by scripts/get-refresh-token.js (must match the redirect URL on your OAuth app)
|
package/ARCHITECTURE.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# Architecture and design notes
|
|
2
2
|
|
|
3
|
-
For contributors. Unofficial local MCP server (Node ESM, stdio) for the Snapchat Marketing API:
|
|
3
|
+
For contributors. Unofficial local MCP server (Node ESM, stdio) for the Snapchat Marketing API: 85 tools, all tests mocked (`npm test`). Read `README.md` first for setup and the tool table.
|
|
4
4
|
|
|
5
5
|
## Architecture (src/)
|
|
6
|
+
- `portfolio.js`: several accounts side by side, from the settings files the owner lists in SNAP_PORTFOLIO_FILES (read-only).
|
|
7
|
+
- `hygiene.js`: billing, unused media, audience health, funnel, catalog feed status (read-only). `toolsets.js`: tool groups for SNAP_TOOLSETS (a test fails when a new tool is not in a group).
|
|
8
|
+
- `controls.js`: frequency cap and ad schedule planners. `advice.js`: hourly report, creative comparison and budget advice (read-only suggestions).
|
|
9
|
+
- `intel.js`: Audience Insights, the public Ads Gallery, Conversions API test events (the token goes only to tr.snapchat.com; the real events endpoint is never called).
|
|
10
|
+
- `checks.js`: landing page checker (https only, public addresses only, redirects followed by hand), anomaly check, blended ROAS (read-only).
|
|
11
|
+
- `catalog-ads.js`: product set filter rules, dynamic template / creative builders and DPA audiences (Snap's Dynamic Product Ads guide).
|
|
6
12
|
- `insights.js`: audience size, spend pacing, ad preview (read-only). `prompts.js`: the playbooks (MCP prompts).
|
|
7
13
|
- `setup.js`: the guided `setup` command; `oauth.js`: authorization link, code exchange and ad-account list (used by `setup` and the `snap_connect` tool). `manifest.json` + `scripts/build-mcpb.js`: the Claude Desktop extension (`npm run pack:mcpb`).
|
|
8
|
-
- `cli.js`: npm command (`npx ads-mcp-for-snapchat`): no command starts the server; `setup`, `init`, `where`, `save-secret`, `auth`, `check`, `weekly-report` run the setup scripts. `index.js`: MCP server entry. `tools.js`: all
|
|
14
|
+
- `cli.js`: npm command (`npx ads-mcp-for-snapchat`): no command starts the server; `setup`, `init`, `where`, `save-secret`, `auth`, `check`, `weekly-report` run the setup scripts. `index.js`: MCP server entry. `tools.js`: all 85 tool definitions (zod schemas, handlers).
|
|
9
15
|
- `snap.js`: `SnapClient` (token refresh, retry), `ENTITIES` (campaign, adsquad, ad, creative, media, segment), sanitize-for-create/update helpers, `createEntity/updateEntity/getEntity/listChildren`, `upload`.
|
|
10
16
|
- `env.js`: `.env` loading, `setEnvValue` (writes a value without printing it) and `dataDir` (the project folder for a git checkout; `~/.ads-mcp-for-snapchat` for a copy inside `node_modules`; `SNAP_HOME` overrides). The default change log and `exports/` live there too.
|
|
11
17
|
- `changes.js`: plan functions (status, budget, exclusions, rename, bid, targeting, schedule), `applyChange` (logs before/after), `containsDeep`, `planUndo`.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0 (2026-11-15)
|
|
4
|
+
|
|
5
|
+
- **Shared login (log in with Snapchat, no OAuth app).** `setup` offers it first; in Claude Desktop leave the Client ID and secret empty and ask Claude to connect: the browser finishes the login by itself, nothing is pasted. A small stateless login service (`broker/`, a Cloudflare Worker) holds one shared app's secret and nothing else. It stores no tokens, accounts or logs: at login it seals the refresh token to a key made on the person's own computer and redirects only to `http://127.0.0.1:<port>` (checked), and later it only swaps a refresh token for a 30-minute access token. Using your own Snapchat app still works exactly as before and always wins when its secret is present.
|
|
6
|
+
- The login is protected by a signed state (no storage), a cookie that ties it to the browser that started it, an expiry, a loopback-only redirect, a nonce-bound sealed token, and a listener on the computer that checks the Host header and accepts one callback only.
|
|
7
|
+
- New: `PRIVACY.md`, `broker/README.md` (how to deploy and what to check before announcing it), `SNAP_BROKER_URL`, `adsMcpBroker` in `package.json` (the default service address, empty until one is deployed).
|
|
8
|
+
- Not yet run against the real Snapchat login: the service is tested against a fake one. Follow `broker/README.md` step 5 before announcing it. ChatGPT support is not part of this: ChatGPT needs a hosted MCP server.
|
|
9
|
+
|
|
10
|
+
## Unreleased
|
|
11
|
+
|
|
12
|
+
- Docs: `SECURITY.md` now lists every outside address the server contacts and what is sent. New tests fail when a tool or a `SNAP_` setting is missing from the README, or when the code starts contacting an address that `SECURITY.md` does not list. `SNAP_HOME` was missing from the README and is now documented.
|
|
13
|
+
|
|
14
|
+
## 0.8.0 (2026-11-15)
|
|
15
|
+
|
|
16
|
+
Not yet verified on a live account (built from Snap's documentation and mocked tests).
|
|
17
|
+
|
|
18
|
+
- `snap_set_bid_strategy`: switch an ad squad between max bid and target cost with the bid for the new strategy, under the same bid limits as `snap_set_bid`. An ad squad on auto-bid can be given a cap this way. Switching TO auto-bid is deliberately not offered, and an undo can never restore auto-bid, because that would remove the bid cap.
|
|
19
|
+
- `snap_set_placement`: automatic, or custom positions (PUBLIC_STORIES_INSTREAM, INTERSTITIAL_CONTENT, INTERSTITIAL_SPOTLIGHT, INTERSTITIAL_USER, FEED, CAMERA, CHAT_FEED with Snap's CHAT_FEED rule). Refused on ad squads that use content inclusion or exclusion lists. Undo works when a placement was set before.
|
|
20
|
+
- `snap_portfolio_summary`: all your ad accounts side by side. The accounts are the settings files you list in `SNAP_PORTFOLIO_FILES`; the tool takes no arguments, so the AI app cannot choose files. Each account is read with its own credentials, only account-level numbers are returned, and currencies are never added together.
|
|
21
|
+
- Undo now validates the new editable fields (placement, caps, schedules, bid strategy) the same way it validates the old ones.
|
|
22
|
+
- This release also contains everything in 0.7.0, which is already on npm.
|
|
23
|
+
|
|
24
|
+
## 0.7.0 (2026-11-15)
|
|
25
|
+
|
|
26
|
+
Everything below is built from Snap's documentation and mocked tests and is not yet verified on a live account. New write tools are previewed, need approval, are audited and create things PAUSED; all other new tools only read.
|
|
27
|
+
|
|
28
|
+
**Catalog ads (Dynamic Product Ads)**
|
|
29
|
+
- `snap_create_product_set` (Snap's filter rules are checked before anything is sent), `snap_create_dynamic_template`, `snap_list_dynamic_templates`.
|
|
30
|
+
- `snap_create_campaign` takes `catalog_id`; `snap_create_adsquad` takes `product_set_id`, `dpa_mode` (retargeting / prospecting) and `audience_days`; `snap_create_creative` takes `creative_type: DYNAMIC_PRODUCT`; `snap_create_ad` creates the DYNAMIC ad and refuses a creative whose product set differs from the ad squad's. Catalogs and templates must belong to the ad account's organization / account.
|
|
31
|
+
|
|
32
|
+
**Checks**
|
|
33
|
+
- `snap_check_landing_pages`: opens each active ad's link once (https only, never private or link-local addresses, every redirect checked) and reports broken, slow, server-error, unreachable and non-https links, links that end on another site, and links missing parameters you name. It cannot see "out of stock" text inside a page that opens.
|
|
34
|
+
- `snap_anomaly_check`: the last full local day against the usual day: spend spike or drop, zero or falling purchases (possible broken pixel), ROAS drop, cost-per-purchase spike.
|
|
35
|
+
- `snap_blended_roas`: Snap's reported revenue against the revenue your store confirms.
|
|
36
|
+
- `snap_billing_check` (card expiry, daily limit vs budgets, credit left), `snap_unused_media`, `snap_audience_health`, `snap_funnel`, `snap_catalog_feed_status`.
|
|
37
|
+
|
|
38
|
+
**Intelligence**
|
|
39
|
+
- `snap_audience_insights`: who is in an audience compared with everyone in the same countries.
|
|
40
|
+
- `snap_competitor_ads`: a company's ads from Snap's public Ads Gallery (no login; nothing about your account is sent; ad text is cut and marked as untrusted).
|
|
41
|
+
- `snap_capi_status` and `snap_capi_test_event`: Conversions API TEST events only (email hashed locally, validate endpoint only). There is deliberately no tool that sends real conversion events.
|
|
42
|
+
|
|
43
|
+
**Controls and advice**
|
|
44
|
+
- `snap_set_frequency_cap` and `snap_set_ad_schedule` (undoable when a value existed before). Snap allows an ad schedule only on lifetime-budget ad squads, so it is refused on daily-budget ones with the reason.
|
|
45
|
+
- `snap_create_adsquad` takes `goal`: pixel goals (purchase, add to cart, page view, sign-up), traffic (SWIPES), awareness (IMPRESSIONS), video views. The default is unchanged.
|
|
46
|
+
- `snap_report_hourly`, `snap_creative_compare`, `snap_budget_advice` (suggested moves that net to zero and stay inside your limits, each naming the tool that applies it).
|
|
47
|
+
- Playbooks: Budget review, Tracking check, Competitor scan, Fix rejected ads; Weekly review and Launch checklist use the new checks.
|
|
48
|
+
|
|
49
|
+
**Other**
|
|
50
|
+
- `SNAP_TOOLSETS`: offer only some tool groups (setup, read, reports, checks, changes, create) to the AI app. A typo stops the server; a test fails when a new tool is missing from a group.
|
|
51
|
+
- Privacy fix: the audit log now removes emails and phone numbers from logged tool arguments (by key and inside text), as it already did for credentials.
|
|
52
|
+
- Not built, because Snap's documentation does not show a safe form: custom placement control, bid-strategy switching.
|
|
53
|
+
|
|
3
54
|
## 0.6.0 (2026-11-14)
|
|
4
55
|
|
|
5
56
|
- `snap_audience_size`: Snap's reach estimate before spending, for an existing ad squad or for targeting you are planning (same targeting rules as creating an ad squad), with a verdict: very small, small, OK or very broad. Nothing is created.
|
package/PRIVACY.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Privacy
|
|
2
|
+
|
|
3
|
+
Ads MCP for Snapchat is open-source software that runs **on your own computer**. This page covers the optional **shared login service** and the tool itself.
|
|
4
|
+
|
|
5
|
+
## The tool (on your computer)
|
|
6
|
+
- Your settings, the change log and exports stay on your computer. Nothing is sent to the maintainer.
|
|
7
|
+
- It talks to Snapchat's servers with your login to read and change your own ad account, as you ask. It also contacts the addresses listed in `SECURITY.md`.
|
|
8
|
+
- Your AI app (for example Claude) sees the data the tool returns, under that app's own terms.
|
|
9
|
+
|
|
10
|
+
## The shared login service (optional)
|
|
11
|
+
The service lets you log in with Snapchat without creating your own Snapchat app. It is a small, stateless program (`broker/worker.js`, running on Cloudflare Workers).
|
|
12
|
+
|
|
13
|
+
**What it does**
|
|
14
|
+
- At login, Snapchat sends it a one-time code. It exchanges that code, using the shared app's secret, for your refresh token.
|
|
15
|
+
- It immediately **seals** that token to a key that only your computer holds, and sends it to your own computer (an address starting with `http://127.0.0.1`, which is your machine). After that it cannot read it again.
|
|
16
|
+
- Later, your computer sends its refresh token to the service to get a short-lived access token, because that step needs the app's secret.
|
|
17
|
+
|
|
18
|
+
**What it does not do**
|
|
19
|
+
- It stores **no** tokens, no ad account data, no names, emails or IP addresses. It has no database and writes no logs of its own (a test checks the code uses no storage and no logging).
|
|
20
|
+
- It cannot read your ad account: your computer talks to Snapchat directly.
|
|
21
|
+
- It does not sell, share or analyze anything.
|
|
22
|
+
|
|
23
|
+
**Good to know**
|
|
24
|
+
- While a request is being handled the service holds your refresh token in memory, as it must. Its hosting provider (Cloudflare) may keep standard request metadata under its own terms.
|
|
25
|
+
- If you prefer, skip the shared login and use your own Snapchat OAuth app (see the README). You can also run your own copy of the service (`broker/README.md`).
|
|
26
|
+
- To stop access: revoke the app in Snapchat Business Manager and delete your settings file.
|
|
27
|
+
|
|
28
|
+
This is an unofficial project and is not affiliated with or endorsed by Snap Inc.
|
package/README.md
CHANGED
|
@@ -17,13 +17,18 @@ A local [MCP](https://modelcontextprotocol.io) server that lets an AI assistant
|
|
|
17
17
|
- Data that comes back from the API (names, review reasons) is shown to your AI assistant. Treat it as untrusted input, and keep your client's approval prompt on for write tools.
|
|
18
18
|
|
|
19
19
|
## Ad formats
|
|
20
|
+
- **Goals for link ads**: `snap_create_adsquad` takes `goal`: purchase, add to cart, page view or sign-up (need a pixel), or traffic (SWIPES), awareness (IMPRESSIONS) and video views (no pixel needed). App installs and lead generation are not built.
|
|
20
21
|
- **Single Snap with a link** (WEB_VIEW): `snap_create_creative`, then `snap_create_ad`.
|
|
21
22
|
- **Single Snap, no link** (image or video): `snap_create_creative` with `creative_type: "SNAP_AD"`.
|
|
22
23
|
- **Story Ad**: create the Snaps first (any of the two above), then `snap_create_story_creative` with their ids in order. Add `preview` (a 3:5 PNG tile, at least 360x600 px, and a headline of up to 55 characters) to also show it in the Stories tab.
|
|
24
|
+
- **Catalog ad (Dynamic Product Ads)**: `snap_create_campaign` with `catalog_id` (SALES objective), then `snap_create_product_set` (and `snap_create_dynamic_template` if you have none), then `snap_create_adsquad` with `product_set_id` and `dpa_mode` (retargeting: viewed or added to cart but did not buy; prospecting: has not interacted), then `snap_create_creative` with `creative_type: "DYNAMIC_PRODUCT"`, then `snap_create_ad`. The ad squad and the creative must use the same product set, which the tools check. The catalog and its product feed are set up in Ads Manager or Business Manager.
|
|
23
25
|
- **Collection Ad**: upload a main image or video and one **square** image per product (1:1, at least 120x120 px; checked in the preview), then `snap_create_collection_creative` with 4-20 products, each with its own https page.
|
|
24
26
|
|
|
25
27
|
In every case `snap_create_ad` picks the matching ad type (REMOTE_WEBPAGE, SNAP_AD, STORY or COLLECTION) and the ad starts PAUSED. Creatives never deliver on their own. Find media already in the account with `snap_list_media`, or upload with `snap_upload_media` and wait until `snap_get_media` says READY.
|
|
26
28
|
|
|
29
|
+
## Easiest: log in with Snapchat (no OAuth app)
|
|
30
|
+
When a login service is available (see `broker/README.md` and `PRIVACY.md`), you do not need to create a Snapchat OAuth app. Run `npx -y ads-mcp-for-snapchat setup` and choose **1. Shared login**, or install the Claude Desktop file, leave Client ID and secret empty, and ask Claude: "Connect my Snapchat ad account." You log in with Snapchat in your browser and pick your ad account. The service only passes your login along: it stores nothing, and your access is sealed so only your own computer can read it. Prefer to stay independent? Use your own app (next section), or run your own copy of the service.
|
|
31
|
+
|
|
27
32
|
## Easy setup (about 5 minutes)
|
|
28
33
|
First, once: in [Snap Business Manager](https://business.snapchat.com) open **Business Details > OAuth Apps > + OAuth App**, use the Redirect URI `https://127.0.0.1/callback`, and copy the **Client ID** and **Client Secret** (the secret is shown only once).
|
|
29
34
|
|
|
@@ -81,6 +86,10 @@ With this setting the server asks **you**, through the MCP client's own dialog (
|
|
|
81
86
|
| `SNAP_MAX_ADDED_DAILY_BUDGET_24H` | 2 x the line above | Most daily budget this server may add to the account in any 24 hours, all tools together: budgets it starts plus budget increases |
|
|
82
87
|
| `SNAP_ACCOUNT_CURRENCY` | not set | If set (e.g. `USD`), writes are refused unless the ad account uses that currency |
|
|
83
88
|
| `SNAP_READ_ONLY` | 0 | `1` = previews and reads only |
|
|
89
|
+
| `SNAP_BROKER_URL` | (none) | The shared login service: connect with a normal Snapchat login and no OAuth app. https only. A refresh token is sent there, so use only a service you trust (see `PRIVACY.md`, `broker/README.md`). `setup` saves it for you. |
|
|
90
|
+
| `SNAP_HOME` | `~/.ads-mcp-for-snapchat` for an npm install, the project folder for a git checkout | Where the settings file, the change log and `exports/` live. Set it to keep them somewhere else. |
|
|
91
|
+
| `SNAP_PORTFOLIO_FILES` | (none) | Absolute paths of the settings files of the accounts for `snap_portfolio_summary`, comma-separated (up to 10). Only you can set it: the AI app cannot pick files. |
|
|
92
|
+
| `SNAP_TOOLSETS` | all | Show only some tool groups to the AI app: `setup, read, reports, checks, changes, create` (comma-separated). Fewer tools make some apps faster and less error-prone, e.g. `setup,reports,checks` for an analyst. It only hides tools. |
|
|
84
93
|
| `SNAP_HUMAN_APPROVAL` | off | `elicit` = ask the user through the MCP client before every write |
|
|
85
94
|
| `SNAP_APPROVAL_TTL_SECONDS` | 600 | Lifetime of an approval token |
|
|
86
95
|
| `SNAP_REPEAT_WINDOW_SECONDS` | 600 | An identical create, copy, claim or upload is refused within this time |
|
|
@@ -95,6 +104,10 @@ Existing items above a limit can still be read, lowered and paused, but not rais
|
|
|
95
104
|
|
|
96
105
|
## Playbooks
|
|
97
106
|
Ready-made instructions in Claude's prompt menu (the "+" or "/" menu). They only read and preview; nothing is applied without your yes.
|
|
107
|
+
- **Budget review**: checks tracking first, then suggests at most 3 budget moves with previews.
|
|
108
|
+
- **Tracking check**: pixel, yesterday's purchases, Conversions API test events, Snap vs store revenue.
|
|
109
|
+
- **Competitor scan**: a competitor's ads from Snap's public Ads Gallery (Europe), and 3 ideas.
|
|
110
|
+
- **Fix rejected ads**: why Snap rejected each ad, and a proposed fix as a preview.
|
|
98
111
|
- **Weekly review**: last 7 days vs the 7 before, problems, tired ads, pacing, and up to 5 actions.
|
|
99
112
|
- **Launch checklist**: before turning on a paused campaign or ad squad: audience size, pixel, budget, creatives, review status, preview links. PASS / WARN / FAIL per item.
|
|
100
113
|
- **Replace tired ads**: finds wearing-out ads in a campaign and drafts paused replacements from new media.
|
|
@@ -106,6 +119,27 @@ Ready-made instructions in Claude's prompt menu (the "+" or "/" menu). They only
|
|
|
106
119
|
| `snap_audience_size` | read: Snap's reach estimate for an ad squad or for targeting you are planning, with a verdict (very small / small / OK / very broad) |
|
|
107
120
|
| `snap_spend_pacing` | read: today's spend per active ad squad vs its budget for this time of day, month-to-date spend, projected month and, with a monthly budget, over / under |
|
|
108
121
|
| `snap_ad_preview` | read: a no-login preview link (90 days) and a Snapcode to scan on a phone (7 days) |
|
|
122
|
+
| `snap_list_dynamic_templates` | read: the ad account's dynamic templates (product layouts for catalog ads) |
|
|
123
|
+
| `snap_create_product_set`, `snap_create_dynamic_template` | write (preview + approval): a filtered group of catalog products; a product layout |
|
|
124
|
+
| `snap_check_landing_pages` | read: opens each active ad's link once (https only, never private addresses) and flags broken, slow, server-error and non-https links, links that end on another site, and links missing parameters you name |
|
|
125
|
+
| `snap_anomaly_check` | read: yesterday vs the usual day: spend spike or drop, zero or falling purchases (possible broken pixel), ROAS drop, cost-per-purchase spike |
|
|
126
|
+
| `snap_blended_roas` | read: Snap's reported revenue vs the revenue your store confirms (you give the store figure): overstates, understates or consistent |
|
|
127
|
+
| `snap_audience_insights` | read: who is in an audience (age, gender, languages, interests, devices) compared with everyone in the same countries, with an index |
|
|
128
|
+
| `snap_competitor_ads` | read: a company's ads from Snap's public Ads Gallery (no login, nothing about your account sent; Europe only) |
|
|
129
|
+
| `snap_capi_status`, `snap_capi_test_event` | Conversions API TEST events only: read the last test events and their errors; send one test event (previewed, email hashed). No tool sends real conversion events. |
|
|
130
|
+
| `snap_set_frequency_cap` | write (preview + approval): at most N impressions per person per N hours/days, or clear it |
|
|
131
|
+
| `snap_set_ad_schedule` | write (preview + approval): which hours of which days ads run; Snap allows it only on lifetime-budget ad squads |
|
|
132
|
+
| `snap_report_hourly` | read: spend, purchases and ROAS by local hour of the day (last 1-7 days), best and worst hours |
|
|
133
|
+
| `snap_creative_compare` | read: the ads of a campaign or ad squad ranked against the median ROAS (WINNER / LAGGING), grouped by call to action |
|
|
134
|
+
| `snap_budget_advice` | read: suggested daily-budget moves (lower the weak, raise the proven, funded by what is freed, inside your limits), each naming the tool that applies it |
|
|
135
|
+
| `snap_billing_check` | read: ad account status, funding sources (card expiry, daily limit vs budgets, credit left) and a verdict |
|
|
136
|
+
| `snap_unused_media` | read: uploaded images and videos no creative uses (never deletes) |
|
|
137
|
+
| `snap_audience_health` | read: audiences that are not targetable, tiny, stale, or unused by active ad squads |
|
|
138
|
+
| `snap_funnel` | read: impressions → swipes → views → add to cart → checkout → purchases with the rate at each step and the weakest step |
|
|
139
|
+
| `snap_catalog_feed_status` | read: for each catalog feed, the last completed upload, the latest upload's status and issues |
|
|
140
|
+
| `snap_set_bid_strategy` | write (preview + approval): switch an ad squad between max bid and target cost with a new bid, inside the bid limits. Switching TO auto-bid is not offered (it removes the bid cap). |
|
|
141
|
+
| `snap_set_placement` | write (preview + approval): automatic, or custom positions (Discover feed, Camera, Spotlight, Stories...). Undo works when a placement was set before. |
|
|
142
|
+
| `snap_portfolio_summary` | read: all your ad accounts side by side (yesterday and last 7 days, what needs attention, totals per currency). Reads the settings files you list in `SNAP_PORTFOLIO_FILES`; the AI app cannot choose files. |
|
|
109
143
|
| `snap_connect` | connect an ad account from inside the chat (link, pasted address, account choice); saves access on this computer, changes no ads |
|
|
110
144
|
| `snap_list_campaigns`, `snap_list_adsquads`, `snap_list_ads`, `snap_list_creatives`, `snap_get_entity`, `snap_get_media`, `snap_get_stats` | read |
|
|
111
145
|
| `snap_report` | read: ROAS, CPA, swipe rate, frequency by ad squad or ad |
|
|
@@ -230,7 +264,7 @@ Verified on the maintainer's own ad account. Anything not listed here is covered
|
|
|
230
264
|
|
|
231
265
|
**Before the safety layer (earlier tests, on throwaway paused objects):** pause/enable (single and bulk), budget, bid, targeting, schedule, bulk edits, campaign / ad squad copy, ad and creative clone, create campaign and ad squad, lookalike and pixel audiences, customer-list audience (with fake data), influencer flow and batch, media upload (simple and chunked), async reports, health check, review issues, pixel health, and the guarded delete (on a throwaway campaign).
|
|
232
266
|
|
|
233
|
-
**Not verified live:** `snap_audience_size`, `snap_spend_pacing` and
|
|
267
|
+
**Not verified live:** everything added in 0.6.0 and 0.7.0 (`snap_audience_size`, `snap_spend_pacing`, `snap_ad_preview`; catalog ads; bid-strategy switching, placement and the portfolio summary; the landing page, anomaly, blended ROAS, audience insights, competitor ads, Conversions API test, hourly, creative comparison, budget advice, billing, unused media, audience health, funnel and feed tools; frequency cap and ad schedule; the new ad squad goals), all built from Snap's documentation and mocked tests, the 24-hour spend limit and absolute limits on real writes (mocked tests only), `SNAP_HUMAN_APPROVAL=elicit` in Claude Code, `snap_create_creative` with a WEB_VIEW link, a campaign-level `snap_set_daily_budget`, a successful `snap_delete` of an ad squad, ad or audience, a customer-list upload of real data, and Node 18 / 20 outside CI.
|
|
234
268
|
|
|
235
269
|
## Not built
|
|
236
270
|
- A hosted multi-user version (this server runs on your own machine with your own credentials).
|
package/SECURITY.md
CHANGED
|
@@ -13,5 +13,18 @@ Supported version: the latest release on `main`. This is a small, unofficial pro
|
|
|
13
13
|
- Rotate the client secret whenever it may have been seen outside your machine (pasted in a chat, a screenshot, a shared terminal): create a new secret in Snap Ads Manager, run `node scripts/save-secret.js`, then authorize again with `scripts/get-refresh-token.js`. The old secret and refresh token stop working.
|
|
14
14
|
- Anything that can read `.env` holds the full API credentials and bypasses every guard in this server. Deny your AI client's file tools access to `.env` and `changes.log.jsonl`.
|
|
15
15
|
|
|
16
|
+
## What this server connects to
|
|
17
|
+
Everything runs on your computer. These are the only outside addresses it contacts:
|
|
18
|
+
|
|
19
|
+
| Address | What for | What is sent |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `adsapi.snapchat.com`, `accounts.snapchat.com` | The Snapchat Marketing API and login | Your requests, with your access token |
|
|
22
|
+
| `tr.snapchat.com` | Conversions API **test** events and their status (`snap_capi_*`) | Your access token and one test event; an email is hashed first. Real conversion events are never sent. |
|
|
23
|
+
| `adsapi.snapchat.com/v1/ads_library/...` | Competitor ads (`snap_competitor_ads`) | The advertiser name you search for. **No token**, nothing about your account. |
|
|
24
|
+
| The links of your own active ads | `snap_check_landing_pages` opens each link once | A plain request. Only `https`, never private, loopback or link-local addresses, and every redirect is checked again. No credentials. |
|
|
25
|
+
| The shared login service (`SNAP_BROKER_URL`), only if you chose the shared login | Logging in, and renewing the 30-minute access token | Your refresh token (it must, to renew). It stores nothing; see `PRIVACY.md`. Only use a service you trust. |
|
|
26
|
+
|
|
27
|
+
Text that comes back from outside (competitors' ads, page contents, ad review reasons) is untrusted data: it is cut, marked as such in the answer, and must not be followed as instructions. `SNAP_PORTFOLIO_FILES` can only be set by you in your own settings; the AI app cannot choose which files are read. The audit log removes credentials, emails and phone numbers from logged arguments.
|
|
28
|
+
|
|
16
29
|
## Safety design
|
|
17
30
|
Write tools need the approval token of a preview of the exact same request, create objects paused, enforce absolute and relative money limits that fail closed, only touch the configured ad account, and record every write in an audit log. The approval token is not a human signature: keep your MCP client's permission prompt on for write tools (see README, "What the approval token is not"). This tool edits real campaigns: review each preview before approving.
|
package/broker/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Login service (optional)
|
|
2
|
+
|
|
3
|
+
A small, **stateless** Cloudflare Worker that lets people connect their Snapchat ad account with a normal "log in with Snapchat" click, without creating their own Snapchat OAuth app. It holds one shared app's secret and nothing else: no tokens, no accounts, no logs. See `../PRIVACY.md`.
|
|
4
|
+
|
|
5
|
+
You only need this folder if you want to **run the login service** (the maintainer does this once, for everyone). Normal users never touch it.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
1. `npx ads-mcp-for-snapchat setup` (or the Claude Desktop extension) makes a one-time key pair on the user's computer and opens `https://<service>/login?port=...&pk=<public key>&nonce=...`.
|
|
9
|
+
2. The service sends the browser to Snapchat's login with a **signed** state (no storage needed) and a cookie that ties the login to that browser.
|
|
10
|
+
3. Snapchat sends the browser back to `/callback`. The service checks the signature, expiry and cookie, exchanges the code (using the secret) for a refresh token, **seals it to the user's public key**, and redirects the browser to `http://127.0.0.1:<port>/callback` on the user's own machine. The service keeps nothing.
|
|
11
|
+
4. Later the computer sends its refresh token to `POST /v1/refresh` to get a 30-minute access token, because that needs the secret.
|
|
12
|
+
|
|
13
|
+
## Deploy (about 20 minutes)
|
|
14
|
+
You need a free Cloudflare account and a Snapchat Business Manager login.
|
|
15
|
+
|
|
16
|
+
1. Install the tool and sign in: `npm install -g wrangler`, then `wrangler login`.
|
|
17
|
+
2. Deploy once to learn the address: `cd broker && wrangler deploy`. It prints something like `https://ads-mcp-for-snapchat-login.<you>.workers.dev`. (Or attach your own domain in the Cloudflare dashboard.)
|
|
18
|
+
3. In Snap Business Manager open **Business Details > OAuth Apps > + OAuth App**. Name it "Ads MCP for Snapchat". Set the **Redirect URI** to `https://<your address>/callback` exactly. Copy the Client ID and Client Secret.
|
|
19
|
+
4. Store the three secrets (they are never put in files):
|
|
20
|
+
```
|
|
21
|
+
wrangler secret put SNAP_CLIENT_ID
|
|
22
|
+
wrangler secret put SNAP_CLIENT_SECRET
|
|
23
|
+
wrangler secret put STATE_KEY
|
|
24
|
+
```
|
|
25
|
+
For `STATE_KEY` paste any random text of 32+ characters, for example the output of `openssl rand -base64 48`.
|
|
26
|
+
5. Check it: open `https://<your address>/` (a short home page) and `/privacy`. Then on your own computer run:
|
|
27
|
+
```
|
|
28
|
+
SNAP_BROKER_URL=https://<your address> npx -y ads-mcp-for-snapchat setup
|
|
29
|
+
```
|
|
30
|
+
Choose option 1 (shared login). It should open Snapchat's login, then say Connected.
|
|
31
|
+
6. Make it the default for everyone: put the address in `package.json` as `"adsMcpBroker": "https://<your address>"`, then release a new version.
|
|
32
|
+
|
|
33
|
+
## Before you tell other people about it
|
|
34
|
+
- **Ask Snap** whether an OAuth app may connect advertisers other than your own company, and whether the app needs review. Snap's rules decide this, not this code. Give them the privacy page address.
|
|
35
|
+
- **Add rate limits** in the Cloudflare dashboard (Security > WAF > Rate limiting): for example 30 requests per minute per IP for `/login` and `/v1/refresh`.
|
|
36
|
+
- **Know what you are running.** The service briefly holds each user's refresh token in memory while it handles a request. If its secrets leak, an attacker could use the shared app, so keep them in Cloudflare secrets only and rotate them if in doubt.
|
|
37
|
+
- If the service is down, shared-login users cannot renew their 30-minute access tokens until it is back. People with their own app are unaffected.
|
|
38
|
+
|
|
39
|
+
## Run your own copy
|
|
40
|
+
The same code works with your own Snapchat app: deploy it as above and give your users `SNAP_BROKER_URL=https://<your address>`. Only point `SNAP_BROKER_URL` at a service you trust: a refresh token is sent there.
|
|
41
|
+
|
|
42
|
+
## What is tested
|
|
43
|
+
`npm test` runs the real Worker code against a fake Snapchat: the state signature (tampered, expired, other key, other browser), the loopback-only redirect, sealing (only the user's key opens it), that no plaintext token or secret is ever in a redirect or an error, that nothing is logged or stored, and the whole login end to end. The Worker was also run in Cloudflare's own local runtime (`wrangler dev`): a token sealed there opens on a computer running Node, and forged or invalid requests are refused. It has **not** been run against the real Snapchat login: do step 5 above before announcing it.
|
package/broker/worker.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Login service for "Ads MCP for Snapchat": a small, STATELESS Cloudflare Worker. It lets people connect their Snapchat ad
|
|
2
|
+
// account with a normal "log in with Snapchat" click, without making their own Snapchat OAuth app. It holds the shared app's
|
|
3
|
+
// secret and nothing else: it stores no tokens, no accounts and no logs. See broker/README.md and PRIVACY.md.
|
|
4
|
+
//
|
|
5
|
+
// GET /login?port=&pk=&nonce= the person's computer starts a login (loopback port, a public key made for this login)
|
|
6
|
+
// GET /callback?code=&state= Snapchat sends the person back here; the refresh token is sealed to their key and handed to
|
|
7
|
+
// their own computer (http://127.0.0.1:<port>/callback). Nothing is kept.
|
|
8
|
+
// POST /v1/refresh their computer swaps its refresh token for a short-lived access token (needs the secret)
|
|
9
|
+
//
|
|
10
|
+
// Settings (Worker secrets and variables): SNAP_CLIENT_ID, SNAP_CLIENT_SECRET, STATE_KEY (random text, 32+ characters).
|
|
11
|
+
import { checkPublicKey, fromB64u, seal, toB64u } from "../src/hybrid.js";
|
|
12
|
+
|
|
13
|
+
const AUTHORIZE = "https://accounts.snapchat.com/login/oauth2/authorize";
|
|
14
|
+
const TOKEN = "https://accounts.snapchat.com/login/oauth2/access_token";
|
|
15
|
+
const STATE_MINUTES = 10;
|
|
16
|
+
const COOKIE = "ads_mcp_login";
|
|
17
|
+
const MAX_BODY = 8 * 1024;
|
|
18
|
+
const enc = new TextEncoder();
|
|
19
|
+
|
|
20
|
+
const SECURITY_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'" };
|
|
21
|
+
|
|
22
|
+
const page = (title, body, status = 200, extra = {}) =>
|
|
23
|
+
new Response(`<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${title}</title><style>body{font:16px/1.5 system-ui,sans-serif;max-width:40rem;margin:3rem auto;padding:0 1rem;color:#1a1a1a}code{background:#f2f2f2;padding:.1rem .3rem;border-radius:4px}</style><body>${body}</body></html>`, { status, headers: { "Content-Type": "text/html; charset=utf-8", ...SECURITY_HEADERS, ...extra } });
|
|
24
|
+
|
|
25
|
+
const json = (obj, status = 200) => new Response(JSON.stringify(obj), { status, headers: { "Content-Type": "application/json", ...SECURITY_HEADERS } });
|
|
26
|
+
const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
27
|
+
|
|
28
|
+
// ---------- state: signed, so the service needs no storage ----------
|
|
29
|
+
|
|
30
|
+
async function hmacKey(env) {
|
|
31
|
+
if (!env.STATE_KEY || String(env.STATE_KEY).length < 32) throw new Error("STATE_KEY is missing or too short");
|
|
32
|
+
return crypto.subtle.importKey("raw", enc.encode(env.STATE_KEY), { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function signState(env, payload) {
|
|
36
|
+
const body = toB64u(enc.encode(JSON.stringify(payload)));
|
|
37
|
+
const sig = new Uint8Array(await crypto.subtle.sign("HMAC", await hmacKey(env), enc.encode(body)));
|
|
38
|
+
return `${body}.${toB64u(sig)}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function readState(env, text, now = Date.now()) {
|
|
42
|
+
const [body, sig, extra] = String(text ?? "").split(".");
|
|
43
|
+
if (!body || !sig || extra !== undefined) return null;
|
|
44
|
+
let sigBytes;
|
|
45
|
+
try {
|
|
46
|
+
sigBytes = fromB64u(sig);
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (!(await crypto.subtle.verify("HMAC", await hmacKey(env), sigBytes, enc.encode(body)))) return null;
|
|
51
|
+
let payload;
|
|
52
|
+
try {
|
|
53
|
+
payload = JSON.parse(new TextDecoder().decode(fromB64u(body)));
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (!payload || typeof payload.e !== "number" || payload.e < now) return null;
|
|
58
|
+
return payload;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const validPort = (p) => /^\d{4,5}$/.test(p) && Number(p) >= 1024 && Number(p) <= 65535;
|
|
62
|
+
const validNonce = (n) => /^[A-Za-z0-9_-]{16,64}$/.test(n ?? "");
|
|
63
|
+
const origin = (request, env) => (env.PUBLIC_URL ? String(env.PUBLIC_URL).replace(/\/+$/, "") : new URL(request.url).origin);
|
|
64
|
+
const getCookie = (request, name) => (request.headers.get("Cookie") ?? "").split(";").map((c) => c.trim().split("=")).find(([k]) => k === name)?.[1];
|
|
65
|
+
|
|
66
|
+
function need(env, ...keys) {
|
|
67
|
+
for (const k of keys) if (!env[k]) throw new Error(`${k} is not set`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ---------- routes ----------
|
|
71
|
+
|
|
72
|
+
async function login(request, env) {
|
|
73
|
+
need(env, "SNAP_CLIENT_ID", "SNAP_CLIENT_SECRET", "STATE_KEY");
|
|
74
|
+
const u = new URL(request.url);
|
|
75
|
+
const port = u.searchParams.get("port");
|
|
76
|
+
const pk = u.searchParams.get("pk");
|
|
77
|
+
const nonce = u.searchParams.get("nonce");
|
|
78
|
+
if (!validPort(port) || !checkPublicKey(pk) || !validNonce(nonce)) return page("Cannot start", "<h1>Cannot start the login</h1><p>The link is not valid. Start again from the setup command or the Claude Desktop extension.</p>", 400);
|
|
79
|
+
const state = await signState(env, { p: Number(port), k: pk, n: nonce, e: Date.now() + STATE_MINUTES * 60_000 });
|
|
80
|
+
const auth = new URL(AUTHORIZE);
|
|
81
|
+
auth.search = new URLSearchParams({ response_type: "code", client_id: env.SNAP_CLIENT_ID, redirect_uri: `${origin(request, env)}/callback`, scope: "snapchat-marketing-api", state }).toString();
|
|
82
|
+
return new Response(null, { status: 302, headers: { Location: auth.toString(), "Set-Cookie": `${COOKIE}=${nonce}; Path=/callback; Max-Age=${STATE_MINUTES * 60}; HttpOnly; Secure; SameSite=Lax`, ...SECURITY_HEADERS } });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function callback(request, env, fetchImpl) {
|
|
86
|
+
need(env, "SNAP_CLIENT_ID", "SNAP_CLIENT_SECRET", "STATE_KEY");
|
|
87
|
+
const u = new URL(request.url);
|
|
88
|
+
const clear = { "Set-Cookie": `${COOKIE}=; Path=/callback; Max-Age=0; HttpOnly; Secure; SameSite=Lax` };
|
|
89
|
+
const state = await readState(env, u.searchParams.get("state"));
|
|
90
|
+
if (!state || !state.k || !validPort(String(state.p)) || !validNonce(state.n) || getCookie(request, COOKIE) !== state.n) {
|
|
91
|
+
return page("Login expired", "<h1>This login link is not valid any more</h1><p>It may have expired, or it was opened in a different browser. Start again from the setup command.</p>", 400, clear);
|
|
92
|
+
}
|
|
93
|
+
if (u.searchParams.get("error")) return page("Login cancelled", "<h1>Snapchat did not approve the login</h1><p>Nothing was saved. You can close this tab and start again.</p>", 400, clear);
|
|
94
|
+
const code = u.searchParams.get("code");
|
|
95
|
+
if (!code || code.length > 2048) return page("Login failed", "<h1>No code came back from Snapchat</h1><p>Start again.</p>", 400, clear);
|
|
96
|
+
const res = await fetchImpl(TOKEN, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ grant_type: "authorization_code", code, redirect_uri: `${origin(request, env)}/callback`, client_id: env.SNAP_CLIENT_ID, client_secret: env.SNAP_CLIENT_SECRET }) });
|
|
97
|
+
const data = await res.json().catch(() => ({}));
|
|
98
|
+
if (!res.ok || !data.refresh_token) return page("Login failed", "<h1>Snapchat did not accept the login</h1><p>The code may have expired. Start again.</p>", 502, clear);
|
|
99
|
+
// The refresh token leaves here sealed to the key the person's own computer made for this login. It is not stored.
|
|
100
|
+
const sealed = await seal(state.k, data.refresh_token, state.n);
|
|
101
|
+
const back = new URL(`http://127.0.0.1:${state.p}/callback`);
|
|
102
|
+
back.search = new URLSearchParams({ nonce: state.n, epk: sealed.epk, salt: sealed.salt, iv: sealed.iv, ct: sealed.ct }).toString();
|
|
103
|
+
return new Response(null, { status: 302, headers: { Location: back.toString(), ...SECURITY_HEADERS, ...clear } });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function refresh(request, env, fetchImpl) {
|
|
107
|
+
need(env, "SNAP_CLIENT_ID", "SNAP_CLIENT_SECRET");
|
|
108
|
+
if (request.method !== "POST") return json({ error: "use POST" }, 405);
|
|
109
|
+
if (!/^application\/json\b/i.test(request.headers.get("Content-Type") ?? "")) return json({ error: "send JSON" }, 415);
|
|
110
|
+
const text = await request.text();
|
|
111
|
+
if (text.length > MAX_BODY) return json({ error: "request too large" }, 413);
|
|
112
|
+
let body;
|
|
113
|
+
try {
|
|
114
|
+
body = JSON.parse(text);
|
|
115
|
+
} catch {
|
|
116
|
+
return json({ error: "invalid JSON" }, 400);
|
|
117
|
+
}
|
|
118
|
+
const token = body?.refresh_token;
|
|
119
|
+
if (typeof token !== "string" || token.length < 10 || token.length > 4096 || /\s/.test(token)) return json({ error: "refresh_token is missing or invalid" }, 400);
|
|
120
|
+
const res = await fetchImpl(TOKEN, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ grant_type: "refresh_token", refresh_token: token, client_id: env.SNAP_CLIENT_ID, client_secret: env.SNAP_CLIENT_SECRET }) });
|
|
121
|
+
const data = await res.json().catch(() => ({}));
|
|
122
|
+
if (!res.ok || !data.access_token) {
|
|
123
|
+
// Only Snap's short reason goes back; never the secret or anything we sent.
|
|
124
|
+
const reason = String(data.error_description ?? data.error ?? "refused").slice(0, 200);
|
|
125
|
+
return json({ error: "snapchat_refused", reason }, res.status === 400 || res.status === 401 ? 401 : 502);
|
|
126
|
+
}
|
|
127
|
+
return json({ access_token: data.access_token, expires_in: data.expires_in ?? 1800, ...(data.refresh_token && data.refresh_token !== token ? { refresh_token: data.refresh_token } : {}) });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const HOME = `<h1>Ads MCP for Snapchat: login service</h1>
|
|
131
|
+
<p>This small service lets you connect your own Snapchat ad account to the open-source tool <a href="https://github.com/Usame794/snap-ads-mcp">Ads MCP for Snapchat</a> with a normal "log in with Snapchat" button, so you do not have to create your own Snapchat app.</p>
|
|
132
|
+
<p><strong>It stores nothing.</strong> Your access is sealed so that only your own computer can read it. See the <a href="/privacy">privacy page</a>. This is an unofficial project and is not affiliated with Snap Inc.</p>`;
|
|
133
|
+
|
|
134
|
+
const PRIVACY = `<h1>Privacy</h1>
|
|
135
|
+
<p>This login service is part of the open-source tool Ads MCP for Snapchat. The tool itself runs on your computer.</p>
|
|
136
|
+
<h2>What this service does</h2>
|
|
137
|
+
<ul>
|
|
138
|
+
<li>When you log in, it receives a one-time code from Snapchat and exchanges it, using the shared app's secret, for your refresh token.</li>
|
|
139
|
+
<li>It immediately <strong>seals</strong> that token to a key that only your computer holds, and sends it to your computer (an address that starts with <code>http://127.0.0.1</code>, which is your own machine).</li>
|
|
140
|
+
<li>Later, your computer sends its refresh token to this service to get a short-lived access token, because that step needs the app's secret.</li>
|
|
141
|
+
</ul>
|
|
142
|
+
<h2>What it does not do</h2>
|
|
143
|
+
<ul>
|
|
144
|
+
<li>It does <strong>not store</strong> tokens, ad account data, names, emails or IP addresses, and it keeps no database and no logs of its own.</li>
|
|
145
|
+
<li>It cannot read your ad account data: your computer talks to Snapchat directly.</li>
|
|
146
|
+
<li>It does not sell, share or analyze anything.</li>
|
|
147
|
+
</ul>
|
|
148
|
+
<h2>Good to know</h2>
|
|
149
|
+
<ul>
|
|
150
|
+
<li>While a request is being handled the service briefly holds your refresh token in memory, as it must. The hosting provider (Cloudflare) may keep standard request metadata under its own terms.</li>
|
|
151
|
+
<li>You can revoke access at any time in Snapchat (Business Manager > Business Details > OAuth Apps / connected apps) and by deleting your settings file.</li>
|
|
152
|
+
<li>You can run your own copy of this service with your own Snapchat app: the code is in the <code>broker</code> folder of the repository.</li>
|
|
153
|
+
</ul>`;
|
|
154
|
+
|
|
155
|
+
export default {
|
|
156
|
+
async fetch(request, env, _ctx, fetchImpl = fetch) {
|
|
157
|
+
try {
|
|
158
|
+
const { pathname } = new URL(request.url);
|
|
159
|
+
if (pathname === "/" && request.method === "GET") return page("Ads MCP for Snapchat", HOME);
|
|
160
|
+
if (pathname === "/privacy" && request.method === "GET") return page("Privacy", PRIVACY);
|
|
161
|
+
if (pathname === "/login" && request.method === "GET") return await login(request, env);
|
|
162
|
+
if (pathname === "/callback" && request.method === "GET") return await callback(request, env, fetchImpl);
|
|
163
|
+
if (pathname === "/v1/refresh") return await refresh(request, env, fetchImpl);
|
|
164
|
+
return page("Not found", "<h1>Not found</h1>", 404);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
// A generic answer: the reason may name a setting, never a value, and nothing about the request is logged.
|
|
167
|
+
const setting = /^(\w+) is (missing|not set)/.exec(e?.message ?? "")?.[1];
|
|
168
|
+
return page("Not available", `<h1>The login service is not set up correctly</h1>${setting ? `<p>Missing setting: <code>${esc(setting)}</code></p>` : ""}`, 503);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Cloudflare Worker settings for the login service. See broker/README.md.
|
|
2
|
+
name = "ads-mcp-for-snapchat-login"
|
|
3
|
+
main = "worker.js"
|
|
4
|
+
compatibility_date = "2025-01-01"
|
|
5
|
+
|
|
6
|
+
# Set these as secrets, never in this file:
|
|
7
|
+
# wrangler secret put SNAP_CLIENT_ID
|
|
8
|
+
# wrangler secret put SNAP_CLIENT_SECRET
|
|
9
|
+
# wrangler secret put STATE_KEY (any random text of 32+ characters)
|
|
10
|
+
# Optional: PUBLIC_URL, if the address people reach is not the Worker's own origin.
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ads-mcp-for-snapchat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Unofficial local MCP server for the Snapchat Marketing API: reports, audits and safe, previewed changes to campaigns, ad squads and ads.",
|
|
5
5
|
"mcpName": "io.github.Usame794/ads-mcp-for-snapchat",
|
|
6
|
+
"adsMcpBroker": "",
|
|
6
7
|
"type": "module",
|
|
7
8
|
"main": "src/index.js",
|
|
8
9
|
"bin": {
|
|
@@ -52,6 +53,8 @@
|
|
|
52
53
|
"SECURITY.md",
|
|
53
54
|
"LICENSE",
|
|
54
55
|
".env.example",
|
|
55
|
-
"CHANGELOG.md"
|
|
56
|
+
"CHANGELOG.md",
|
|
57
|
+
"broker",
|
|
58
|
+
"PRIVACY.md"
|
|
56
59
|
]
|
|
57
60
|
}
|