Skip to main content
Glama
dienhokhanh

gtm-mcp-server

by dienhokhanh

gtm-mcp-server

An MCP (Model Context Protocol) server for creating and managing tags, triggers, and variables in Google Tag Manager directly from Claude, Codex, or any MCP client.

The server only operates at the workspace (draft) level — it never auto-publishes a container to production. You still need to review and publish the version yourself in the GTM UI (or via a future extension of this tool).

Features

  • gtm_list_accounts, gtm_list_containers, gtm_list_workspaces

  • gtm_list_tags, gtm_create_tag, gtm_update_tag, gtm_delete_tag

  • gtm_list_triggers, gtm_create_trigger

  • gtm_list_variables, gtm_create_variable

Every tool accepts account / container / workspace as either a name or an ID (e.g. container: "GTM-ABC123" or container: "My Website").

Related MCP server: GTM MCP Server

1. Create an OAuth client on Google Cloud

  1. Go to Google Cloud Console and create (or select) a project.

  2. Go to APIs & Services → Library and enable the Tag Manager API.

  3. Go to APIs & Services → Credentials → Create Credentials → OAuth client ID.

    • Application type: Desktop app.

  4. Download the resulting JSON file and rename it to credentials.json.

  5. Place it at ~/.gtm-mcp/credentials.json (default location), or set the GTM_MCP_CREDENTIALS_PATH environment variable to point somewhere else.

The Google account you sign in with needs access to the relevant GTM account/container (add it under GTM → Admin → User Management if needed).

2. Install

git clone https://github.com/YOUR_USERNAME/gtm-mcp-server.git
cd gtm-mcp-server
npm install
npm run build

3. Sign in to Google (one-time)

npm run auth

This prints a URL — open it in your browser, sign in, and grant access. The token is saved to ~/.gtm-mcp/token.json and refreshes automatically afterwards (no need to sign in again).

4. Connect to Claude Code / Claude Desktop

With Claude Code:

claude mcp add gtm -- node "/path/to/gtm-mcp-server/dist/index.js"

With Claude Desktop, add this to claude_desktop_config.json:

{
  "mcpServers": {
    "gtm": {
      "command": "node",
      "args": ["/path/to/gtm-mcp-server/dist/index.js"]
    }
  }
}

Once connected, you can ask directly, for example:

"Create a GA4 event tag named 'purchase_tracking' in container GTM-ABC123, default workspace, fired by the 'Purchase Event' trigger."

Environment variables

Variable

Default

Meaning

GTM_MCP_CONFIG_DIR

~/.gtm-mcp

Directory holding credentials/token

GTM_MCP_CREDENTIALS_PATH

<config_dir>/credentials.json

Path to the OAuth client secret file

GTM_MCP_TOKEN_PATH

<config_dir>/token.json

Path to the cached token

Security notes

  • Never commit credentials.json or token.json to git (already covered by .gitignore).

  • The token is stored in plaintext on your local machine — only run this server on a machine you trust.

  • All changes are made at the workspace draft level; publishing still requires a manual step in the GTM UI.

License

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    C
    maintenance
    Enables comprehensive management of Google Tag Manager accounts, containers, workspaces, tags, triggers, and variables through OAuth2 authentication, allowing users to create, update, and publish GTM configurations via natural language.
    26
    21 npm
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    MCP server for Google Tag Manager API v2, enabling programmatic management of accounts, containers, workspaces, tags, triggers, variables, and version workflows.
    21 npm
    14
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables full Google Tag Manager management via the GTM API v2, including tags, triggers, variables, and version publishing, with workspace-based change tracking.
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    MCP server for the Google Tag Manager API v2, enabling natural-language management of containers, workspaces, tags, triggers, variables, and publishing. It handles OAuth authentication and built-in rate limiting for the strict GTM API quota.
    19
    120 npm
    1
    MIT