Skip to main content

GTM MCP Server

Package: @ainative/gtm-mcp
Run: npx @ainative/gtm-mcp
Auth: Google Cloud service account (headless — no browser OAuth)
Tools: 20 across 5 categories

Lets AI agents audit GTM containers for misfiring tags, fix conversion tracking issues, manage tags and triggers, and publish workspace versions — all without touching the GTM UI.


Quick Start

Claude Code

claude mcp add ainative-gtm-mcp npx -- -y @ainative/gtm-mcp \
-e GTM_SERVICE_ACCOUNT_KEY_PATH=/path/to/service-account.json

Manual Config

{
"mcpServers": {
"ainative-gtm": {
"command": "npx",
"args": ["-y", "@ainative/gtm-mcp"],
"env": {
"GTM_SERVICE_ACCOUNT_KEY_PATH": "/path/to/service-account.json"
}
}
}
}

Authentication Setup

The server authenticates via a Google Cloud service account — no browser pop-up, designed for agent/headless use.

Step 1 — Enable Tag Manager API

  1. Open Google Cloud Console
  2. APIs & Services → Library → search Tag Manager API → Enable

Step 2 — Create a Service Account

  1. IAM & Admin → Service Accounts → Create Service Account
  2. Name it (e.g. gtm-mcp-agent), skip GCP role assignment
  3. Open the service account → Keys → Add Key → JSON → download

Step 3 — Grant Access Inside GTM

This is the step most people miss — GCP IAM does not control GTM access:

  1. Go to tagmanager.google.com
  2. Admin → Account → User Management → +
  3. Add the service account email (e.g. gtm-mcp-agent@project.iam.gserviceaccount.com)
  4. Set permission: Publish (for full access) or Read (audit only)

Step 4 — Set the env var

export GTM_SERVICE_ACCOUNT_KEY_PATH="/path/to/service-account.json"

Tools Reference

Accounts & Containers (3 tools)

ToolDescription
gtm_list_accountsList all GTM accounts accessible to the service account
gtm_list_containersList containers within an account
gtm_get_containerGet container details (ID, publicId, usageContext)

Tags (4 tools)

ToolDescription
gtm_list_tagsList all tags in a workspace
gtm_get_tagGet tag details (type, firing triggers, parameters)
gtm_update_tagUpdate tag parameters or firing triggers
gtm_delete_tagDelete a tag

Triggers (4 tools)

ToolDescription
gtm_list_triggersList all triggers in a workspace
gtm_get_triggerGet trigger details
gtm_create_triggerCreate a new trigger (custom event, page view, click, etc.)
gtm_update_triggerUpdate trigger conditions

Audit (3 tools)

ToolDescription
gtm_audit_containerFull container audit: orphaned tags, broad triggers, missing conversions
gtm_find_misfiring_conversion_tagsFind conversion tags firing on broad triggers (All Pages, etc.)
gtm_fix_conversion_tag_triggerAuto-create a scoped custom event trigger and reassign the misfiring tag

The audit tools are the most powerful — they can detect and auto-fix the most common GTM misconfiguration (conversion tags firing on All Pages instead of a specific event).


Versions & Publishing (6 tools)

ToolDescription
gtm_list_workspacesList workspaces in a container
gtm_get_workspace_statusGet workspace changes (added/modified/deleted entities)
gtm_create_versionCreate a container version from current workspace
gtm_publishPublish the latest version to production

Example Workflows

Audit and fix misfiring conversion tags

You: "Audit my GTM container GTM-XXXXX and fix any misfiring conversion tags"

Agent: [gtm_audit_container] Found 3 issues:
- GA4 Purchase tag fires on trigger "All Pages" — should be "purchase" event
- Meta Pixel Lead tag fires on "All Pages" — should be "generate_lead" event

[gtm_fix_conversion_tag_trigger] Created trigger "CE - purchase", reassigned GA4 tag
[gtm_fix_conversion_tag_trigger] Created trigger "CE - generate_lead", reassigned Meta Pixel tag

[gtm_create_version] Created version "Auto-fix misfiring tags 2026-05-09"

You: "Publish it"
Agent: [gtm_publish] Published. Version 47 is now live.

Review workspace before publishing

You: "What changes are in the current workspace?"

Agent: [gtm_get_workspace_status]
Modified: GA4 Config tag (updated measurement ID)
Added: New scroll depth trigger
Deleted: Old UA Universal Analytics tag