mcp-ga4 2.0.9 → 2.0.10

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.
@@ -1 +1 @@
1
- {"sha":"2bb300b","builtAt":"2026-04-09T22:09:46.643Z"}
1
+ {"sha":"0a22160","builtAt":"2026-04-09T22:24:08.905Z"}
package/dist/errors.js CHANGED
@@ -29,14 +29,21 @@ export function validateCredentials() {
29
29
  missing.push("GA4_PROPERTY_ID");
30
30
  if (!process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim())
31
31
  missing.push("GOOGLE_APPLICATION_CREDENTIALS");
32
+ // Basic format validation: credentials should have reasonable length > 5 chars
33
+ if (process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim() && process.env.GOOGLE_APPLICATION_CREDENTIALS.trim().length > 0 && process.env.GOOGLE_APPLICATION_CREDENTIALS.trim().length < 5) {
34
+ missing.push("GOOGLE_APPLICATION_CREDENTIALS (format: path too short, expected length > 5)");
35
+ }
32
36
  return { valid: missing.length === 0, missing };
33
37
  }
34
38
  export function classifyError(error) {
35
39
  const message = error?.message || String(error);
36
40
  const code = error?.code || error?.status;
41
+ // Check response body for error objects (gRPC/REST can return errors in body)
42
+ const bodyError = error?.response?.body?.error || error?.data?.error || error?.errors?.[0];
37
43
  if (code === 401 || code === 403 || code === 7 || code === 16 ||
38
44
  message.includes("PERMISSION_DENIED") || message.includes("UNAUTHENTICATED") ||
39
- message.includes("invalid_grant")) {
45
+ message.includes("invalid_grant") ||
46
+ bodyError?.code === 7 || bodyError?.code === 16) {
40
47
  return new Ga4AuthError(`GA4 auth failed: ${message}. Check credentials.`, error);
41
48
  }
42
49
  if (code === 429 || code === 8 || message.includes("RESOURCE_EXHAUSTED") || message.includes("rateLimitExceeded")) {
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import { GoogleAuth } from "google-auth-library";
11
11
  import { Ga4AuthError, Ga4RateLimitError, Ga4ServiceError, classifyError, } from "./errors.js";
12
12
  import { tools } from "./tools.js";
13
13
  import { withResilience, safeResponse, logger } from "./resilience.js";
14
+ import v8 from "v8";
14
15
  // CLI package info
15
16
  const __cliPkg = JSON.parse(readFileSync(join(dirname(new URL(import.meta.url).pathname), "..", "package.json"), "utf-8"));
16
17
  // Log build fingerprint at startup
@@ -42,6 +43,15 @@ if (process.argv.includes("--version") || process.argv.includes("-v")) {
42
43
  console.error(__cliPkg.version);
43
44
  process.exit(0);
44
45
  }
46
+ // Startup: detect npx vs direct node
47
+ if (process.argv[1]?.includes('.npm/_npx')) {
48
+ console.error("[startup] Running via npx -- first run may be slow due to package resolution");
49
+ }
50
+ // Startup: check heap size
51
+ const heapLimit = v8.getHeapStatistics().heap_size_limit;
52
+ if (heapLimit < 256 * 1024 * 1024) {
53
+ console.error(`[startup] WARNING: Heap limit is ${Math.round(heapLimit / 1024 / 1024)}MB`);
54
+ }
45
55
  // ============================================
46
56
  // ENV VAR TRIMMING
47
57
  // ============================================
@@ -2,6 +2,7 @@ import { retry, circuitBreaker, wrap, handleWhen, timeout, TimeoutStrategy, Expo
2
2
  import pino from "pino";
3
3
  export const logger = pino({
4
4
  level: process.env.LOG_LEVEL || "info",
5
+ redact: ["access_token", "refresh_token", "client_secret", "*.access_token", "*.refresh_token", "*.client_secret"],
5
6
  ...(process.env.NODE_ENV !== "test" && process.stderr.isTTY && {
6
7
  transport: {
7
8
  target: "pino-pretty",
package/dist/tools.js CHANGED
@@ -3,6 +3,7 @@ export const tools = [
3
3
  name: "ga4_get_client_context",
4
4
  description: "Get the current GA4 client context and health status based on working directory. Call this first to confirm which GA4 property you're working with.",
5
5
  inputSchema: {
6
+ additionalProperties: false,
6
7
  type: "object",
7
8
  properties: {
8
9
  working_directory: { type: "string", description: "The current working directory" },
@@ -14,6 +15,7 @@ export const tools = [
14
15
  name: "ga4_run_report",
15
16
  description: 'Query GA4 historical report. Common patterns: top pages (dimensions="pagePath", metrics="screenPageViews"), traffic sources (dimensions="sessionSource,sessionMedium", metrics="sessions,totalUsers"), daily trend (dimensions="date", metrics="sessions").',
16
17
  inputSchema: {
18
+ additionalProperties: false,
17
19
  type: "object",
18
20
  properties: {
19
21
  property_id: { type: "string", description: "GA4 property ID (numeric)" },
@@ -32,6 +34,7 @@ export const tools = [
32
34
  name: "ga4_realtime_report",
33
35
  description: "Query GA4 Realtime Report (last 30 minutes).",
34
36
  inputSchema: {
37
+ additionalProperties: false,
35
38
  type: "object",
36
39
  properties: {
37
40
  property_id: { type: "string", description: "GA4 property ID (numeric)" },
@@ -46,6 +49,7 @@ export const tools = [
46
49
  name: "ga4_list_custom_dimensions",
47
50
  description: "List all registered custom dimensions for a GA4 property.",
48
51
  inputSchema: {
52
+ additionalProperties: false,
49
53
  type: "object",
50
54
  properties: {
51
55
  property_id: { type: "string", description: "GA4 property ID (numeric)" },
@@ -57,6 +61,7 @@ export const tools = [
57
61
  name: "ga4_create_custom_dimension",
58
62
  description: "Register a new custom dimension in a GA4 property.",
59
63
  inputSchema: {
64
+ additionalProperties: false,
60
65
  type: "object",
61
66
  properties: {
62
67
  property_id: { type: "string", description: "GA4 property ID (numeric)" },
@@ -72,6 +77,7 @@ export const tools = [
72
77
  name: "ga4_list_custom_metrics",
73
78
  description: "List all registered custom metrics for a GA4 property.",
74
79
  inputSchema: {
80
+ additionalProperties: false,
75
81
  type: "object",
76
82
  properties: {
77
83
  property_id: { type: "string", description: "GA4 property ID (numeric)" },
@@ -83,6 +89,7 @@ export const tools = [
83
89
  name: "ga4_list_data_streams",
84
90
  description: "List all data streams for a GA4 property.",
85
91
  inputSchema: {
92
+ additionalProperties: false,
86
93
  type: "object",
87
94
  properties: {
88
95
  property_id: { type: "string", description: "GA4 property ID (numeric)" },
@@ -94,6 +101,7 @@ export const tools = [
94
101
  name: "ga4_send_feedback",
95
102
  description: "Send feedback about the GA4 MCP tools. Use when a query didn't work as expected.",
96
103
  inputSchema: {
104
+ additionalProperties: false,
97
105
  type: "object",
98
106
  properties: {
99
107
  feedback_type: { type: "string", description: "One of: bug, feature, question" },
@@ -107,6 +115,7 @@ export const tools = [
107
115
  name: "ga4_suggest_improvement",
108
116
  description: "Log a GA4 query pattern that didn't work well, so it can be improved.",
109
117
  inputSchema: {
118
+ additionalProperties: false,
110
119
  type: "object",
111
120
  properties: {
112
121
  failed_query: { type: "string", description: "The natural language question the user asked" },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-ga4",
3
3
  "mcpName": "io.github.mharnett/ga4",
4
- "version": "2.0.9",
4
+ "version": "2.0.10",
5
5
  "description": "MCP server for Google Analytics 4 - query GA4 data with natural language via Claude.",
6
6
  "main": "dist/index.js",
7
7
  "bin": {