mcp-ga4 2.0.10 → 2.0.12
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 +2 -0
- package/dist/build-info.json +1 -1
- package/dist/index.js +11 -2
- package/dist/resilience.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@ npm run build
|
|
|
27
27
|
|
|
28
28
|
## Configuration
|
|
29
29
|
|
|
30
|
+
**Security:** Never share your `.mcp.json` file or commit it to git -- it may contain API credentials. Add `.mcp.json` to your `.gitignore`.
|
|
31
|
+
|
|
30
32
|
### Mode 1: Single Property (env vars)
|
|
31
33
|
|
|
32
34
|
Set environment variables to connect to a single GA4 property:
|
package/dist/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"sha":"
|
|
1
|
+
{"sha":"3bd9339","builtAt":"2026-04-09T23:11:56.896Z"}
|
package/dist/index.js
CHANGED
|
@@ -184,12 +184,19 @@ class Ga4Manager {
|
|
|
184
184
|
const mets = (options.metrics || "eventCount").split(",").map(m => ({ name: m.trim() })).filter(m => m.name);
|
|
185
185
|
const startDate = options.startDate || "7daysAgo";
|
|
186
186
|
const endDate = options.endDate || "today";
|
|
187
|
+
// Future date validation (skip relative dates like "7daysAgo")
|
|
188
|
+
const today_ga4 = new Date().toISOString().slice(0, 10);
|
|
189
|
+
if (startDate && !startDate.includes("daysAgo") && !startDate.includes("yesterday") && !startDate.includes("today") && startDate > today_ga4) {
|
|
190
|
+
return { rows: [], row_count: 0, error: `start_date "${startDate}" is in the future. Reports only cover historical data.` };
|
|
191
|
+
}
|
|
192
|
+
// Cap limit at 10,000 for sanity (GA4 API max is 100,000)
|
|
193
|
+
const limit = Math.min(options.limit || 100, 10000);
|
|
187
194
|
const request = {
|
|
188
195
|
property: `properties/${propertyId}`,
|
|
189
196
|
dimensions: dims,
|
|
190
197
|
metrics: mets,
|
|
191
198
|
dateRanges: [{ startDate, endDate }],
|
|
192
|
-
limit
|
|
199
|
+
limit,
|
|
193
200
|
};
|
|
194
201
|
if (options.dimensionFilter && options.dimensionFilter.includes("==")) {
|
|
195
202
|
const [field, value] = options.dimensionFilter.split("==", 2);
|
|
@@ -443,9 +450,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
443
450
|
else {
|
|
444
451
|
response.details = rawError.stack;
|
|
445
452
|
}
|
|
453
|
+
// Size-limit error responses through safeResponse to prevent oversized payloads
|
|
454
|
+
const safeErrorResponse = safeResponse(response, "error");
|
|
446
455
|
return {
|
|
447
456
|
isError: true,
|
|
448
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
457
|
+
content: [{ type: "text", text: JSON.stringify(safeErrorResponse, null, 2) }],
|
|
449
458
|
};
|
|
450
459
|
}
|
|
451
460
|
});
|
package/dist/resilience.js
CHANGED
|
@@ -25,6 +25,10 @@ export function safeResponse(data, context) {
|
|
|
25
25
|
const sizeBytes = Buffer.byteLength(jsonStr, "utf-8");
|
|
26
26
|
if (sizeBytes <= MAX_RESPONSE_SIZE)
|
|
27
27
|
return current;
|
|
28
|
+
// Deep clone on first truncation pass to avoid mutating the original object
|
|
29
|
+
if (pass === 0 && typeof current === "object" && current !== null) {
|
|
30
|
+
current = JSON.parse(JSON.stringify(current));
|
|
31
|
+
}
|
|
28
32
|
logger.warn({ sizeBytes, maxSize: MAX_RESPONSE_SIZE, context, pass }, "Response exceeds size limit, truncating");
|
|
29
33
|
if (Array.isArray(current)) {
|
|
30
34
|
current = current.slice(0, Math.max(1, Math.floor(current.length * 0.5)));
|
package/package.json
CHANGED