mcp-google-tagmanager 1.3.3 → 1.3.4

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/dist/auth.js CHANGED
@@ -26,6 +26,15 @@ export class TokenProvider {
26
26
  this.config = config;
27
27
  this.fallback = fallback;
28
28
  }
29
+ /** Mirrors the priority of {@link getAccessToken}: env access token, env refresh trio, stored login. */
30
+ source() {
31
+ if (this.config.accessToken)
32
+ return "access_token";
33
+ if (!this.config.clientId && !this.config.clientSecret && !this.config.refreshToken) {
34
+ return this.fallback ? "login" : "none";
35
+ }
36
+ return "refresh_token";
37
+ }
29
38
  async getAccessToken() {
30
39
  if (this.config.accessToken)
31
40
  return this.config.accessToken;
package/dist/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TokenProvider } from "./auth.js";
2
- import { isQuotaError, TagManagerError } from "./types.js";
2
+ import { isQuotaError, isScopeError, TagManagerError } from "./types.js";
3
3
  import { DEFAULT_BASE } from "./config.js";
4
4
  const ENTITY_COLLECTION = {
5
5
  tag: "tags",
@@ -146,8 +146,10 @@ export class TagManagerClient {
146
146
  await delay(this.backoffMs(attempt, res));
147
147
  continue;
148
148
  }
149
- if (!res.ok)
150
- throw new TagManagerError(res.status, data);
149
+ if (!res.ok) {
150
+ const hint = res.status === 403 && isScopeError(data) ? SCOPE_HINTS[this.tokens.source()] : undefined;
151
+ throw new TagManagerError(res.status, data, hint);
152
+ }
151
153
  return data;
152
154
  }
153
155
  }
@@ -234,6 +236,27 @@ export class TagManagerClient {
234
236
  return this.request("GET", `accounts/${accountId}/containers/${containerId}/versions:live`);
235
237
  }
236
238
  }
239
+ const SCOPES_NEEDED = "tagmanager.edit.containers, tagmanager.edit.containerversions and tagmanager.publish " +
240
+ "(Google grants each one separately)";
241
+ /**
242
+ * What to do about "insufficient authentication scopes", by token source. The API's
243
+ * message names neither the scope nor the fix, and the fix differs: a stored in-chat
244
+ * login is repaired by logging in again (a login made before 1.3.3 never asked for
245
+ * edit.containerversions, and the consent screen lets the user untick a permission),
246
+ * while environment credentials outrank a stored login, so there only a new token helps.
247
+ */
248
+ export const SCOPE_HINTS = {
249
+ login: "the stored login was granted without an OAuth scope this call needs. Call start_login again, have the " +
250
+ "user approve every permission on the Google consent screen, then finish_login and retry this call — " +
251
+ "no restart is needed",
252
+ refresh_token: "the refresh token in GOOGLE_TAGMANAGER_REFRESH_TOKEN was issued without an OAuth scope this call needs. " +
253
+ `Issue a new one that includes ${SCOPES_NEEDED}, set it and restart the server. start_login will not ` +
254
+ "help: environment credentials take priority over a stored login",
255
+ access_token: "the access token in GOOGLE_TAGMANAGER_ACCESS_TOKEN was issued without an OAuth scope this call needs. " +
256
+ `Issue a new one that includes ${SCOPES_NEEDED}, set it and restart the server. start_login will not ` +
257
+ "help: environment credentials take priority over a stored login",
258
+ none: undefined,
259
+ };
237
260
  /** Drops keys whose value is `undefined` so they are not sent to the API. */
238
261
  function compact(obj) {
239
262
  return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined));
package/dist/types.js CHANGED
@@ -17,8 +17,13 @@
17
17
  export class TagManagerError extends Error {
18
18
  status;
19
19
  body;
20
- constructor(status, body) {
21
- super(`HTTP ${status}: ${formatErrorBody(body)}`);
20
+ /**
21
+ * `hint` is this server's own advice on top of the API's words (what to do about a
22
+ * missing OAuth scope). It goes after a "; " so the API's text stays intact and the
23
+ * telemetry excerpt, which stops at ";", stays the API's own message.
24
+ */
25
+ constructor(status, body, hint) {
26
+ super(`HTTP ${status}: ${formatErrorBody(body)}${hint ? `; ${hint}` : ""}`);
22
27
  this.name = "TagManagerError";
23
28
  this.status = status;
24
29
  this.body = body;
@@ -84,3 +89,26 @@ export function isQuotaError(body) {
84
89
  return true;
85
90
  return typeof e.message === "string" && /quota|rate limit/i.test(e.message);
86
91
  }
92
+ /**
93
+ * True when a 403 body says the access token lacks an OAuth scope, as opposed to
94
+ * the Google account lacking a GTM permission. Google marks it with the ErrorInfo
95
+ * reason ACCESS_TOKEN_SCOPE_INSUFFICIENT in `error.details` and the fixed message
96
+ * "Request had insufficient authentication scopes."; either one is enough. The
97
+ * legacy `errors[].reason` (insufficientPermissions) is deliberately not matched:
98
+ * it is too close to a genuine permission denial to hang re-login advice on.
99
+ */
100
+ export function isScopeError(body) {
101
+ if (!body || typeof body !== "object")
102
+ return false;
103
+ const err = body.error;
104
+ if (!err || typeof err !== "object")
105
+ return false;
106
+ const e = err;
107
+ if (Array.isArray(e.details) &&
108
+ e.details.some((item) => item &&
109
+ typeof item === "object" &&
110
+ item.reason === "ACCESS_TOKEN_SCOPE_INSUFFICIENT")) {
111
+ return true;
112
+ }
113
+ return typeof e.message === "string" && /insufficient authentication scopes/i.test(e.message);
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-google-tagmanager",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "MCP server for the Google Tag Manager API v2 — accounts, containers, workspaces, tags, triggers, variables, versions and publishing. For Claude, Cursor, Codex and other AI clients.",
5
5
  "mcpName": "io.github.A1-x-Tech/mcp-google-tagmanager",
6
6
  "type": "module",