ads-mcp-for-snapchat 0.11.1 → 0.11.2
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 +1 -1
- package/CHANGELOG.md +7 -0
- package/README.md +2 -1
- package/package.json +1 -1
- package/src/index.js +11 -1
- package/src/media-dir.js +3 -3
- package/src/policy.js +3 -2
- package/src/snap.js +11 -3
package/.env.example
CHANGED
|
@@ -10,7 +10,7 @@ SNAP_MAX_DAILY_BUDGET=1000
|
|
|
10
10
|
# Optional: a warning (not a limit) in the preview when a change adds more daily budget than this.
|
|
11
11
|
# SNAP_WARN_DAILY_BUDGET=
|
|
12
12
|
# Optional: only read media and customer-list files from this folder (absolute path).
|
|
13
|
-
# SNAP_MEDIA_DIR=
|
|
13
|
+
# SNAP_MEDIA_DIR= (default: ~/SnapAds; an absolute folder path, or "any" to allow files from anywhere)
|
|
14
14
|
SNAP_MIN_DAILY_BUDGET=5
|
|
15
15
|
SNAP_MAX_BID=50
|
|
16
16
|
SNAP_MAX_BUDGET_INCREASE_PCT=100
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.2 (2026-11-26)
|
|
4
|
+
More fixes from the release audit.
|
|
5
|
+
|
|
6
|
+
- **Token refresh**: requests that run at the same time now share one refresh instead of each making their own (Snap may rotate the refresh token on every refresh, so parallel refreshes could leave an old one saved and force a reconnect). Retrying on server errors is now decided by the caller, not by whether the address contains `access_token`, so Conversions API test events are no longer repeated.
|
|
7
|
+
- **Local files are only read from one folder**: `~/SnapAds` by default (created if missing; the Desktop extension has a setting for it). Set `SNAP_MEDIA_DIR` to another folder, or to `any` to allow files from anywhere. If you uploaded from other folders before, move the files or set `SNAP_MEDIA_DIR`.
|
|
8
|
+
- **Hosted connector**: the consent page and README now say plainly that the approval code is not a human approval and that your AI app's permission prompt is the real one. (The connector already starts read-only; changes need a tick on the consent page.)
|
|
9
|
+
|
|
3
10
|
## 0.11.1 (2026-11-26)
|
|
4
11
|
Fixes from the release audit (read tools that did not match Snapchat's published API).
|
|
5
12
|
|
package/README.md
CHANGED
|
@@ -121,6 +121,7 @@ A second way to use the same tools with **nothing to install**: a connector you
|
|
|
121
121
|
What it does:
|
|
122
122
|
- You add the connector, sign in with Snapchat, and choose which ad account to use (`snap_connect`).
|
|
123
123
|
- **Read-only unless you tick "allow changes" on the consent page.** With changes allowed you get the same safety rules as the local version: everything created is paused, every change is previewed first with an approval code that works once for exactly that request, spending limits apply, and the change log lives in your own private database.
|
|
124
|
+
- **Who approves a change:** the approval code only proves the change was previewed and has not moved. It does not prove that you looked at it, because your AI app receives the code. On the hosted connector the real approval is **your AI app's permission prompt**, so ticking "allow changes" is only safe if you keep that prompt on for the tools that change things.
|
|
124
125
|
- Each person gets a separate private database. `snap_disconnect` deletes everything stored about you; also revoke the app in Snapchat Business Manager.
|
|
125
126
|
- Interactive cards (below) are shown in Claude with this version.
|
|
126
127
|
- **Works with apps that support remote MCP servers with sign-in** (OAuth with dynamic registration, which is what this server offers). It has been **tested with Claude only**. ChatGPT's custom connectors use the same standard, but it has **not been tested there**, and what ChatGPT allows depends on your plan.
|
|
@@ -154,7 +155,7 @@ With this setting the server asks **you**, through the MCP client's own dialog (
|
|
|
154
155
|
| `SNAP_MAX_RESPONSE_CHARS` | 100000 | Longest answer a tool returns; longer ones are cut with a note saying how to ask for less. |
|
|
155
156
|
| `SNAP_LEGACY_TOOLS` | off | Set to 1 to also show the old tool names that were merged into other tools (for example `snap_set_status_bulk`, `snap_bulk_set_budget`, `snap_report_daily`). They work as before and say which tool replaced them. Off by default, so the assistant sees fewer tools. |
|
|
156
157
|
| `SNAP_TOOLSETS_DEFAULT` | (none) | Set by the Claude Desktop extension to `core`: used only when `SNAP_TOOLSETS` is empty or was never saved, so upgraded installs start with the core tool set. A real `SNAP_TOOLSETS` value always wins. |
|
|
157
|
-
| `SNAP_MEDIA_DIR` |
|
|
158
|
+
| `SNAP_MEDIA_DIR` | `~/SnapAds` | The one folder `snap_upload_media` and `snap_upload_customer_list` may read files from (symbolic links are resolved first), so the server cannot be steered into reading other files on your computer. Created if missing. Set another absolute folder to change it, or `any` to allow files from anywhere. |
|
|
158
159
|
| `SNAP_WARN_DAILY_BUDGET` | (none) | Optional **warning** level, not a limit: a change that adds more than this daily budget shows a `budget_warning` in the preview. Without it, the preview still warns when a change adds more than twice your largest running ad squad (or, on an account with none running, more than half of `SNAP_MAX_DAILY_BUDGET`). |
|
|
159
160
|
| `SNAP_MIN_DAILY_BUDGET` | 5 | Lowest daily budget |
|
|
160
161
|
| `SNAP_MAX_BID` | 50 | Highest max bid |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ads-mcp-for-snapchat",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
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
6
|
"adsMcpBroker": "https://ads-mcp-for-snapchat-login.ads-mcp.workers.dev",
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,9 @@ import { loadPolicy } from "./policy.js";
|
|
|
7
7
|
import { SnapClient } from "./snap.js";
|
|
8
8
|
import { registerTools } from "./tools.js";
|
|
9
9
|
import { INSTRUCTIONS } from "./instructions.js";
|
|
10
|
+
import { mkdirSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
10
13
|
|
|
11
14
|
// A Claude Desktop extension passes optional settings the person left empty as unreplaced "${user_config.x}" text on some
|
|
12
15
|
// versions. Treat those as unset, so an empty optional setting can never stop the server or become a real value.
|
|
@@ -15,6 +18,13 @@ loadEnv();
|
|
|
15
18
|
// The Desktop extension offers "core" when its Tool set setting is empty or was never saved (an upgraded install has no value for a
|
|
16
19
|
// setting added later). A real value, including "all", always wins.
|
|
17
20
|
if (!process.env.SNAP_TOOLSETS && process.env.SNAP_TOOLSETS_DEFAULT) process.env.SNAP_TOOLSETS = process.env.SNAP_TOOLSETS_DEFAULT;
|
|
21
|
+
// Local files are only read from one folder (~/SnapAds by default), so an instruction hidden in an ad name or a web page cannot make
|
|
22
|
+
// the server read some other file. SNAP_MEDIA_DIR=any switches this off; any other absolute path replaces the folder.
|
|
23
|
+
if (!String(process.env.SNAP_MEDIA_DIR ?? "").trim()) {
|
|
24
|
+
const dir = join(homedir(), "SnapAds");
|
|
25
|
+
try { mkdirSync(dir, { recursive: true }); } catch { /* the upload tools say so if it cannot be used */ }
|
|
26
|
+
process.env.SNAP_MEDIA_DIR = dir;
|
|
27
|
+
}
|
|
18
28
|
let policy;
|
|
19
29
|
try {
|
|
20
30
|
// Safety settings are validated before anything else. An invalid value stops the server instead of disabling a limit.
|
|
@@ -25,7 +35,7 @@ try {
|
|
|
25
35
|
}
|
|
26
36
|
// Snapshot of the non-secret settings taken at startup. Later edits to .env do not change limits or the target account.
|
|
27
37
|
const settings = { ...process.env };
|
|
28
|
-
const server = new McpServer({ name: "ads-mcp-for-snapchat", version: "0.11.
|
|
38
|
+
const server = new McpServer({ name: "ads-mcp-for-snapchat", version: "0.11.2", ...BRAND }, { instructions: INSTRUCTIONS });
|
|
29
39
|
// Only the OAuth credentials are re-read from .env when a token is needed, so replacing them does not require a restart.
|
|
30
40
|
const client = new SnapClient({ beforeToken: () => loadEnv(undefined, { override: true }), onNewRefreshToken: (t) => setEnvValue("SNAP_REFRESH_TOKEN", t), timeoutMs: policy.httpTimeoutMs });
|
|
31
41
|
registerTools(server, client, settings);
|
package/src/media-dir.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Folder allow-list for local files this server reads and uploads (media and customer lists), ~/SnapAds unless SNAP_MEDIA_DIR says otherwise. A file must be inside it after symbolic links are resolved,
|
|
2
2
|
// a file must be inside that folder after symbolic links are resolved, so an instruction hidden in an ad name or a web page
|
|
3
3
|
// cannot make the server read some other file on the computer.
|
|
4
4
|
import { realpathSync } from "node:fs";
|
|
@@ -11,7 +11,7 @@ export function assertFileAllowed(filePath, mediaDir) {
|
|
|
11
11
|
try {
|
|
12
12
|
root = realpathSync(mediaDir);
|
|
13
13
|
} catch {
|
|
14
|
-
throw new Error(`
|
|
14
|
+
throw new Error(`The upload folder (${mediaDir}) does not exist or cannot be read. Create it, or set SNAP_MEDIA_DIR to another folder.`);
|
|
15
15
|
}
|
|
16
16
|
try {
|
|
17
17
|
real = realpathSync(resolve(String(filePath)));
|
|
@@ -20,6 +20,6 @@ export function assertFileAllowed(filePath, mediaDir) {
|
|
|
20
20
|
}
|
|
21
21
|
const rel = relative(root, real);
|
|
22
22
|
if (rel === "" || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
23
|
-
throw new Error(`That file is outside the folder
|
|
23
|
+
throw new Error(`That file is outside the upload folder (${mediaDir}). Put the file inside that folder and try again (SNAP_MEDIA_DIR changes the folder; SNAP_MEDIA_DIR=any allows files from anywhere).`);
|
|
24
24
|
}
|
|
25
25
|
}
|
package/src/policy.js
CHANGED
|
@@ -70,8 +70,9 @@ export function loadPolicy(env = process.env) {
|
|
|
70
70
|
let mediaDir = null;
|
|
71
71
|
if (env.SNAP_MEDIA_DIR !== undefined && String(env.SNAP_MEDIA_DIR).trim() !== "") {
|
|
72
72
|
const d = String(env.SNAP_MEDIA_DIR).trim();
|
|
73
|
-
if (
|
|
74
|
-
else
|
|
73
|
+
if (d.toLowerCase() === "any") mediaDir = null; // the owner chose to allow files from anywhere
|
|
74
|
+
else if (/^(\/|[A-Za-z]:[\\/])/.test(d)) mediaDir = d;
|
|
75
|
+
else errors.push("SNAP_MEDIA_DIR must be an absolute folder path (media and customer-list files must be inside it), or \"any\" to allow files from anywhere.");
|
|
75
76
|
}
|
|
76
77
|
let warnDailyBudget = null;
|
|
77
78
|
if (env.SNAP_WARN_DAILY_BUDGET !== undefined && String(env.SNAP_WARN_DAILY_BUDGET).trim() !== "") {
|
package/src/snap.js
CHANGED
|
@@ -185,9 +185,10 @@ export class SnapClient {
|
|
|
185
185
|
|
|
186
186
|
// Reads (and the token call) retry on 429/5xx and network errors. Writes retry ONLY on 429, which Snap sends before
|
|
187
187
|
// processing, so a create/claim is never repeated by accident.
|
|
188
|
-
async fetchRetry(url, opts = {}, { timeoutMs = this.timeoutMs } = {}) {
|
|
188
|
+
async fetchRetry(url, opts = {}, { timeoutMs = this.timeoutMs, idempotent = false } = {}) {
|
|
189
189
|
const method = (opts.method ?? "GET").toUpperCase();
|
|
190
|
-
|
|
190
|
+
// Only reads, and calls the caller says are repeatable (the token refresh), are retried on 5xx and network errors. Never decided from the URL.
|
|
191
|
+
const safe = method === "GET" || idempotent;
|
|
191
192
|
let last;
|
|
192
193
|
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
193
194
|
try {
|
|
@@ -223,8 +224,15 @@ export class SnapClient {
|
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
|
|
227
|
+
// One refresh at a time: requests that run in parallel (dashboards fan out) share it. Snap may rotate the refresh token on each
|
|
228
|
+
// refresh, so several refreshes at once could leave a stale one saved.
|
|
226
229
|
async accessToken() {
|
|
227
230
|
if (this.token && Date.now() < this.tokenExpiry - 60_000) return this.token;
|
|
231
|
+
this.refreshing ??= this.refreshAccessToken().finally(() => { this.refreshing = null; });
|
|
232
|
+
return this.refreshing;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async refreshAccessToken() {
|
|
228
236
|
this.beforeToken?.();
|
|
229
237
|
const { SNAP_CLIENT_ID, SNAP_CLIENT_SECRET, SNAP_REFRESH_TOKEN } = this.env;
|
|
230
238
|
// Shared login: no app secret on this computer; the login service holds it and swaps the refresh token.
|
|
@@ -250,7 +258,7 @@ export class SnapClient {
|
|
|
250
258
|
client_secret: SNAP_CLIENT_SECRET,
|
|
251
259
|
refresh_token: SNAP_REFRESH_TOKEN,
|
|
252
260
|
}),
|
|
253
|
-
});
|
|
261
|
+
}, { idempotent: true });
|
|
254
262
|
const data = await res.json().catch(() => ({}));
|
|
255
263
|
if (!res.ok || !data.access_token) {
|
|
256
264
|
throw new Error(`Snap token refresh failed (${res.status}): ${data.error_description || data.error || "no detail"}`);
|