ads-mcp-for-snapchat 0.0.0-stage → 0.4.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 +27 -0
- package/ARCHITECTURE.md +40 -0
- package/CHANGELOG.md +82 -0
- package/LICENSE +21 -0
- package/README.md +222 -2
- package/SECURITY.md +17 -0
- package/package.json +54 -4
- package/scripts/check.js +20 -0
- package/scripts/get-refresh-token.js +32 -0
- package/scripts/save-secret.js +22 -0
- package/scripts/weekly-report.js +78 -0
- package/src/activation.js +95 -0
- package/src/approval.js +119 -0
- package/src/async-report.js +56 -0
- package/src/audit-log.js +139 -0
- package/src/audit.js +150 -0
- package/src/bulk-edit.js +66 -0
- package/src/bulk.js +79 -0
- package/src/changes.js +307 -0
- package/src/cli.js +73 -0
- package/src/clipboard.js +45 -0
- package/src/clone-ad.js +69 -0
- package/src/copy.js +145 -0
- package/src/create.js +167 -0
- package/src/creative-tools.js +44 -0
- package/src/customer-list.js +106 -0
- package/src/delete.js +73 -0
- package/src/env.js +52 -0
- package/src/fatigue.js +52 -0
- package/src/formats.js +112 -0
- package/src/index.js +24 -0
- package/src/influencer-batch.js +35 -0
- package/src/influencer.js +90 -0
- package/src/ownership.js +42 -0
- package/src/policy.js +154 -0
- package/src/readers.js +111 -0
- package/src/report.js +155 -0
- package/src/snap.js +287 -0
- package/src/tools.js +1207 -0
package/.env.example
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Snapchat Marketing API OAuth app (create it in Snap Business Manager > Business Details > OAuth Apps)
|
|
2
|
+
SNAP_CLIENT_ID=
|
|
3
|
+
SNAP_CLIENT_SECRET=
|
|
4
|
+
# Refresh token from the one-time authorization (see README)
|
|
5
|
+
SNAP_REFRESH_TOKEN=
|
|
6
|
+
# Default ad account id (find it in Ads Manager or via the snap_ping tool)
|
|
7
|
+
SNAP_AD_ACCOUNT_ID=
|
|
8
|
+
# Safety limits (optional; plain numbers in account currency; an invalid value stops the server; restart to apply)
|
|
9
|
+
SNAP_MAX_DAILY_BUDGET=1000
|
|
10
|
+
SNAP_MIN_DAILY_BUDGET=5
|
|
11
|
+
SNAP_MAX_BID=50
|
|
12
|
+
SNAP_MAX_BUDGET_INCREASE_PCT=100
|
|
13
|
+
SNAP_MAX_BID_INCREASE_PCT=50
|
|
14
|
+
# Market settings (no hidden defaults: leave unset to always pass countries explicitly)
|
|
15
|
+
SNAP_DEFAULT_COUNTRY=
|
|
16
|
+
SNAP_DEFAULT_PHONE_CODE=
|
|
17
|
+
SNAP_REPORT_UTC_OFFSET=+00:00
|
|
18
|
+
# Optional: where the change/audit log goes (default: changes.log.jsonl, or <SNAP_ENV_FILE>.log.jsonl when that is set)
|
|
19
|
+
# SNAP_LOG_FILE=
|
|
20
|
+
# Optional: SNAP_MAX_LIFETIME_BUDGET, SNAP_MAX_ACTIVATION_DAILY_BUDGET, SNAP_MAX_ADDED_DAILY_BUDGET_24H, SNAP_ACCOUNT_CURRENCY=USD,
|
|
21
|
+
# SNAP_READ_ONLY=1, SNAP_HUMAN_APPROVAL=elicit (see README "Safety settings")
|
|
22
|
+
# Only needed once, by scripts/get-refresh-token.js (must match the redirect URL on your OAuth app)
|
|
23
|
+
SNAP_REDIRECT_URI=https://127.0.0.1/callback
|
|
24
|
+
# Brand profile id (only needed to claim creator ad codes)
|
|
25
|
+
SNAP_BRAND_PROFILE_ID=
|
|
26
|
+
# Default pixel id for new ad squads
|
|
27
|
+
SNAP_PIXEL_ID=
|
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Architecture and design notes
|
|
2
|
+
|
|
3
|
+
For contributors. Unofficial local MCP server (Node ESM, stdio) for the Snapchat Marketing API: 58 tools, all tests mocked (`npm test`). Read `README.md` first for setup and the tool table.
|
|
4
|
+
|
|
5
|
+
## Architecture (src/)
|
|
6
|
+
- `cli.js`: npm command (`npx ads-mcp-for-snapchat`): no command starts the server; `init`, `where`, `save-secret`, `auth`, `check`, `weekly-report` run the setup scripts. `index.js`: MCP server entry. `tools.js`: all 58 tool definitions (zod schemas, handlers).
|
|
7
|
+
- `snap.js`: `SnapClient` (token refresh, retry), `ENTITIES` (campaign, adsquad, ad, creative, media, segment), sanitize-for-create/update helpers, `createEntity/updateEntity/getEntity/listChildren`, `upload`.
|
|
8
|
+
- `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.
|
|
9
|
+
- `changes.js`: plan functions (status, budget, exclusions, rename, bid, targeting, schedule), `applyChange` (logs before/after), `containsDeep`, `planUndo`.
|
|
10
|
+
- Feature modules: `formats.js` (SNAP_AD, Story and Collection builders, ad type per creative type, CTA list), `copy.js`, `clone-ad.js`, `bulk.js`, `bulk-edit.js`, `influencer.js`, `influencer-batch.js`, `create.js`, `creative-tools.js`, `readers.js`, `report.js`, `async-report.js`, `audit.js`, `fatigue.js`, `customer-list.js`, `delete.js`.
|
|
11
|
+
- `policy.js` (limits and market settings, validated at startup), `approval.js`, `ownership.js`, `activation.js`, `audit-log.js` (see "Safety design").
|
|
12
|
+
- `scripts/`: `check.js`, `get-refresh-token.js`, `save-secret.js` (clipboard or `--stdin`, via `src/clipboard.js`), `smoke.js` (9 live read checks), `live-create-creative.js`, `weekly-report.js`.
|
|
13
|
+
|
|
14
|
+
## Safety design (keep it)
|
|
15
|
+
- Writes go through one path in `tools.js` (`write`): preview with a single-use `approval_token` (`approval.js`), ownership check (`ownership.js`), audit intent/result (`audit-log.js`). `confirm=true` without the token of that exact preview sends nothing.
|
|
16
|
+
- Everything created is PAUSED. Status is only ACTIVE or PAUSED.
|
|
17
|
+
- Limits live in `policy.js`, validated at startup (invalid = server does not start): absolute daily budget / bid / lifetime / activation ceilings, +100% budget and +50% bid per step and per 24h, minimum daily budget. 20 items per bulk action (fixed).
|
|
18
|
+
- Each change is read back and verified (`containsDeep` compares only changed fields), then appended to `changes.log.jsonl` with before/after so `snap_undo` works (it refuses if the object changed again).
|
|
19
|
+
- Multi-step flows stop at the first failure. `snap_delete` is guarded: paused, no spend in 30 days, no active children, exact name typed.
|
|
20
|
+
- Reads retry on 429/5xx/network with backoff. Writes retry only on 429, so a create or claim is never repeated.
|
|
21
|
+
|
|
22
|
+
## Snap API quirks learned the hard way
|
|
23
|
+
- OAuth redirect URI must be https (`https://127.0.0.1/callback`); `localhost` is rejected. The client secret is shown once.
|
|
24
|
+
- `claim_media_by_ad_code`: `ad_code` and `profile_id` go as QUERY params (a JSON body gives a 500). Ad codes are single-use and one-way; expired codes are not consumed.
|
|
25
|
+
- Reading ad squads needs `return_placement_v2=true` if you plan to re-create them. `catalog_vertical` must be stripped on create. Keep `render_type` for ads. A creative's product set must match the ad squad's.
|
|
26
|
+
- Breakdown stats are paged: follow `paging.next_link` (`collectBreakdown`). `report_dimension` values: country, gender, age, region, dma, make. Conversion fields do not work with `dimension=`.
|
|
27
|
+
- Chunked media upload: INIT/ADD/FINALIZE, 30 MiB chunks, up to 1 GB.
|
|
28
|
+
- Snap's default attribution (1-day view) overstates results vs last-click store data. Use Snap numbers to compare trends, not as revenue.
|
|
29
|
+
|
|
30
|
+
## Not built
|
|
31
|
+
- Hosted multi-user version (needs per-user OAuth, encrypted token storage, abuse protection). Not planned in this repository.
|
|
32
|
+
- Non-WEB_VIEW creatives (Collection, Story, video formats), product set creation, position-level reports, lifetime / reach-and-frequency budgets, custom location targeting.
|
|
33
|
+
- Not run live on their own: `snap_create_creative`, `snap_create_ad` (ran inside the influencer flow), campaign-level `snap_set_daily_budget`, a successful `snap_delete` of an ad squad / ad / audience, real-data customer-list upload.
|
|
34
|
+
|
|
35
|
+
## Working rules for contributors
|
|
36
|
+
- Run `npm test` after every change. Run `npm run smoke` (needs real credentials) after touching the API client.
|
|
37
|
+
- Never commit `.env`, `changes.log.jsonl`, or `exports/`. Never print secrets or paste them into chat.
|
|
38
|
+
- Test live changes only on paused throwaway objects, and clean them up in Ads Manager.
|
|
39
|
+
- Keep identifiers (account, pixel, profile IDs, ad codes) and anything specific to one market or one business out of committed files and tests.
|
|
40
|
+
- A new write tool must go through `write` in `src/tools.js`, so it gets the preview/approval, ownership check, spend limits and audit trail. `test/safety-tools.test.js` fails if a mutating tool bypasses them.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.0 (2026-11-14)
|
|
4
|
+
|
|
5
|
+
- Install from npm: `npx -y ads-mcp-for-snapchat` starts the server. `init`, `where`, `save-secret`, `auth`, `check` and `weekly-report` replace `node scripts/...` for installed copies; `help` lists them.
|
|
6
|
+
- An installed copy keeps its settings, change log and exports in `~/.ads-mcp-for-snapchat` (or `SNAP_HOME`), never inside `node_modules`, so an update cannot erase them. A git checkout works exactly as before.
|
|
7
|
+
- `server.json` for the official MCP Registry (`io.github.Usame794/ads-mcp-for-snapchat`).
|
|
8
|
+
- The repository is now `Usame794/ads-mcp-for-snapchat`. Old links redirect.
|
|
9
|
+
- Verified live on a real account: a COLLECTION ad (paused).
|
|
10
|
+
|
|
11
|
+
## 0.3.2 (2026-11-14)
|
|
12
|
+
|
|
13
|
+
- Collection: product images are checked in the preview: they must be images, square (1:1) and at least 120x120 px. Snap refused 600x1000 images only at confirm time; now the preview says so before anything is sent. When Snap gives no size, the preview warns that the shape could not be checked.
|
|
14
|
+
- Collection: the preview lists the main Snap and every product image with its id and size, so what is approved is visible.
|
|
15
|
+
- Verified live on a real account: Collection creative (product tiles, product row, COLLECTION creative).
|
|
16
|
+
|
|
17
|
+
## 0.3.1 (2026-11-14)
|
|
18
|
+
|
|
19
|
+
- New read-only tool `snap_list_media`: the account's images and videos (READY by default), newest first, filtered by type and name, across every page. Finding a media id for a Story, Collection or Snap no longer needs the raw API tool.
|
|
20
|
+
- Verified live on a real account: Story creative and STORY ad (paused), and a SNAP_AD creative.
|
|
21
|
+
|
|
22
|
+
## 0.3.0 (2026-11-14)
|
|
23
|
+
|
|
24
|
+
Renamed to **Ads MCP for Snapchat** (package `ads-mcp-for-snapchat`), so the name does not read as Snap's own product. Tool names (`snap_*`) are unchanged.
|
|
25
|
+
|
|
26
|
+
### New ad formats
|
|
27
|
+
- `snap_create_story_creative`: Story Ads from 1-20 existing Snaps in a fixed order, with an optional tile for the Stories tab (PREVIEW + COMPOSITE creatives).
|
|
28
|
+
- `snap_create_collection_creative`: Collection Ads with 4-20 product tiles (creative elements, interaction zone, COLLECTION creative).
|
|
29
|
+
- `snap_create_creative` takes `creative_type: "SNAP_AD"` for a Snap with no link (image or video).
|
|
30
|
+
- `snap_create_ad` takes the ad type from the creative (REMOTE_WEBPAGE, SNAP_AD, STORY, COLLECTION) and refuses a mismatch.
|
|
31
|
+
|
|
32
|
+
### Fixes
|
|
33
|
+
- The call to action list now matches Snap's documented WEB_VIEW values; `BUY_NOW` and `VIEW_MORE`, which Snap does not accept for these creatives, were removed.
|
|
34
|
+
|
|
35
|
+
The new formats follow Snap's API reference and are covered by mocked tests; they have not yet been run against a live account.
|
|
36
|
+
|
|
37
|
+
## 0.2.1 (2026-11-14)
|
|
38
|
+
|
|
39
|
+
Fixes from a full code review, and a note on Snap's terms.
|
|
40
|
+
|
|
41
|
+
- `snap_undo` ignores list order and computed fields, so a targeting undo is no longer refused when Snap returns lists in another order.
|
|
42
|
+
- A damaged change log is reported instead of looking empty; `snap_undo` refuses rather than saying there is nothing to undo.
|
|
43
|
+
- The change log is parsed once per change of the file instead of once per item of a bulk edit; the in-memory copy keeps only the last 25 hours.
|
|
44
|
+
- Media uploads get a fresh token once on 401, like other requests.
|
|
45
|
+
- The weekly report names a missing `SNAP_AD_ACCOUNT_ID`.
|
|
46
|
+
- A confirm after the approval expired says "expired" instead of "unknown token".
|
|
47
|
+
- The async report download only follows a public https link.
|
|
48
|
+
- README: this is not Snap's official Ads MCP server; Snap's terms; which local files hold Snap data.
|
|
49
|
+
|
|
50
|
+
## 0.2.0 (2026-11-13)
|
|
51
|
+
|
|
52
|
+
First public release.
|
|
53
|
+
|
|
54
|
+
### Safety
|
|
55
|
+
- Every write is two steps: a preview returns a single-use approval token bound to the tool, ad account, arguments and target state. Stale, reused, expired or different requests are refused, and the refusal names the fields that changed. Fields Snap computes itself and list order are ignored.
|
|
56
|
+
- Absolute limits for daily budget, bid, lifetime budget, the budget one call may start, and everything added to an account in 24 hours. Budgets may rise at most 100% and bids 50% per step and per 24 hours. The limits apply to every path that can start or raise spending: set, bulk, create, copy, undo, enabling, and schedule changes that start delivery.
|
|
57
|
+
- Invalid safety settings stop the server at start-up instead of switching a limit off.
|
|
58
|
+
- Writes only touch the configured ad account. Ids are validated. Unknown arguments are refused.
|
|
59
|
+
- Every write records an intent before and a result after in the audit log; if the log cannot be written, the write does not run. Credentials are never logged; ad codes are masked.
|
|
60
|
+
- `SNAP_READ_ONLY=1` turns every write off. `SNAP_HUMAN_APPROVAL=elicit` asks the user directly through the MCP client.
|
|
61
|
+
- Deleting an audience that ACTIVE ad squads use is refused.
|
|
62
|
+
|
|
63
|
+
### Reliability and reports
|
|
64
|
+
- Deadline on every request; a write that fails in transit is never re-sent. A refused access token is replaced once.
|
|
65
|
+
- List tools read every page, take `name_contains`, and say when a list is cut.
|
|
66
|
+
- Reports compute totals from raw values, state their basis and attribution (optionally pinned), use the local day of the requested offset, and flag truncation. The health check reports unreadable stats as unknown.
|
|
67
|
+
- Changing countries keeps regional targeting of the countries that stay.
|
|
68
|
+
|
|
69
|
+
### Open source
|
|
70
|
+
- No hidden market defaults: `SNAP_DEFAULT_COUNTRY`, `SNAP_DEFAULT_PHONE_CODE`, `SNAP_REPORT_UTC_OFFSET`.
|
|
71
|
+
- Several ad accounts: one settings file per account (`SNAP_ENV_FILE`), each with its own credentials and change log.
|
|
72
|
+
- `save-secret.js` works on macOS, Windows and Linux, or with `--stdin`.
|
|
73
|
+
- Tool annotations (`readOnlyHint`, `destructiveHint`) for MCP clients.
|
|
74
|
+
- `zod` 4 and patched `hono` (npm audit clean). CI runs `npm audit` and the tests on Node 18, 20 and 22.
|
|
75
|
+
|
|
76
|
+
### Compatibility
|
|
77
|
+
- Writes need two calls (preview, then `confirm=true` with the `approval_token`).
|
|
78
|
+
- Default limits are conservative; set yours in `.env`. Limit changes apply after a restart.
|
|
79
|
+
- `countries` is required unless `SNAP_DEFAULT_COUNTRY` is set.
|
|
80
|
+
|
|
81
|
+
## 0.1.0
|
|
82
|
+
Initial version (private).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ads-mcp-for-snapchat contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,223 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Ads MCP for Snapchat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A local [MCP](https://modelcontextprotocol.io) server that lets an AI assistant (Claude Code, Claude Desktop and other MCP clients) work with **your own** Snapchat ad account: read performance, audit campaigns, and make careful, reviewable changes. It also turns creators' **ad codes** into paused ads.
|
|
4
|
+
|
|
5
|
+
> **Unofficial.** Not affiliated with or endorsed by Snap Inc. This tool can change real ad campaigns that spend real money. You use it at your own risk (see LICENSE). Check Snap's developer terms for your own use. Review every preview before approving.
|
|
6
|
+
|
|
7
|
+
## What it is, and what it is not
|
|
8
|
+
- **It runs on your machine, with your own Snapchat OAuth app and your own ad account.** Nothing is hosted or shared, and no credentials leave your computer except to Snap's API.
|
|
9
|
+
- **It is a safety-first tool, not an autopilot.** Writes are previewed first, created things start paused, and there are hard limits on money. See "Safety rules" below, and read "What the approval token is not".
|
|
10
|
+
- **It is not a hosted service.** Services that only accept remote MCP servers (for example ChatGPT connectors) cannot use it as it is. Do not expose it on the internet.
|
|
11
|
+
- **Money limits are in your account's currency.** Defaults (`SNAP_MAX_DAILY_BUDGET=1000`, `SNAP_MAX_BID=50`) are deliberately conservative; set your own in `.env`.
|
|
12
|
+
|
|
13
|
+
## Snap's terms and data
|
|
14
|
+
- This project is **not** Snap's official Ads MCP server and is not endorsed by Snap Inc. "Snapchat" is a trademark of Snap Inc.; it is used here only to say which API this tool works with.
|
|
15
|
+
- Using the Snapchat Marketing API means accepting Snap's Developer Terms and [Business Tools Terms](https://snap.com/terms/snap-business-tools). Read them yourself; they include duties on how long Snap data may be kept and how it must be protected.
|
|
16
|
+
- This server keeps data only on your machine: the change log (`changes.log.jsonl` or `<settings file>.log.jsonl`) and anything you export to `exports/`. You are responsible for keeping and deleting those files in line with Snap's terms.
|
|
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
|
+
|
|
19
|
+
## Ad formats
|
|
20
|
+
- **Single Snap with a link** (WEB_VIEW): `snap_create_creative`, then `snap_create_ad`.
|
|
21
|
+
- **Single Snap, no link** (image or video): `snap_create_creative` with `creative_type: "SNAP_AD"`.
|
|
22
|
+
- **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.
|
|
23
|
+
- **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
|
+
|
|
25
|
+
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
|
+
|
|
27
|
+
## Install from npm (no download needed)
|
|
28
|
+
Needs Node 18 or newer. Your settings live in `~/.ads-mcp-for-snapchat/.env`, outside the package, so updates never touch them.
|
|
29
|
+
|
|
30
|
+
1. `npx -y ads-mcp-for-snapchat init` creates the settings file (private to you). `npx -y ads-mcp-for-snapchat where` prints its path.
|
|
31
|
+
2. Open it, fill in `SNAP_CLIENT_ID`, `SNAP_AD_ACCOUNT_ID`, your limits and market settings, then follow **Setup (one time)** below using these commands instead of `node scripts/...`:
|
|
32
|
+
- `npx -y ads-mcp-for-snapchat save-secret` (client secret from the clipboard; `--stdin` to paste it instead)
|
|
33
|
+
- `npx -y ads-mcp-for-snapchat auth THE_CODE` (refresh token)
|
|
34
|
+
- `npx -y ads-mcp-for-snapchat check` (read-only test)
|
|
35
|
+
3. Register it: `claude mcp add --scope user snapchat-ads -- npx -y ads-mcp-for-snapchat`, then restart Claude Code. For Claude Desktop use `"command": "npx", "args": ["-y", "ads-mcp-for-snapchat"]`.
|
|
36
|
+
|
|
37
|
+
`npx -y ads-mcp-for-snapchat help` lists every command. For a second ad account, put `SNAP_ENV_FILE=/path/to/.env.account2` in front of any command, and add `-e SNAP_ENV_FILE=/path/to/.env.account2` when registering it (see "Several ad accounts"). It is also listed in the official MCP Registry as `io.github.Usame794/ads-mcp-for-snapchat`.
|
|
38
|
+
|
|
39
|
+
## Quick start (from source)
|
|
40
|
+
1. `git clone` this repository, then `npm ci`, then `npm test` (all tests are mocked and need no account).
|
|
41
|
+
2. Create a Snapchat OAuth app and connect it to your account: follow **Setup (one time)** below (about 10 minutes).
|
|
42
|
+
3. Copy the safety and market settings from `.env.example` into `.env` and set **your** limits, `SNAP_DEFAULT_COUNTRY`, `SNAP_ACCOUNT_CURRENCY` and `SNAP_REPORT_UTC_OFFSET`.
|
|
43
|
+
4. Start with `SNAP_READ_ONLY=1`: connect your MCP client, try `snap_ping`, a report, and a few previews, and compare the numbers with Ads Manager. Remove the setting when you are comfortable.
|
|
44
|
+
5. Keep your client's permission prompt **on** for write tools.
|
|
45
|
+
|
|
46
|
+
## Safety rules (built in)
|
|
47
|
+
- Every write tool works in **two steps**. `confirm=false` (the default) returns a preview and a single-use `approval_token`. To apply, the same arguments are sent again with `confirm=true` and that token. The token is bound to the tool, the ad account, the arguments and the state of the items at preview time: if anything changed, or the token is reused, expired or from another request, nothing is sent.
|
|
48
|
+
- Everything that creates something (copies, clones, new ads, new creatives) is created **PAUSED**. Enabling is a separate step, and its preview shows the daily budget that would really start delivering (for a campaign: the budgets of its ACTIVE ad squads).
|
|
49
|
+
- **Absolute limits**, in account currency, apply to every path that can raise money (set, bulk, create, copy, undo, enable): see the table below. On top of them, a budget may rise at most +100% and a bid +50% per step **and per 24 hours** (counted from this server's change log), so repeating a step does not compound.
|
|
50
|
+
- Writes only touch items of the configured `SNAP_AD_ACCOUNT_ID`. Ids are validated before they are used.
|
|
51
|
+
- The only delete tool is `snap_delete`, behind many guards. Status can only be `ACTIVE` or `PAUSED`.
|
|
52
|
+
- Every write is recorded in `changes.log.jsonl`: an intent record before anything is sent (if it cannot be written, the operation does not run) and a result record after, with tool, account, target ids, redacted arguments, and before/after values for edits. Credentials are never logged; ad codes are masked.
|
|
53
|
+
- Multi-step creates (copy, influencer flow) stop at the first failure and report exactly what was already created. A write that fails in transit is never re-sent; it is reported as "outcome unknown".
|
|
54
|
+
- Safety settings are validated when the server starts. An invalid value (for example `100%`) **stops the server** instead of switching the limit off. Limits and the target account are fixed until restart; only the OAuth credentials are re-read from `.env`.
|
|
55
|
+
|
|
56
|
+
### What the approval token is not
|
|
57
|
+
The token proves that this exact change was previewed and that nothing moved since. It does **not** prove that a person looked at it: the AI client receives the token and can send it back by itself. Human authorization is the permission prompt of your MCP client, so **do not auto-approve the write tools**. Tools are annotated (`readOnlyHint`, `destructiveHint`) so a client can auto-allow reads only. `SNAP_READ_ONLY=1` turns every write off.
|
|
58
|
+
|
|
59
|
+
### Asking you directly (`SNAP_HUMAN_APPROVAL=elicit`)
|
|
60
|
+
With this setting the server asks **you**, through the MCP client's own dialog (MCP elicitation), before every write, and refuses when it cannot ask. The question and your answer do not pass through the model. For anything that adds spend, for deletes and for undo, you must also type a 4-digit code that only the dialog shows. Limits you should know:
|
|
61
|
+
- It needs a client that shows elicitation dialogs. Claude Code documents this for interactive terminal sessions; in non-interactive sessions the request is cancelled, so writes are refused. This server's tests use the SDK's client, not Claude Code itself: try one harmless write (a rename) before relying on it.
|
|
62
|
+
- A client can be configured to answer elicitations automatically (in Claude Code, an `Elicitation` hook). Such a hook removes the human from the loop. Do not install one for this server, and keep your client's settings files out of reach of the AI's file tools.
|
|
63
|
+
|
|
64
|
+
### Safety settings (`.env`, all optional, restart to apply)
|
|
65
|
+
| Setting | Default | Meaning |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `SNAP_MAX_DAILY_BUDGET` | 1000 | Highest daily budget any single campaign or ad squad may be given or enabled with |
|
|
68
|
+
| `SNAP_MIN_DAILY_BUDGET` | 5 | Lowest daily budget |
|
|
69
|
+
| `SNAP_MAX_BID` | 50 | Highest max bid |
|
|
70
|
+
| `SNAP_MAX_BUDGET_INCREASE_PCT` | 100 | Largest budget increase per step and per 24 hours |
|
|
71
|
+
| `SNAP_MAX_BID_INCREASE_PCT` | 50 | Largest bid increase per step and per 24 hours |
|
|
72
|
+
| `SNAP_MAX_LIFETIME_BUDGET` | 30 x max daily | Highest lifetime budget a copy may carry or an enable may start |
|
|
73
|
+
| `SNAP_MAX_ACTIVATION_DAILY_BUDGET` | 5 x max daily | Most daily budget one call may start (enable, undo of a pause, or a schedule change that starts delivery) |
|
|
74
|
+
| `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 |
|
|
75
|
+
| `SNAP_ACCOUNT_CURRENCY` | not set | If set (e.g. `USD`), writes are refused unless the ad account uses that currency |
|
|
76
|
+
| `SNAP_READ_ONLY` | 0 | `1` = previews and reads only |
|
|
77
|
+
| `SNAP_HUMAN_APPROVAL` | off | `elicit` = ask the user through the MCP client before every write |
|
|
78
|
+
| `SNAP_APPROVAL_TTL_SECONDS` | 600 | Lifetime of an approval token |
|
|
79
|
+
| `SNAP_REPEAT_WINDOW_SECONDS` | 600 | An identical create, copy, claim or upload is refused within this time |
|
|
80
|
+
| `SNAP_HTTP_TIMEOUT_MS` | 60000 | Deadline for each API request |
|
|
81
|
+
| `SNAP_DEFAULT_COUNTRY` | not set | 2-letter country used when a tool is called without countries (new ad squads, lookalikes, targeting lookups). **Not set = countries must always be given**; there is no hidden default market |
|
|
82
|
+
| `SNAP_DEFAULT_PHONE_CODE` | not set | Country code (digits, no `+`) for local phone numbers in customer lists. Not set = local numbers are counted as invalid instead of being guessed |
|
|
83
|
+
| `SNAP_REPORT_UTC_OFFSET` | `+00:00` | Offset for `scripts/weekly-report.js` and `scripts/smoke.js` day boundaries, e.g. `+03:00` |
|
|
84
|
+
|
|
85
|
+
Reports state what their numbers mean (`basis`): amounts are Snap micro-currency divided by 1,000,000 in the account currency, purchases are Snap-attributed, and attribution uses the account's default windows unless you pin them with `swipe_up_attribution_window` / `view_attribution_window` on `snap_report` and `snap_report_daily`. Totals are computed from raw values (account ROAS = purchase value / spend). A report that was cut off says `incomplete` or `truncated`.
|
|
86
|
+
|
|
87
|
+
Existing items above a limit can still be read, lowered and paused, but not raised or enabled until the owner raises the limit. The 24-hour rules and the audit trail rely on `changes.log.jsonl` (plus an in-memory copy while the server runs, so deleting the file does not reset them until a restart); changes made in Ads Manager are not counted, and the file is not tamper-proof against someone with access to your disk. Keep `.env` and the log out of reach of the AI client's file tools (for Claude Code: a `Read`/`Edit` deny rule for the project folder).
|
|
88
|
+
|
|
89
|
+
## Tools
|
|
90
|
+
| Tool | Type |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `snap_ping` | check credentials |
|
|
93
|
+
| `snap_list_campaigns`, `snap_list_adsquads`, `snap_list_ads`, `snap_list_creatives`, `snap_get_entity`, `snap_get_media`, `snap_get_stats` | read |
|
|
94
|
+
| `snap_report` | read: ROAS, CPA, swipe rate, frequency by ad squad or ad |
|
|
95
|
+
| `snap_report_daily` | read: day-by-day performance (up to 31 days) |
|
|
96
|
+
| `snap_report_audience` | read: performance by country, gender, age, region, dma or make |
|
|
97
|
+
| `snap_health_check` | read: audits every active squad for missing buyer exclusion, high frequency, low swipe rate, low ROAS, spend with no purchases, paused parents |
|
|
98
|
+
| `snap_review_issues` | read: rejected / pending ads with Snap's reasons |
|
|
99
|
+
| `snap_pixel_health` | read: pixel signal readiness and event-quality issues, top priority first |
|
|
100
|
+
| `snap_creative_fatigue` | read: which ads are tired (ROAS down 30%+ with higher frequency or lower swipe rate), which to replace first |
|
|
101
|
+
| `snap_report_compare` | read: two time windows side by side with the changes |
|
|
102
|
+
| `snap_report_async_start`, `snap_report_async_status`, `snap_report_async_download` | read: very large CSV reports saved to `exports/` |
|
|
103
|
+
| `snap_api_get` | read-only GET for anything else (allow-listed paths, never writes) |
|
|
104
|
+
| `snap_list_segments`, `snap_list_pixels`, `snap_list_catalogs`, `snap_list_product_sets`, `snap_targeting_options` | read: audiences, pixels, catalogs, product sets, interest/region/language ids |
|
|
105
|
+
| `snap_change_log` | read the local log |
|
|
106
|
+
| `snap_set_status`, `snap_set_status_bulk` | pause / enable (bulk up to 20, warns when a parent is paused) |
|
|
107
|
+
| `snap_set_daily_budget`, `snap_set_bid`, `snap_rename` | edit |
|
|
108
|
+
| `snap_set_targeting` | change countries, age, gender, interests, device OS, include segments, stop excluding segments; everything else is kept |
|
|
109
|
+
| `snap_set_schedule` | set start/end time on a campaign or ad squad |
|
|
110
|
+
| `snap_exclude_segments` | add buyer-exclusion audiences to an ad squad |
|
|
111
|
+
| `snap_copy_campaign` | copy a campaign (all or selected ad squads, with or without ads), paused |
|
|
112
|
+
| `snap_create_campaign` | create a new empty campaign, paused |
|
|
113
|
+
| `snap_create_adsquad` | create a new purchase-optimized web ad squad (max bid or auto-bid, interests, device OS, buyer exclusions), paused |
|
|
114
|
+
| `snap_create_lookalike` | create a lookalike audience from a customer-list seed |
|
|
115
|
+
| `snap_copy_adsquad` | copy one ad squad into a campaign, paused |
|
|
116
|
+
| `snap_clone_ad` | clone an ad into other ad squads, paused (skips duplicates and different product sets) |
|
|
117
|
+
| `snap_bulk_exclude_segments`, `snap_bulk_set_budget`, `snap_bulk_set_schedule`, `snap_bulk_rename` | edit up to 20 items at once with a per-item preview; stop at the first failure |
|
|
118
|
+
| `snap_undo` | revert a change from the log (refuses if the field changed again since) |
|
|
119
|
+
| `snap_clone_creative` | duplicate a creative with a new name/headline/link |
|
|
120
|
+
| `snap_create_pixel_audience` | audience of people who fired pixel events (e.g. ADD_CART) |
|
|
121
|
+
| `snap_upload_customer_list` | customer-list audience from a local CSV; hashed locally, only hashes uploaded |
|
|
122
|
+
| `snap_influencer_batch` | influencer flow for up to 10 ad codes into one squad; expired codes are skipped |
|
|
123
|
+
| `snap_delete` | guarded delete: paused, no spend in 30 days, no active children, exact name typed |
|
|
124
|
+
| `snap_claim_ad_code` | claim a creator ad code (one-way, single-use) |
|
|
125
|
+
| `snap_upload_media` | upload a local video/image (up to 1 GB, chunked above 32 MB) to the ad account, not attached to any ad |
|
|
126
|
+
| `snap_create_creative`, `snap_create_ad` | creative from an image or video: WEB_VIEW (swipe-up link) or SNAP_AD (the Snap only); ad from a creative, its type taken from the creative (paused) |
|
|
127
|
+
| `snap_list_media` | images and videos in the account (READY by default), newest first, filter by type and name |
|
|
128
|
+
| `snap_create_story_creative` | Story Ad: 1-20 existing Snaps in a fixed order, with an optional tile for the Stories tab |
|
|
129
|
+
| `snap_create_collection_creative` | Collection Ad: a main image or video with 4-20 product tiles, each opening its own page |
|
|
130
|
+
| `snap_influencer_ad` | the whole influencer flow in one step: claim, wait for media, creative, paused ad |
|
|
131
|
+
|
|
132
|
+
## Influencer ad-code flow
|
|
133
|
+
Creators share a code like `adcode_<uuid>`. `snap_influencer_ad` claims it into the ad account (`POST /adaccounts/{id}/claim_media_by_ad_code?ad_code=&profile_id=`, parameters go in the query string), waits for the media to be READY, creates a WEB_VIEW creative on the brand profile (`SNAP_BRAND_PROFILE_ID`) and creates a **paused** ad in the ad squad you choose.
|
|
134
|
+
Notes from live use:
|
|
135
|
+
- Claiming is one-way and codes are single-use. Expired codes return "Ad code has expired" and are not consumed.
|
|
136
|
+
- Codes beyond their lifetime cannot be refreshed; ask the creator for a new one.
|
|
137
|
+
- Codes starting with `#` are for other platforms and are rejected.
|
|
138
|
+
|
|
139
|
+
## Scripts
|
|
140
|
+
From an npm install, use `npx -y ads-mcp-for-snapchat check | weekly-report` instead; reports then go to `~/.ads-mcp-for-snapchat/exports/`.
|
|
141
|
+
- `npm run smoke`: live read-only check of credentials, token refresh and the main read paths (exit code 1 on any failure). Run it after changing a secret or updating the server.
|
|
142
|
+
- `npm run weekly-report`: read-only weekly report saved to `exports/weekly-<date>.md` (spend and ROAS vs last week, top campaigns, account health, tired ads, review problems, pixel issues). Optional argument: end date, e.g. `npm run weekly-report -- 2026-10-27`.
|
|
143
|
+
- Reliability: reads retry automatically on rate limits (429), server errors and network errors; writes retry only on 429, so a create or claim is never repeated by accident.
|
|
144
|
+
|
|
145
|
+
## Requirements
|
|
146
|
+
Node 18+ and a Snapchat Ads account with permission to create an OAuth app. Install dependencies with `npm install`. Run the tests with `npm test` (all mocked, no credentials needed).
|
|
147
|
+
|
|
148
|
+
Each user runs this server locally with their own OAuth app and their own ad account. Nothing is shared or hosted.
|
|
149
|
+
|
|
150
|
+
## Setup (one time)
|
|
151
|
+
1. In Snap Ads Manager open **Business Details > OAuth Apps** and create an app. Redirect URL must be https and not `localhost`, for example `https://127.0.0.1/callback`. **The client secret is shown once**: select it and copy it before leaving the page.
|
|
152
|
+
2. Copy `.env.example` to `.env`, fill in `SNAP_CLIENT_ID` and `SNAP_REDIRECT_URI`.
|
|
153
|
+
3. Save the secret from your clipboard: `node scripts/save-secret.js` (reads the clipboard on macOS, Windows, and Linux with `wl-paste`, `xclip` or `xsel`; it refuses text that does not look like a secret and clears the clipboard). Without a clipboard tool use `node scripts/save-secret.js --stdin`, or add `SNAP_CLIENT_SECRET=...` to `.env` yourself and make the file private (`chmod 600 .env`).
|
|
154
|
+
4. Open this URL in a browser signed in to Snapchat and approve (replace the two values):
|
|
155
|
+
`https://accounts.snapchat.com/login/oauth2/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&scope=snapchat-marketing-api&state=ads-mcp-for-snapchat`
|
|
156
|
+
5. The browser redirects to `...?code=...`. Within a minute or two run: `CODE=THE_CODE node scripts/get-refresh-token.js`. It saves `SNAP_REFRESH_TOKEN` into `.env` and prints nothing secret.
|
|
157
|
+
6. `node scripts/check.js` refreshes the token and tests `/me` and the ad account (read-only).
|
|
158
|
+
7. Register: `claude mcp add --scope user snapchat-ads -- node "/ABSOLUTE/PATH/TO/ads-mcp-for-snapchat/src/index.js"`, then restart Claude Code.
|
|
159
|
+
|
|
160
|
+
## Use it from Claude or ChatGPT
|
|
161
|
+
This is a local MCP server (stdio). Credentials stay in your `.env`; the AI app only starts the process.
|
|
162
|
+
|
|
163
|
+
**Claude Code** (step 7 above): `claude mcp add --scope user snapchat-ads -- node "/ABSOLUTE/PATH/TO/ads-mcp-for-snapchat/src/index.js"`, then restart. Check with `claude mcp list`.
|
|
164
|
+
|
|
165
|
+
**Claude Desktop**: open Settings > Developer > Edit Config and add this to `claude_desktop_config.json`, then fully quit and reopen the app:
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"mcpServers": {
|
|
169
|
+
"snapchat-ads": {
|
|
170
|
+
"command": "node",
|
|
171
|
+
"args": ["/ABSOLUTE/PATH/TO/ads-mcp-for-snapchat/src/index.js"]
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
Use the absolute path to `node` as `command` if the app cannot find it. The server reads `.env` from its own folder (an npm install reads `~/.ads-mcp-for-snapchat/.env`), so no secrets go in this file.
|
|
177
|
+
|
|
178
|
+
**ChatGPT**: ChatGPT connects to *remote* MCP servers (an https URL) through its connectors / developer mode, not to local stdio programs. This server is local only, so it cannot be added to ChatGPT as it is. Doing that would need a hosted version with per-user OAuth and encrypted token storage (see "Not built"). Do not expose this server publicly as it is: it can change real ad campaigns. Other desktop MCP clients that launch local stdio servers (Cursor, VS Code, Cline) work with the same `command` and `args` as above.
|
|
179
|
+
|
|
180
|
+
## Several ad accounts
|
|
181
|
+
Run one server per ad account, each with its own settings file. Each server only touches its own account, and keeps its own change log (`<settings file>.log.jsonl`), so limits, undo and the audit trail never mix.
|
|
182
|
+
|
|
183
|
+
1. Copy your settings: `cp .env .env.account2`. In `.env.account2`, set that account's `SNAP_AD_ACCOUNT_ID`, `SNAP_PIXEL_ID`, `SNAP_BRAND_PROFILE_ID` and its own limits. Every `.env*` file except `.env.example` is git-ignored.
|
|
184
|
+
2. If that account belongs to another Snapchat login, authorize it into its own file (same steps as "Setup", with the variable in front): `SNAP_ENV_FILE=.env.account2 node scripts/get-refresh-token.js`, then `SNAP_ENV_FILE=.env.account2 node scripts/check.js`. If the same login can see both accounts, the copied credentials already work.
|
|
185
|
+
3. Register a second server with an absolute path to the file:
|
|
186
|
+
`claude mcp add --scope user -e SNAP_ENV_FILE="/ABSOLUTE/PATH/TO/ads-mcp-for-snapchat/.env.account2" snapchat-ads-2 -- node "/ABSOLUTE/PATH/TO/ads-mcp-for-snapchat/src/index.js"`
|
|
187
|
+
4. Start with `SNAP_READ_ONLY=1` in the new file and check `snap_ping` shows the right account.
|
|
188
|
+
|
|
189
|
+
Scripts work the same way: put `SNAP_ENV_FILE=.env.account2` in front of any `node scripts/...` command.
|
|
190
|
+
|
|
191
|
+
## Weekly report on a schedule
|
|
192
|
+
`npm run weekly-report` writes `exports/weekly-<account>-<date>.md` (read-only; nothing is changed in the account). To run it every Sunday at 09:30 on macOS or Linux, add a line with `crontab -e`, using the full path of `node` (`which node`):
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
30 9 * * 0 cd "/ABSOLUTE/PATH/TO/ads-mcp-for-snapchat" && /full/path/to/node scripts/weekly-report.js >> "$HOME/snap-weekly.log" 2>&1
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The computer must be awake at that time. Set `SNAP_REPORT_UTC_OFFSET` so the week starts at your local midnight. For a second account add `SNAP_ENV_FILE=.env.account2` before `/full/path/to/node`.
|
|
199
|
+
|
|
200
|
+
## Verified live (against the real Snapchat API)
|
|
201
|
+
Verified on the maintainer's own ad account. Anything not listed here is covered by mocked tests only: try it with `SNAP_READ_ONLY=1` on your account first.
|
|
202
|
+
|
|
203
|
+
**After the safety layer (November 2026):**
|
|
204
|
+
- Connection and settings: token refresh, `snap_ping` (shows the limits in force), start-up validation of `.env`.
|
|
205
|
+
- Reads: campaign and ad squad lists across more than one page, finding one campaign among about 2,000 with `name_contains`, ad squad details.
|
|
206
|
+
- Reports: the weekly report's account spend for a full week matched the figure in Ads Manager for the same dates and time zone. Purchases and ROAS use Snap's attribution and can differ from other tools.
|
|
207
|
+
- Previews: enabling a campaign and an ad squad shows what would really start delivering, including an ad squad under a paused campaign, and its daily budget matched Ads Manager.
|
|
208
|
+
- One real write on a throwaway campaign: preview, approval token, rename, read-back verification, audit entries (intent and result), `snap_undo` preview and undo.
|
|
209
|
+
- Story Ads (0.3.0): a Story creative from two existing creatives (account and type checks, fixed order), then `snap_create_ad` choosing ad type STORY, created PAUSED in a paused test ad squad.
|
|
210
|
+
- SNAP_AD creative (0.3.0): a Snap with no link from an uploaded vertical video.
|
|
211
|
+
- Collection Ads (0.3.1): 4 product tiles, the product row, the COLLECTION creative, then `snap_create_ad` choosing ad type COLLECTION, created PAUSED in a paused test ad squad. Snap refused non-square product images, which the preview now checks (0.3.2).
|
|
212
|
+
|
|
213
|
+
**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).
|
|
214
|
+
|
|
215
|
+
**Not verified live:** 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.
|
|
216
|
+
|
|
217
|
+
## Not built
|
|
218
|
+
- A hosted multi-user version (this server runs on your own machine with your own credentials).
|
|
219
|
+
- Lens, App Install, Deep Link, lead-form and dynamic product creatives, product set creation, ad squad types other than purchase-optimized web squads, custom location/radius targeting, lifetime or reach-and-frequency budgets, and position-level reports.
|
|
220
|
+
- Anything that spends money without a separate, explicit enable step.
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
`npm ci`, then `npm test` (all tests use a mocked API; none touch your account). See `ARCHITECTURE.md` for the design and `CONTRIBUTING.md` before sending changes.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
## Reporting a vulnerability
|
|
4
|
+
Please do not open a public issue for security problems. Use GitHub's "Report a vulnerability" (private security advisory) on this repository. Never include real tokens, secrets or account data in a report; describe how to reproduce it with a mock.
|
|
5
|
+
|
|
6
|
+
Supported version: the latest release on `main`. This is a small, unofficial project maintained on a best-effort basis.
|
|
7
|
+
|
|
8
|
+
## Handling secrets
|
|
9
|
+
- Credentials live only in your local `.env`, which is git-ignored. Never commit it, paste it in issues, or share logs that contain it.
|
|
10
|
+
- If a client secret or refresh token is ever exposed, revoke it in Snap Ads Manager (Business Details > OAuth Apps) and create a new one.
|
|
11
|
+
- `changes.log.jsonl` and `exports/` can contain account data; they are git-ignored too.
|
|
12
|
+
|
|
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
|
+
- 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
|
+
|
|
16
|
+
## Safety design
|
|
17
|
+
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/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ads-mcp-for-snapchat",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Unofficial local MCP server for the Snapchat Marketing API: reports, audits and safe, previewed changes to campaigns, ad squads and ads.",
|
|
5
|
+
"mcpName": "io.github.Usame794/ads-mcp-for-snapchat",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "src/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"ads-mcp-for-snapchat": "src/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"start": "node src/index.js",
|
|
13
|
+
"test": "node --test test/*.test.js",
|
|
14
|
+
"smoke": "node scripts/smoke.js",
|
|
15
|
+
"weekly-report": "node scripts/weekly-report.js"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
19
|
+
"zod": "^4.6.7"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"private": false,
|
|
26
|
+
"keywords": [
|
|
27
|
+
"mcp",
|
|
28
|
+
"model-context-protocol",
|
|
29
|
+
"snapchat",
|
|
30
|
+
"snapchat-ads",
|
|
31
|
+
"snap-marketing-api",
|
|
32
|
+
"claude",
|
|
33
|
+
"advertising"
|
|
34
|
+
],
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/Usame794/ads-mcp-for-snapchat.git"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/Usame794/ads-mcp-for-snapchat/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/Usame794/ads-mcp-for-snapchat#readme",
|
|
43
|
+
"files": [
|
|
44
|
+
"src",
|
|
45
|
+
"scripts/save-secret.js",
|
|
46
|
+
"scripts/get-refresh-token.js",
|
|
47
|
+
"scripts/check.js",
|
|
48
|
+
"scripts/weekly-report.js",
|
|
49
|
+
"README.md",
|
|
50
|
+
"ARCHITECTURE.md",
|
|
51
|
+
"SECURITY.md",
|
|
52
|
+
"LICENSE",
|
|
53
|
+
".env.example",
|
|
54
|
+
"CHANGELOG.md"
|
|
55
|
+
]
|
|
56
|
+
}
|
package/scripts/check.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Refreshes the access token and makes read-only test calls. Prints only non-secret results.
|
|
3
|
+
import { loadEnv } from "../src/env.js";
|
|
4
|
+
import { SnapClient } from "../src/snap.js";
|
|
5
|
+
|
|
6
|
+
loadEnv();
|
|
7
|
+
const client = new SnapClient();
|
|
8
|
+
try {
|
|
9
|
+
await client.accessToken();
|
|
10
|
+
console.log("Token refresh: OK");
|
|
11
|
+
const me = (await client.request("GET", "/me")).me ?? {};
|
|
12
|
+
console.log(`GET /me: OK (${me.display_name ?? me.email ?? "authorized user"})`);
|
|
13
|
+
const acct = process.env.SNAP_AD_ACCOUNT_ID;
|
|
14
|
+
const data = await client.request("GET", `/adaccounts/${acct}`);
|
|
15
|
+
const a = data.adaccounts?.[0]?.adaccount ?? {};
|
|
16
|
+
console.log(`Ad account: OK (${a.name}, ${a.status}, ${a.currency})`);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.error("Check failed:", e.message);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// One-time helper: exchange the authorization code for a refresh token and save it to .env.
|
|
3
|
+
// Usage: CODE=<code> node scripts/get-refresh-token.js (or pass the code as the first argument)
|
|
4
|
+
// Needs SNAP_CLIENT_ID, SNAP_CLIENT_SECRET and SNAP_REDIRECT_URI in .env. Prints nothing secret.
|
|
5
|
+
import { loadEnv, setEnvValue } from "../src/env.js";
|
|
6
|
+
|
|
7
|
+
loadEnv();
|
|
8
|
+
const code = process.argv[2] || process.env.CODE;
|
|
9
|
+
const { SNAP_CLIENT_ID, SNAP_CLIENT_SECRET, SNAP_REDIRECT_URI } = process.env;
|
|
10
|
+
const missing = Object.entries({ code, SNAP_CLIENT_ID, SNAP_CLIENT_SECRET, SNAP_REDIRECT_URI }).filter(([, v]) => !v).map(([k]) => k);
|
|
11
|
+
if (missing.length) {
|
|
12
|
+
console.error(`Missing: ${missing.join(", ")}. Usage: CODE=<code> node scripts/get-refresh-token.js`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const res = await fetch("https://accounts.snapchat.com/login/oauth2/access_token", {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
18
|
+
body: new URLSearchParams({
|
|
19
|
+
grant_type: "authorization_code",
|
|
20
|
+
code,
|
|
21
|
+
redirect_uri: SNAP_REDIRECT_URI,
|
|
22
|
+
client_id: SNAP_CLIENT_ID,
|
|
23
|
+
client_secret: SNAP_CLIENT_SECRET,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
const data = await res.json().catch(() => ({}));
|
|
27
|
+
if (!res.ok || !data.refresh_token) {
|
|
28
|
+
console.error(`Exchange failed (${res.status}): ${data.error_description || data.error || "no detail"}. The code may have expired; get a new one.`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
setEnvValue("SNAP_REFRESH_TOKEN", data.refresh_token);
|
|
32
|
+
console.log(`Saved SNAP_REFRESH_TOKEN to .env (${data.refresh_token.length} chars).`);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Saves the client secret into .env after checking that it looks like a secret. Prints nothing secret.
|
|
3
|
+
// Usage: node scripts/save-secret.js reads the system clipboard (macOS, Linux with wl-paste/xclip/xsel, Windows) and clears it
|
|
4
|
+
// node scripts/save-secret.js --stdin reads the secret from standard input instead (e.g. `pbpaste | node scripts/save-secret.js --stdin`)
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { setEnvValue } from "../src/env.js";
|
|
7
|
+
import { clearClipboard, readClipboard, secretProblems } from "../src/clipboard.js";
|
|
8
|
+
|
|
9
|
+
const fromStdin = process.argv.includes("--stdin");
|
|
10
|
+
const text = fromStdin ? readFileSync(0, "utf8").trim() : readClipboard();
|
|
11
|
+
if (text === null) {
|
|
12
|
+
console.error("No clipboard tool was found. Run it as: node scripts/save-secret.js --stdin and paste the secret, or add SNAP_CLIENT_SECRET=... to .env yourself (chmod 600 .env).");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const problems = secretProblems(text);
|
|
16
|
+
if (problems.length) {
|
|
17
|
+
console.error(`The text does not look like a client secret: ${problems.join("; ")}. Nothing was saved. Copy the secret again and rerun.`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
setEnvValue("SNAP_CLIENT_SECRET", text);
|
|
21
|
+
const cleared = fromStdin ? false : clearClipboard();
|
|
22
|
+
console.log(`Saved SNAP_CLIENT_SECRET to .env (${text.length} chars).${cleared ? " Clipboard cleared." : fromStdin ? "" : " Clear your clipboard yourself."}`);
|