---
title: "GTM MCP Server"
description: "Audit, fix, and publish Google Tag Manager containers from AI agents — 20 tools"
canonical: "https://docs.ainative.studio/docs/mcp/gtm-server"
last-updated: "2026-09-23T01:51:08.820Z"
---

# GTM MCP Server

Source: https://docs.ainative.studio/docs/mcp/gtm-server

> Audit, fix, and publish Google Tag Manager containers from AI agents — 20 tools

# GTM MCP Server

**Package:** `@ainative/gtm-mcp`  
**Version:** 0.2.0  
**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

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

### Manual Config

```json
{
  "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](https://console.cloud.google.com)
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](https://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

```bash
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
```

---

## Changelog

### v0.2.0 (current)

- Added to AINative MCP catalog for discovery and search (Refs #2856)
- Google Ads integration: `gads_list_conversion_actions`, `gads_update_conversion_counting`, `gads_audit_conversion_goals`, `gads_get_account_performance`
- 20 tools across 5 categories: Accounts, Tags, Triggers, Audit, Versions/Publishing
- Container audit with auto-fix for misfiring conversion tags

### v0.1.0

- Initial release with GTM container, tag, and trigger management
- Service account authentication (headless, no browser OAuth)
- Workspace versioning and publishing
