Skip to main content
Glama

GTM MCP Server (gtm-mcp)

CI

MCP server for Google Tag Manager. Runs on your own computer, talks to the Tag Manager API v2 with your own Google account. 34 tools: 23 🟢 read/audit tools, 10 🟡 workspace-write tools (every one previews with dry_run=true first) and exactly one 🔴 tool, gtm_publish_version. No delete and no user-management tools exist.

Sister project: GA4-MCP-Server (Google Analytics 4). Both servers share the small Python library marketing-mcp-common (Google OAuth desktop flow, httpx client with retry + rate limiter, error mapping, redaction, audit log), which lives in that repo under common/ and is installed automatically from a pinned tag (see pyproject.toml). You can use the same Google Cloud OAuth client for both servers. Status, scope decisions and log of this server: PROJECT.md; programme-wide conventions (risk tiers, auth rules, access roles): GA4-MCP-Server/PROJECT.md.

1. Setup (one time)

1a. Owner: Google Cloud project

  1. Open the Cloud project that holds your OAuth client (the ga4-mcp one works) → APIs & Services → Library → enable Tag Manager API.

  2. Google Auth Platform → Data Access (Scopes) → add https://www.googleapis.com/auth/tagmanager.readonly. Only if people will use the write tools, also add tagmanager.edit.containers, tagmanager.edit.containerversions, tagmanager.publish.

  3. The existing Desktop app OAuth client id/secret is reused — share it with the team through a password manager, never through chat.

1b. Everyone: install uv, sign in

# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# read-only profile (default — enough for audits, listing, coverage checks)
uvx --from "git+https://github.com/Mezbaul-Hasan/GTM-MCP-Server" gtm-mcp auth
# read + write + publish profile (only for people who will change containers)
uvx --from "git+https://github.com/Mezbaul-Hasan/GTM-MCP-Server" gtm-mcp auth --with-writes

The browser opens → sign in → the refresh token is saved to ~/.gtm-mcp/config.json (readable only by you). gtm-mcp status shows the profile (read-only / read+write+publish); gtm-mcp logout revokes and deletes it.

Your Google account also needs a GTM role on the container (Read for 🟢, Edit for workspace writes, Approve/Publish for versions/publish) — the OAuth scope alone is not enough.

1c. Add to Claude Desktop / Cursor

{
  "mcpServers": {
    "gtm": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/Mezbaul-Hasan/GTM-MCP-Server", "gtm-mcp"]
    }
  }
}

First prompt to try: "Find container GTM-XXXXXXX and run a container audit."

Related MCP server: gtm-ga4-mcp

2. Tools

Tool

Tier

What it does

gtm_list_accounts

🟢

accounts visible to the signed-in user

gtm_list_containers

🟢

containers of one account, or of all accounts (≤10)

gtm_find_container

🟢

resolve GTM-XXXXXXX / G-… / AW-… to account + container + default workspace (1–2 requests); or search by name

gtm_get_container

🟢

container details (public id, usage context, domains, linked tag ids)

gtm_list_workspaces

🟢

draft workspaces

gtm_get_workspace_status

🟢

unpublished changes + merge conflicts

gtm_list_tags / gtm_get_tag

🟢

tags with type labels, paused flag, key parameters, trigger ids; full flattened parameters on get

gtm_list_triggers / gtm_get_trigger

🟢

triggers with one-line condition summaries

gtm_list_variables / gtm_get_variable

🟢

user-defined variables with summaries

gtm_list_built_in_variables

🟢

enabled built-ins

gtm_list_folders, gtm_list_templates

🟢

folders, custom/gallery templates (code not returned)

gtm_list_versions, gtm_get_version, gtm_get_live_version

🟢

version headers, one version, the live version (counts, tags by type, optional entity lists)

gtm_list_environments

🟢

environments and the version each serves (preview auth codes stripped)

gtm_container_audit

🟢

one-shot health check: UA leftovers, duplicate Google tags, dangling/unused triggers, undefined {{variables}}, placeholders, GA4 event naming, Custom HTML pixels, paused tags, unpublished changes — 5–7 requests

gtm_check_ga4_ecommerce_coverage

🟢

matrix of the 11 GA4 ecommerce events: covered live / paused only / missing / no ecommerce data, existing custom-event triggers

gtm_raw_get

🟢

GET any accounts/… path (clients, zones, transformations, gtag_config …)

gtm_auth_status

🟢

signed-in profile, requests used this session, rate-limiter state — no API call

gtm_create_workspace

🟡

new draft workspace

gtm_create_tag

🟡

any tag type from a flat {key: value} parameter dict

gtm_create_ga4_event_tag

🟡

typed GA4 event tag (gaawe); reuses or creates the Custom Event trigger; ecommerce flag on by default for ecommerce events

gtm_update_tag

🟡

pause/unpause, rename, swap triggers, merge parameters — shows a before/after diff, sends the fingerprint

gtm_create_trigger

🟡

Custom Event trigger (equals / regex) or other types with filters

gtm_create_variable

🟡

Data Layer variable, constant, or raw parameters for other types

gtm_enable_built_in_variables

🟡

enable built-ins by API type (pageUrl, clickElement, …)

gtm_revert_entity

🟡

undo this workspace's change to one entity (live container untouched)

gtm_create_version

🟡

workspace → version (not live); refuses on merge conflicts; warns that the workspace is consumed

gtm_setup_ga4_ecommerce_events

🟡

recipe: plan/apply triggers + GA4 event tags for the missing ecommerce events (optionally the Google tag)

gtm_publish_version

🔴

makes a version live — needs dry_run=false and confirm=true, the publish scope and the Publish role; returns the previous live id for rollback

Every 🟡/🔴 tool defaults to dry_run=true and returns the exact {method, path, body} it would send plus warnings; call it again with dry_run=false to apply. The read-only profile can run all dry-runs — applying fails with a clear "run gtm-mcp auth --with-writes" message.

3. Quota — why the server is deliberately slow

Google allows 25 requests per 100 seconds and 10,000 per day per Cloud project (shared by everyone using the same OAuth client). gtm-mcp therefore:

  • waits in a client-side token bucket (0.25 req/s, burst 20) before every request — GTM_MCP_RATE_LIMIT_QPS to tune;

  • caches container lookups and the default workspace per process;

  • offers audit/coverage tools that read the whole workspace in a handful of requests instead of many single calls;

  • follows nextPageToken on all lists and retries 429/5xx with back-off. gtm_auth_status shows how many requests the current session used.

4. Environment variables

Variable

Purpose

GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_REFRESH_TOKEN

use these instead of ~/.gtm-mcp/config.json (multi-account / CI); add GOOGLE_SCOPES so the server knows the profile

GTM_MCP_CONFIG_DIR

folder for config.json + audit.jsonl (default ~/.gtm-mcp)

GTM_MCP_AUDIT_DISABLED=1

turn off the local audit log

GTM_MCP_RATE_LIMIT_QPS

client-side rate (default 0.25; 0 disables waiting — tests only)

MCP_LOG_LEVEL

DEBUG / INFO / WARNING — stderr only, never payloads or tokens

5. Development

git clone https://github.com/Mezbaul-Hasan/GTM-MCP-Server && cd GTM-MCP-Server
pip install -e ".[dev]"     # also installs marketing-mcp-common from its pinned git tag
pytest -q                   # 40 tests, Tag Manager API fully mocked (respx) — no network
python server.py            # or: mcp dev server.py

Facts the code relies on (endpoints, list keys, type codes, scopes, quota): docs/platform-notes/gtm.md. Reference review that shaped the tool set: docs/platform-notes/gtm-reference-was-gtm-mcp.md.

To work on the shared library at the same time: clone GA4-MCP-Server next to this repo and pip install -e ../GA4-MCP-Server/common (pip keeps the editable copy); bump the common-vX.Y.Z tag in pyproject.toml when a new library version is needed.

6. Safety model

  • Reads never modify anything; gtm_raw_get is GET-only and limited to tagmanager.googleapis.com.

  • Writes touch a workspace only; the website changes only after gtm_create_version → gtm_publish_version.

  • Publishing is the only 🔴 tool and needs an explicit confirm=true; rollback = publish the previous version id (returned in the result).

  • Scopes: auth = tagmanager.readonly; auth --with-writes adds edit.containers, edit.containerversions, publish. delete.containers, manage.users, manage.accounts are never requested.

  • Audit log: one JSON line per tool call in ~/.gtm-mcp/audit.jsonl (tool, redacted args, duration, status).

License: MIT.

Available Tools

34 tools
gtm_auth_statusSign-in profile & quota usageA
Read-onlyIdempotent

Which scope profile is signed in (read-only vs read+write+publish), API requests made in this session and the client-side rate limiter state. Makes no API call.

Inputs: no named parameters. Returns: object

gtm_check_ga4_ecommerce_coverageGA4 ecommerce event coverageA
Read-onlyIdempotent

Which of the 11 GA4 ecommerce events (view_item_list … purchase, refund) have an active GA4 event tag with 'send ecommerce data', which are missing or paused, and which custom-event triggers already exist (3 requests). include_optional_events adds view_promotion, select_promotion, add_to_wishlist.

Inputs: container (required), workspace_id, include_optional_events. Returns: object

gtm_container_auditAudit a container workspaceA
Read-onlyIdempotent

One-shot health check of a workspace (4–6 requests total — prefer this over many single list calls): UA leftovers, duplicate Google tags, dangling/unused triggers, undefined {{variables}}, placeholder values, GA4 event naming, Custom HTML pixels, paused tags, unpublished changes. Container: GTM-XXXXXXX or accounts//containers/.

Inputs: container (required), workspace_id, include_workspace_status. Returns: object

gtm_create_ga4_event_tagCreate GA4 event tag (🟡 write)A

Typed helper for a GA4 event tag (type gaawe). measurement_id = G-XXXXXXXX or a variable reference like {{GA4 Measurement ID}}. If firing_trigger_ids is omitted, a Custom Event trigger for event_name is reused when it exists or created (dataLayer.push({event: '<event_name>'})). send_ecommerce_data defaults to true for the GA4 ecommerce events. dry_run=true (default) previews the request(s).

Inputs: container (required), event_name (required), measurement_id (required), name, +6 more. Returns: object

gtm_create_tagCreate tag (🟡 write)A

Create any tag type in the workspace. type is the GTM code (gaawe, googtag, html, awct, img, …; see gtm_list_tags output of similar tags). parameters is a flat dict {key: value} — strings become template parameters, bools boolean, ints integer, lists/dicts list/map (or pass raw GTM Parameter objects). Use trigger id 2147479553 for All Pages. For GA4 event tags prefer gtm_create_ga4_event_tag. dry_run=true (default) previews only.

Inputs: name (required), type (required), container (required), parameters (required), +7 more. Returns: object

gtm_create_triggerCreate trigger (🟡 write)A

Create a trigger. type=customEvent needs custom_event_name (the dataLayer event; use_regex=true for 'a|b'). Other types (pageview, domReady, windowLoaded, click, linkClick, historyChange, scrollDepth…) take optional filters: [{"variable": "{{Page Path}}", "op": "equals|contains|startsWith|endsWith|matchRegex", "value": "/checkout", "negate": false}]. dry_run=true (default) previews only.

Inputs: name (required), container (required), type, dry_run, +4 more. Returns: object

gtm_create_variableCreate variable (🟡 write)A

Create a user-defined variable. type=dataLayer (code v) needs data_layer_name (e.g. ecommerce.items); type=constant (code c) needs value; any other GTM type code (jsm, u, k, …) takes raw parameters. dry_run=true (default) previews only.

Inputs: name (required), container (required), type, value, +5 more. Returns: object

gtm_create_versionCreate version from workspace (🟡 write)A

Snapshot the workspace into a container version (NOT published yet). GTM deletes the workspace afterwards and creates a fresh default one. Merge conflicts block it — dry_run=true (default) shows the pending changes/conflicts.

Inputs: name (required), container (required), notes, dry_run, +1 more. Returns: object

gtm_create_workspaceCreate workspace (🟡 write)A

Create a new empty workspace (a draft; nothing is published). Container: GTM-XXXXXXX or accounts//containers/. dry_run=true (default) only previews the request.

Inputs: name (required), container (required), dry_run, description. Returns: object

gtm_enable_built_in_variablesEnable built-in variables (🟡 write)A

Enable built-in variables by API type (pageUrl, pagePath, pageHostname, referrer, event, clickElement, clickClasses, clickId, clickUrl, clickText, formId, scrollDepthThreshold, …). Already-enabled types are harmless. dry_run=true previews.

Inputs: types (required), container (required), dry_run, workspace_id. Returns: object

gtm_find_containerFind container by GTM-/G-/AW- id or nameA
Read-onlyIdempotent

Resolve a public id (GTM-XXXXXXX from the website's source, or a linked G-/AW- destination id) to the account, container id and default workspace — 1–2 requests. Or search container names across all accounts (1 request per account).

Inputs: public_id, name_contains. Returns: object

gtm_get_containerGet GTM containerB
Read-onlyIdempotent

Container details (name, public id, usage context, domains, linked tag ids). Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/.

Inputs: container (required). Returns: object

gtm_get_live_versionGet live (published) versionA
Read-onlyIdempotent

The version currently published on the website — what visitors actually get. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/.

Inputs: container (required), include_entities. Returns: object

gtm_get_tagGet tagA
Read-onlyIdempotent

Full tag: flattened parameters, triggers, consent, notes, fingerprint and the variables it references. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: tag_id (required), container (required), workspace_id. Returns: object

gtm_get_triggerGet triggerA
Read-onlyIdempotent

Full trigger with all filter conditions and fingerprint. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), trigger_id (required), workspace_id. Returns: object

gtm_get_variableGet variableA
Read-onlyIdempotent

Full variable with flattened parameters (e.g. Data Layer name, JS code) and fingerprint. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), variable_id (required), workspace_id. Returns: object

gtm_get_versionGet container versionA
Read-onlyIdempotent

One version: counts and tags-by-type; include_entities=true adds compact tag/trigger/variable lists. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/.

Inputs: container (required), version_id (required), include_entities. Returns: object

gtm_get_workspace_statusWorkspace status (changes & conflicts)A
Read-onlyIdempotent

Unpublished changes and merge conflicts of a workspace — run before gtm_create_version. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), workspace_id. Returns: object

gtm_list_accountsList GTM accountsA
Read-onlyIdempotent

List every Google Tag Manager account the signed-in Google user can see (1 request).

Inputs: no named parameters. Returns: object

gtm_list_built_in_variablesList enabled built-in variablesA
Read-onlyIdempotent

Built-in variables currently enabled in the workspace (type + display name, e.g. pageUrl → 'Page URL'). Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), workspace_id. Returns: object

gtm_list_containersList GTM containersA
Read-onlyIdempotent

List containers of one account (1 request), or of all accounts when account_id is omitted (1 request per account, capped at 10 accounts — quota is 25 requests / 100 s).

Inputs: account_id, name_contains. Returns: object

gtm_list_environmentsList environmentsA
Read-onlyIdempotent

Environments (Live, Latest, custom) with the version each one serves. Preview auth codes are never returned. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/.

Inputs: container (required). Returns: object

gtm_list_foldersList foldersB
Read-onlyIdempotent

Folders of a workspace (tags/triggers/variables reference them via folder_id). Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), workspace_id. Returns: object

gtm_list_tagsList tagsA
Read-onlyIdempotent

Tags of a workspace with type label, paused flag, trigger ids and key parameters (all pages fetched once; filters/offset are applied locally). type examples: gaawe (GA4 event), googtag, html, awct, ua. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), type, limit, offset, +3 more. Returns: object

gtm_list_templatesList custom templatesA
Read-onlyIdempotent

Custom / community-gallery templates installed in the workspace (template code is not returned). Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), workspace_id. Returns: object

gtm_list_triggersList triggersC
Read-onlyIdempotent

Triggers with a one-line condition summary (e.g. 'Custom Event: {{_event}} equals purchase'). Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), type, limit, offset, +2 more. Returns: object

gtm_list_variablesList variablesA
Read-onlyIdempotent

User-defined variables with a summary (type codes: v = Data Layer, c = Constant, jsm = Custom JS, u = URL, k = Cookie). Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/. Workspace id (numeric). Omit to use the 'Default Workspace' (looked up once and cached).

Inputs: container (required), type, limit, offset, +2 more. Returns: object

gtm_list_versionsList container versionsA
Read-onlyIdempotent

Version headers (id, name, entity counts), newest first, plus the latest version id. Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/.

Inputs: container (required), limit, offset, include_deleted. Returns: object

gtm_list_workspacesList workspacesA
Read-onlyIdempotent

Workspaces of a container (unpublished drafts; free tier allows 3). Container as public id (GTM-XXXXXXX, or a linked G-/AW- destination id) or API path accounts//containers/.

Inputs: container (required). Returns: object

gtm_publish_versionPublish version (🔴 goes live)A
Destructive

🔴 Make a container version LIVE for every visitor of the website. Requires gtm-mcp auth --with-writes, the Publish role in GTM, dry_run=false AND confirm=true. dry_run (default) shows the version vs the current live version. Rollback = publish the previous version id.

Inputs: container (required), version_id (required), confirm, dry_run. Returns: object

gtm_raw_getRaw GET (escape hatch)A
Read-onlyIdempotent

GET any Tag Manager v2 resource path (starts with 'accounts/…', e.g. accounts/1/containers/2/workspaces/3/clients) for things no dedicated tool covers. Read-only; output is truncated at 50 KB.

Inputs: path (required), params. Returns: object

gtm_revert_entityRevert workspace changes to an entity (🟡 undo)A

Undo this workspace's changes to one tag / trigger / variable / folder: restores the live version's copy, or removes the entity from the workspace if it was created here (the live container is never touched). dry_run=true previews.

Inputs: container (required), entity_id (required), entity_type (required), dry_run, +1 more. Returns: object

gtm_setup_ga4_ecommerce_eventsSet up GA4 ecommerce event tags (🟡 recipe)A

Plan (dry_run=true, default) or apply (dry_run=false) the standard GA4 ecommerce set in a workspace: for every missing event (view_item_list … purchase, refund; or the events you pass) one Custom Event trigger (dataLayer.push({event: 'purchase', ecommerce: {...}})) + one GA4 event tag with 'send ecommerce data'. Existing triggers/tags are reused, events that only have paused tags are reported (not duplicated). measurement_id = G-XXXXXXXX or {{GA4 Measurement ID}}. Nothing goes live until gtm_create_version + gtm_publish_version.

Inputs: container (required), measurement_id (required), events, dry_run, +5 more. Returns: object

gtm_update_tagUpdate tag (🟡 write)A

Change selected fields of an existing tag (pause/unpause, rename, swap triggers, set parameters). parameters merges by key — pass null for a key to remove it. The tag is read first and updated with its fingerprint (safe against concurrent edits). dry_run=true (default) shows a before/after diff only.

Inputs: tag_id (required), container (required), name, notes, +6 more. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 34 tools

    Disambiguation4/5

    Each tool is scoped to a distinct resource plus action, and the descriptions actively steer between lookalikes (e.g. gtm_create_ga4_event_tag is called out as the preferred path over gtm_create_tag for GA4 events). The only genuine overlap is in the container-resolution trio (gtm_find_container / gtm_list_containers / gtm_get_container) and between the batch helpers (gtm_container_audit, gtm_setup_ga4_ecommerce_events) and their single-entity counterparts, but each description clarifies when to use which.

    Naming Consistency5/5

    Uniform gtm_<verb>_<noun> pattern across all 34 tools, with a consistent split between list_/get_ for reads and create_/update_/publish_/revert_ for writes. No camelCase or ad-hoc verbs leak in.

    Tool Count3/5

    34 tools is heavy for the interaction surface, driven by a list/get pair for every GTM resource type (tags, triggers, variables, folders, templates, versions, workspaces, environments). Most tools do earn their place, but the convenience wrappers (find_container, container_audit, setup_ga4_ecommerce_events, create_ga4_event_tag) add surface area that could arguably be folded into fewer tools.

    Completeness3/5

    Read coverage is excellent and create coverage spans workspaces, tags, triggers, variables, versions and publish. However, writes are asymmetric: only gtm_update_tag exists, with no update for triggers, variables, folders, or containers, and there are no delete operations at all — gtm_revert_entity is only a partial undo, and gtm_raw_get is read-only, so modifying an existing trigger or variable has no clean path.

    Maintenance

    ActivityMaintained
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      Production-grade MCP server for the Google Tag Manager API v2 with read-only GA4 (Admin + Data API) tooling. 107 tools covering the full GTM surface, including server-side containers. Ships read-only: writes, publishes, and deletes are each gated behind separate opt-in flags, every mutation requires per-call confirmation, and a dry-run mode simulates changes. Includes container audits
      203
      283 npm
      4
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables managing Google Tag Manager and Google Analytics 4 through natural language, with tiered read/write/destructive safety controls including dry-run writes and two-phase confirmations for destructive actions.
      8
      1
      MIT
    • F
      license
      Not graded
      quality
      C
      maintenance
      Enables reading, drafting, and publishing Google Tag Manager configurations (accounts, containers, tags, triggers, variables, versions) via the Tag Manager API v2, with isolated workspaces for safe edits and explicit publish for production changes.
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI clients to manage Google Tag Manager accounts and containers through the Tag Manager API v2, covering account/container discovery, workspace creation and syncing, CRUD on tags, triggers, variables, and folders, built-in variable control, version snapshots, and guarded publishing. It authenticates with a user's own Google identity (or a service-account fallback), honors API quota limits, and writes a redacted SQLite debug log of every tool call and API request.
      1
      MIT