
Gtm Ga4
io.github.mharnettPublished by GitHub account mharnettv1.0.1Updated Oct 25, 2026
GTM + GA4 MCP: tag management, consent auditing, workspace versioning, reports.
Overview
A local MCP server that lets an assistant manage Google Tag Manager tags, triggers and variables, audit consent, and run GA4 reports.
- What you can do
- List, read, create and update GTM tags, and list triggers and variables in a workspace. Audit tags for consent configuration compliance. Preview the current workspace and create a container version from it. Run GA4 reports and realtime reports, and list or create GA4 custom dimensions.
- When to use it
- Useful when you work with Google Tag Manager and GA4 and want an assistant to inspect or edit container configuration, check consent setup, or pull analytics reports without switching to the web consoles.
- Requirements
- Runs locally via npm (npx mcp-gtm-ga4) or a built clone, on Node.js. Needs a Google credential JSON key file path in GOOGLE_APPLICATION_CREDENTIALS (service account or authorized-user OAuth), plus GTM_ACCOUNT_ID, GTM_CONTAINER_ID and GA4_PROPERTY_ID. Optional GTM_SANDBOX_WORKSPACE_ID and MCP_SERVER_NAME. Network access to Google APIs.
Installation
In SourceWeft
- Open Gtm Ga4 in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
mcp-gtm-ga4
MCP server for Google Tag Manager and GA4 -- tag management, consent auditing, workspace versioning, and analytics reporting via Claude.
Features
- 14 tools spanning GTM workspace management (tags, triggers, variables), consent compliance auditing, workspace preview/versioning, and GA4 reporting
- Sandbox safety -- all write operations verify they target the resolved workspace, refusing to write to non-sandbox workspaces
- Multi-client support -- configure per-client via environment variables
- Auto-detects Default Workspace ID -- no need to manually specify workspace IDs unless using a custom sandbox
Installation
Or clone and build:
Configuration
Security: Never share your .mcp.json file or commit it to git -- it may contain API credentials. Add .mcp.json to your .gitignore.
Runtime configuration is via environment variables.
See config.example.json for a reference template. The only value read from disk is oauth.scope (in an optional config.json) — the single source of truth for the OAuth scope the onboarding paths request. If no config.json is present, the committed minimum scope is used.
Authentication
This MCP supports two auth models. Both feed the same GOOGLE_APPLICATION_CREDENTIALS runtime path.
Precedence & mechanism
There is no runtime service-account-vs-OAuth toggle. Both models converge on a
single slot — GOOGLE_APPLICATION_CREDENTIALS — which the runtime hands to
GoogleAuth({ keyFile }). Whichever file you point that env var at is the
credential:
- a service-account JSON key (option 1 below), or
- the
authorized_userkeyfile theauthsubcommand writes (option 2) — a file that plugs into the exact same slot.
So the only real precedence rule is failure handling: an explicitly-configured
keyfile is used; when GOOGLE_APPLICATION_CREDENTIALS is unset the server fails
loudly at startup with an onboarding error naming both the service-account path
and the auth OAuth helper. It deliberately does not fall back to Google's
Application Default Credentials (gcloud user creds / GCE metadata server) — no
silent machine-local default, no silent runtime failover.
1. Service account (primary, recommended for unattended/server use)
Create a service account in your GCP project, download its JSON key, grant it the
GTM container role (on the target GTM container) and GA4 property access, and
point GOOGLE_APPLICATION_CREDENTIALS at the key file. No OAuth flow, no browser,
no refresh token. This is the recommended path for headless/server/unattended
deployments.
2. User OAuth (interactive, for users without a service account)
If you can't use a service account, mint a user credential with your own Google OAuth client (a "Desktop app" OAuth 2.0 Client ID created in your own GCP project — enable the Tag Manager API and the Google Analytics Admin + Data APIs). Two equivalent onboarding commands, both hardened with PKCE (RFC 7636, S256) and both requesting the scope from config.json (oauth.scope) so they never drift:
The refresh token / credential is written by you and read from your environment only. Nothing is shared and no OAuth client keyfile is bundled. Do not run the helper with stdout redirected to a shared log — the refresh token is printed to stdout by design.
OAuth scopes requested
The onboarding paths request exactly the scopes this MCP's tools use (from config.example.json → oauth.scope):
tagmanager.readonly is intentionally not requested — the edit scopes already grant read access.
Usage
Claude Code (.mcp.json)
npx
Claude Desktop: Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows).
Safety
Workspace sandbox protection
All write operations (gtm_update_tag, gtm_create_tag, gtm_preview, gtm_create_version) verify they target the resolved workspace before executing. If a request attempts to write to a different workspace, the server returns a SafetyError and blocks the operation.
This prevents accidental production changes when the MCP server is configured against a sandbox workspace.
Tools
GTM Tags
GTM Structure
GTM Consent
GTM Workspace
GA4 Reports
GA4 Admin
Architecture
- GTM API:
googleapis(Tag Manager v2) - GA4 Data:
@google-analytics/data(BetaAnalyticsDataClient) - GA4 Admin:
@google-analytics/admin(AnalyticsAdminServiceClient) - Resilience:
cockatiel(retry, circuit breaker, timeout policies) - Logging:
pinowithpino-pretty - Transport: MCP SDK stdio transport
License
MIT
Author
Built by Mark Harnett / drak-marketing
Source: README.md at commit 539cc67
Tools
0Version history
1- v1.0.1LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts