mcp-ga4 2.0.3 → 2.0.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/README.md +1 -8
- package/dist/build-info.json +1 -1
- package/dist/index.js +9 -1
- package/dist/resilience.js +42 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ npm install mcp-ga4
|
|
|
19
19
|
Or clone the repository:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
git clone https://github.com/
|
|
22
|
+
git clone https://github.com/mharnett/mcp-ga4.git
|
|
23
23
|
cd mcp-ga4
|
|
24
24
|
npm install
|
|
25
25
|
npm run build
|
|
@@ -36,13 +36,6 @@ GA4_PROPERTY_ID=123456789
|
|
|
36
36
|
GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
For OAuth credentials instead of a service account:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
GA4_PROPERTY_ID=123456789
|
|
43
|
-
GA4_CREDENTIALS_FILE=/path/to/oauth-credentials.json
|
|
44
|
-
```
|
|
45
|
-
|
|
46
39
|
### Mode 2: Multi-Client (config.json)
|
|
47
40
|
|
|
48
41
|
Create a `config.json` in the project root to map multiple GA4 properties to project directories. The server auto-detects which property to use based on the caller's working directory.
|
package/dist/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"sha":"
|
|
1
|
+
{"sha":"9b66c73","builtAt":"2026-04-09T21:19:01.910Z"}
|
package/dist/index.js
CHANGED
|
@@ -314,7 +314,7 @@ Metrics: sessions, totalUsers, newUsers, activeUsers, screenPageViews,
|
|
|
314
314
|
|
|
315
315
|
## Date Formats
|
|
316
316
|
Use YYYY-MM-DD or relative: "today", "yesterday", "7daysAgo", "30daysAgo", "90daysAgo"`;
|
|
317
|
-
const server = new Server({ name:
|
|
317
|
+
const server = new Server({ name: __cliPkg.name, version: __cliPkg.version }, { capabilities: { tools: {} } });
|
|
318
318
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
|
|
319
319
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
320
320
|
const { name, arguments: args } = request.params;
|
|
@@ -443,4 +443,12 @@ async function main() {
|
|
|
443
443
|
await server.connect(transport);
|
|
444
444
|
console.error("[startup] MCP GA4 server running");
|
|
445
445
|
}
|
|
446
|
+
process.on("SIGTERM", () => {
|
|
447
|
+
console.error("[shutdown] SIGTERM received, exiting");
|
|
448
|
+
process.exit(0);
|
|
449
|
+
});
|
|
450
|
+
process.on("SIGINT", () => {
|
|
451
|
+
console.error("[shutdown] SIGINT received, exiting");
|
|
452
|
+
process.exit(0);
|
|
453
|
+
});
|
|
446
454
|
main().catch(console.error);
|
package/dist/resilience.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { retry, circuitBreaker, wrap,
|
|
1
|
+
import { retry, circuitBreaker, wrap, handleWhen, timeout, TimeoutStrategy, ExponentialBackoff, ConsecutiveBreaker, } from "cockatiel";
|
|
2
2
|
import pino from "pino";
|
|
3
3
|
export const logger = pino({
|
|
4
4
|
level: process.env.LOG_LEVEL || "info",
|
|
@@ -15,28 +15,55 @@ export const logger = pino({
|
|
|
15
15
|
});
|
|
16
16
|
const MAX_RESPONSE_SIZE = 200_000;
|
|
17
17
|
export function safeResponse(data, context) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
return
|
|
18
|
+
let current = data;
|
|
19
|
+
for (let pass = 0; pass < 10; pass++) {
|
|
20
|
+
const jsonStr = JSON.stringify(current);
|
|
21
|
+
const sizeBytes = Buffer.byteLength(jsonStr, "utf-8");
|
|
22
|
+
if (sizeBytes <= MAX_RESPONSE_SIZE)
|
|
23
|
+
return current;
|
|
24
|
+
logger.warn({ sizeBytes, maxSize: MAX_RESPONSE_SIZE, context, pass }, "Response exceeds size limit, truncating");
|
|
25
|
+
if (Array.isArray(current)) {
|
|
26
|
+
current = current.slice(0, Math.max(1, Math.floor(current.length * 0.5)));
|
|
27
|
+
continue;
|
|
24
28
|
}
|
|
25
|
-
if (typeof
|
|
26
|
-
const obj =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
if (typeof current === "object" && current !== null) {
|
|
30
|
+
const obj = current;
|
|
31
|
+
let truncated = false;
|
|
32
|
+
for (const key of ["items", "results", "data", "rows", "tags", "triggers", "variables"]) {
|
|
33
|
+
if (Array.isArray(obj[key]) && obj[key].length > 1) {
|
|
29
34
|
obj[key] = obj[key].slice(0, Math.max(1, Math.floor(obj[key].length * 0.5)));
|
|
30
|
-
|
|
35
|
+
if ("count" in obj)
|
|
36
|
+
obj.count = obj[key].length;
|
|
37
|
+
if ("row_count" in obj)
|
|
38
|
+
obj.row_count = obj[key].length;
|
|
39
|
+
obj.truncated = true;
|
|
40
|
+
truncated = true;
|
|
41
|
+
break;
|
|
31
42
|
}
|
|
32
43
|
}
|
|
44
|
+
if (truncated)
|
|
45
|
+
continue;
|
|
33
46
|
}
|
|
47
|
+
break;
|
|
34
48
|
}
|
|
35
|
-
return
|
|
49
|
+
return current;
|
|
36
50
|
}
|
|
37
51
|
const backoff = new ExponentialBackoff({ initialDelay: 100, maxDelay: 5_000 });
|
|
38
|
-
const
|
|
39
|
-
const
|
|
52
|
+
const isTransient = handleWhen((err) => {
|
|
53
|
+
const msg = (err?.message || "").toLowerCase();
|
|
54
|
+
const code = err?.code || err?.status;
|
|
55
|
+
if (code === 401 || code === 403 || code === 7 || code === 16)
|
|
56
|
+
return false;
|
|
57
|
+
if (msg.includes("unauthenticated") || msg.includes("permission_denied") || msg.includes("invalid_grant"))
|
|
58
|
+
return false;
|
|
59
|
+
if (code === 429 || msg.includes("rate"))
|
|
60
|
+
return true;
|
|
61
|
+
if (code >= 400 && code < 500)
|
|
62
|
+
return false;
|
|
63
|
+
return true;
|
|
64
|
+
});
|
|
65
|
+
const retryPolicy = retry(isTransient, { maxAttempts: 3, backoff });
|
|
66
|
+
const circuitBreakerPolicy = circuitBreaker(isTransient, { halfOpenAfter: 60_000, breaker: new ConsecutiveBreaker(5) });
|
|
40
67
|
const timeoutPolicy = timeout(30_000, TimeoutStrategy.Cooperative);
|
|
41
68
|
const policy = wrap(timeoutPolicy, circuitBreakerPolicy, retryPolicy);
|
|
42
69
|
export async function withResilience(fn, operationName) {
|
package/package.json
CHANGED