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
- Open Google Cloud Console
- APIs & Services → Library → search Tag Manager API → Enable
Step 2 — Create a Service Account
- IAM & Admin → Service Accounts → Create Service Account
- Name it (e.g.
gtm-mcp-agent), skip GCP role assignment - 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:
- Go to tagmanager.google.com
- Admin → Account → User Management → +
- Add the service account email (e.g.
gtm-mcp-agent@project.iam.gserviceaccount.com) - 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)
| Tool | Description |
|---|---|
gtm_list_accounts | List all GTM accounts accessible to the service account |
gtm_list_containers | List containers within an account |
gtm_get_container | Get container details (ID, publicId, usageContext) |
Tags (4 tools)
| Tool | Description |
|---|---|
gtm_list_tags | List all tags in a workspace |
gtm_get_tag | Get tag details (type, firing triggers, parameters) |
gtm_update_tag | Update tag parameters or firing triggers |
gtm_delete_tag | Delete a tag |
Triggers (4 tools)
| Tool | Description |
|---|---|
gtm_list_triggers | List all triggers in a workspace |
gtm_get_trigger | Get trigger details |
gtm_create_trigger | Create a new trigger (custom event, page view, click, etc.) |
gtm_update_trigger | Update trigger conditions |
Audit (3 tools)
| Tool | Description |
|---|---|
gtm_audit_container | Full container audit: orphaned tags, broad triggers, missing conversions |
gtm_find_misfiring_conversion_tags | Find conversion tags firing on broad triggers (All Pages, etc.) |
gtm_fix_conversion_tag_trigger | Auto-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)
| Tool | Description |
|---|---|
gtm_list_workspaces | List workspaces in a container |
gtm_get_workspace_status | Get workspace changes (added/modified/deleted entities) |
gtm_create_version | Create a container version from current workspace |
gtm_publish | Publish 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