mcp-google-tagmanager 0.1.0 → 0.1.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/README.md +4 -4
- package/dist/index.js +19 -2
- package/dist/telemetry.js +120 -0
- package/package.json +1 -1
- package/test/dist-smoke.test.js +3 -2
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ clicking through the web UI.
|
|
|
23
23
|
-e GOOGLE_TAGMANAGER_CLIENT_ID=your_client_id \
|
|
24
24
|
-e GOOGLE_TAGMANAGER_CLIENT_SECRET=your_client_secret \
|
|
25
25
|
-e GOOGLE_TAGMANAGER_REFRESH_TOKEN=your_refresh_token \
|
|
26
|
-
-- npx -y mcp-google-tagmanager
|
|
26
|
+
-- npx -y mcp-google-tagmanager@latest
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
3. Ask the assistant: "List my GTM containers and show which tags fire on page view."
|
|
@@ -84,7 +84,7 @@ claude mcp add google-tagmanager \
|
|
|
84
84
|
-e GOOGLE_TAGMANAGER_CLIENT_ID=your_client_id \
|
|
85
85
|
-e GOOGLE_TAGMANAGER_CLIENT_SECRET=your_client_secret \
|
|
86
86
|
-e GOOGLE_TAGMANAGER_REFRESH_TOKEN=your_refresh_token \
|
|
87
|
-
-- npx -y mcp-google-tagmanager
|
|
87
|
+
-- npx -y mcp-google-tagmanager@latest
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
</details>
|
|
@@ -99,7 +99,7 @@ claude mcp add google-tagmanager \
|
|
|
99
99
|
"mcpServers": {
|
|
100
100
|
"google-tagmanager": {
|
|
101
101
|
"command": "npx",
|
|
102
|
-
"args": ["-y", "mcp-google-tagmanager"],
|
|
102
|
+
"args": ["-y", "mcp-google-tagmanager@latest"],
|
|
103
103
|
"env": {
|
|
104
104
|
"GOOGLE_TAGMANAGER_CLIENT_ID": "your_client_id",
|
|
105
105
|
"GOOGLE_TAGMANAGER_CLIENT_SECRET": "your_client_secret",
|
|
@@ -122,7 +122,7 @@ claude mcp add google-tagmanager \
|
|
|
122
122
|
"mcpServers": {
|
|
123
123
|
"google-tagmanager": {
|
|
124
124
|
"command": "npx",
|
|
125
|
-
"args": ["-y", "mcp-google-tagmanager"],
|
|
125
|
+
"args": ["-y", "mcp-google-tagmanager@latest"],
|
|
126
126
|
"env": {
|
|
127
127
|
"GOOGLE_TAGMANAGER_CLIENT_ID": "your_client_id",
|
|
128
128
|
"GOOGLE_TAGMANAGER_CLIENT_SECRET": "your_client_secret",
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { TagManagerClient } from "./client.js";
|
|
6
6
|
import { ConfigError, loadConfig } from "./config.js";
|
|
7
|
+
import { instrumentToolCalls, Telemetry } from "./telemetry.js";
|
|
7
8
|
import { registerAccountTools } from "./tools/accounts.js";
|
|
8
9
|
import { registerBuiltInVariableTools } from "./tools/builtins.js";
|
|
9
10
|
import { registerContainerTools } from "./tools/containers.js";
|
|
@@ -21,7 +22,13 @@ function readVersion() {
|
|
|
21
22
|
return "0.0.0";
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Loads the config, reporting the drop-off if it is missing. An unconfigured
|
|
27
|
+
* server dies before the MCP handshake, so this ping is the only trace such an
|
|
28
|
+
* install ever leaves — and it has to be awaited, or process.exit() below would
|
|
29
|
+
* kill the request in flight.
|
|
30
|
+
*/
|
|
31
|
+
async function loadConfigOrExit(telemetry) {
|
|
25
32
|
try {
|
|
26
33
|
return loadConfig();
|
|
27
34
|
}
|
|
@@ -29,16 +36,26 @@ function loadConfigOrExit() {
|
|
|
29
36
|
if (!(err instanceof ConfigError))
|
|
30
37
|
throw err;
|
|
31
38
|
console.error(`Error: ${err.message}`);
|
|
39
|
+
await telemetry.sendBlocking("startup_failed", { reason: err.reason });
|
|
32
40
|
process.exit(1);
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
async function main() {
|
|
36
|
-
|
|
44
|
+
// Anonymous usage pings (ids/names/versions only, never credentials or
|
|
45
|
+
// arguments); opt out with ASKADS_TELEMETRY=0. Built before the config so
|
|
46
|
+
// missing credentials can be reported; wired to the server before tools register.
|
|
47
|
+
const telemetry = new Telemetry(readVersion());
|
|
48
|
+
const config = await loadConfigOrExit(telemetry);
|
|
37
49
|
const client = new TagManagerClient(config);
|
|
38
50
|
const server = new McpServer({
|
|
39
51
|
name: "mcp-google-tagmanager",
|
|
40
52
|
version: readVersion(),
|
|
41
53
|
});
|
|
54
|
+
instrumentToolCalls(server, telemetry);
|
|
55
|
+
server.server.oninitialized = () => {
|
|
56
|
+
telemetry.setClientInfo(server.server.getClientVersion());
|
|
57
|
+
telemetry.send("server_start");
|
|
58
|
+
};
|
|
42
59
|
registerAccountTools(server, client);
|
|
43
60
|
registerContainerTools(server, client);
|
|
44
61
|
registerWorkspaceTools(server, client);
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anonymous usage telemetry — fire-and-forget pings to usage.gistrec.cloud.
|
|
3
|
+
*
|
|
4
|
+
* Privacy contract (mirrored by the receiver): only an anonymous random
|
|
5
|
+
* instance id, event/tool names, a fixed-vocabulary failure reason and
|
|
6
|
+
* environment versions ever leave the machine. The OAuth credentials,
|
|
7
|
+
* account/container ids and paths, tool arguments, prompts and the names or
|
|
8
|
+
* values of environment variables are never read, serialized or sent. Sends
|
|
9
|
+
* are capped at 2 s and swallow every error — telemetry must never affect the
|
|
10
|
+
* server's operation. Opt out for every server by this author at once:
|
|
11
|
+
* ASKADS_TELEMETRY=0 (also accepts false/off/no).
|
|
12
|
+
*/
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
const ENDPOINT = "https://usage.gistrec.cloud/v1/events";
|
|
18
|
+
const APP = "mcp-google-tagmanager";
|
|
19
|
+
const SEND_TIMEOUT_MS = 2000;
|
|
20
|
+
export function telemetryEnabled(env = process.env) {
|
|
21
|
+
const value = (env.ASKADS_TELEMETRY ?? "").trim().toLowerCase();
|
|
22
|
+
return !["0", "false", "off", "no"].includes(value);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Stable anonymous installation id, persisted under the user's config dir.
|
|
26
|
+
* Any filesystem failure degrades to an ephemeral id: the ping still counts
|
|
27
|
+
* today's activity, just not installation uniqueness across restarts.
|
|
28
|
+
*/
|
|
29
|
+
function loadInstanceId() {
|
|
30
|
+
try {
|
|
31
|
+
const base = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
32
|
+
const dir = join(base, APP);
|
|
33
|
+
const file = join(dir, "instance-id");
|
|
34
|
+
try {
|
|
35
|
+
const existing = readFileSync(file, "utf8").trim();
|
|
36
|
+
if (/^[0-9a-f]{8}-[0-9a-f-]{27}$/.test(existing))
|
|
37
|
+
return existing;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// first run — fall through and mint one
|
|
41
|
+
}
|
|
42
|
+
const id = randomUUID();
|
|
43
|
+
mkdirSync(dir, { recursive: true });
|
|
44
|
+
writeFileSync(file, `${id}\n`);
|
|
45
|
+
return id;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return randomUUID();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class Telemetry {
|
|
52
|
+
appVersion;
|
|
53
|
+
enabled;
|
|
54
|
+
fetchImpl;
|
|
55
|
+
instanceId;
|
|
56
|
+
clientInfo;
|
|
57
|
+
constructor(appVersion, enabled = telemetryEnabled(), fetchImpl = fetch) {
|
|
58
|
+
this.appVersion = appVersion;
|
|
59
|
+
this.enabled = enabled;
|
|
60
|
+
this.fetchImpl = fetchImpl;
|
|
61
|
+
this.instanceId = enabled ? loadInstanceId() : "";
|
|
62
|
+
}
|
|
63
|
+
/** The MCP initialize handshake tells us which agent host is on the other side. */
|
|
64
|
+
setClientInfo(info) {
|
|
65
|
+
this.clientInfo = info;
|
|
66
|
+
}
|
|
67
|
+
/** Fire-and-forget: the server's own work never waits on a ping. */
|
|
68
|
+
send(event, fields = {}) {
|
|
69
|
+
void this.post(event, fields);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The same ping, awaited. Only for the startup_failed path: that caller
|
|
73
|
+
* calls process.exit() immediately after, which would kill an in-flight
|
|
74
|
+
* fire-and-forget request before it ever left the machine.
|
|
75
|
+
*/
|
|
76
|
+
async sendBlocking(event, fields = {}) {
|
|
77
|
+
await this.post(event, fields);
|
|
78
|
+
}
|
|
79
|
+
async post(event, fields) {
|
|
80
|
+
if (!this.enabled)
|
|
81
|
+
return;
|
|
82
|
+
const body = JSON.stringify({
|
|
83
|
+
app: APP,
|
|
84
|
+
event,
|
|
85
|
+
instance_id: this.instanceId,
|
|
86
|
+
app_version: this.appVersion,
|
|
87
|
+
client_name: this.clientInfo?.name,
|
|
88
|
+
client_version: this.clientInfo?.version,
|
|
89
|
+
tool: fields.tool,
|
|
90
|
+
reason: fields.reason,
|
|
91
|
+
node_version: process.version,
|
|
92
|
+
os: process.platform,
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
await this.fetchImpl(ENDPOINT, {
|
|
96
|
+
method: "POST",
|
|
97
|
+
headers: { "Content-Type": "application/json" },
|
|
98
|
+
body,
|
|
99
|
+
signal: AbortSignal.timeout(SEND_TIMEOUT_MS),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// network failure, timeout abort or a synchronous throw — all silent
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Count every tool invocation by name. Wraps registerTool once, before the
|
|
109
|
+
* domain modules register their tools, so no per-tool wiring is needed.
|
|
110
|
+
* Only the tool *name* is recorded — arguments never reach telemetry.
|
|
111
|
+
*/
|
|
112
|
+
export function instrumentToolCalls(server, telemetry) {
|
|
113
|
+
const original = server.registerTool.bind(server);
|
|
114
|
+
// registerTool's generic signature does not survive a wrapper; the runtime
|
|
115
|
+
// shape (name, config, callback) is stable per SDK contract.
|
|
116
|
+
server.registerTool = ((name, config, callback) => original(name, config, ((...args) => {
|
|
117
|
+
telemetry.send("tool_call", { tool: name });
|
|
118
|
+
return callback(...args);
|
|
119
|
+
})));
|
|
120
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-google-tagmanager",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|
package/test/dist-smoke.test.js
CHANGED
|
@@ -35,7 +35,7 @@ test("dist binary completes a real MCP handshake over stdio and lists every tool
|
|
|
35
35
|
const transport = new StdioClientTransport({
|
|
36
36
|
command: process.execPath,
|
|
37
37
|
args: [fileURLToPath(new URL("../dist/index.js", import.meta.url))],
|
|
38
|
-
env: { ...process.env, GOOGLE_TAGMANAGER_ACCESS_TOKEN: "smoke-test-token" },
|
|
38
|
+
env: { ...process.env, GOOGLE_TAGMANAGER_ACCESS_TOKEN: "smoke-test-token", ASKADS_TELEMETRY: "0" },
|
|
39
39
|
stderr: "ignore",
|
|
40
40
|
});
|
|
41
41
|
const client = new Client({ name: "dist-smoke", version: "0.0.0" });
|
|
@@ -58,7 +58,8 @@ test("dist binary completes a real MCP handshake over stdio and lists every tool
|
|
|
58
58
|
|
|
59
59
|
test("dist binary exits with an error when unconfigured", async () => {
|
|
60
60
|
const { spawn } = await import("node:child_process");
|
|
61
|
-
|
|
61
|
+
// Opt out so the startup_failed ping never leaves the test machine.
|
|
62
|
+
const env = { ...process.env, ASKADS_TELEMETRY: "0" };
|
|
62
63
|
delete env.GOOGLE_TAGMANAGER_ACCESS_TOKEN;
|
|
63
64
|
delete env.GOOGLE_TAGMANAGER_CLIENT_ID;
|
|
64
65
|
delete env.GOOGLE_TAGMANAGER_CLIENT_SECRET;
|