Google Tag Manager MCP Server

Google Tag Manager MCP Server

Enables natural language management of Google Tag Manager resources including accounts, containers, tags, triggers, and variables via the Model Context Protocol.

Category
访问服务器

README

Google Tag Manager MCP Server

Local Model Context Protocol (MCP) server for Google Tag Manager, allowing Claude to interact with your GTM accounts, containers, tags, triggers, and variables.

🚀 Quick Start

1. Clone and Install

git clone <repository-url>
cd gtm-mcp-server
npm install

2. Setup Google Cloud Project and API

  1. 🌐 Go to Google Cloud Console
  2. 📁 Create a new project (important: create a new project specifically for this)
  3. 🔧 Enable Google Tag Manager API:
    • Inside your project, go to "APIs & Services" > "Library"
    • Search for "Tag Manager API"
    • Click on it and press "Enable"

3. Create OAuth 2.0 Credentials

  1. 🔑 On the Tag Manager API page, click "Create Credentials" button
  2. ❓ In "What data will you be accessing?" select "User data"
  3. 📱 In "OAuth Client ID" section:
    • Application type: select "Desktop app"
    • Give it any name you want
  4. 📥 Download the JSON file and save it as credentials.json in the project root

4. Configure Test Users

  1. 👤 Go to "APIs & Services" > "Credentials" (left sidebar)
  2. 🔍 Find your newly created "OAuth 2.0 Client ID" and click on it
  3. 👥 Go to "Audience" tab, scroll down to "Test Users" section
  4. ➕ Add your email address as a test user

5. Run Authorization

# Build the project first
npm run build

# Run authorization
npm run auth

This will:

  • Open a browser window for Google authorization
  • Redirect you to sign in with the email you added as a test user
  • After successful authorization, show a success page at http://localhost:3000/callback
  • Create a gtm-config.json file with access tokens in your project

6. Configure Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "google-tag-manager": {
      "command": "node",
      "args": ["/FULL/PATH/TO/YOUR/gtm-mcp-server/dist/index.js"],
      "env": {
        "PATH": "/usr/local/bin:/usr/bin:/bin"
      }
    }
  }
}

⚠️ Important: Replace /FULL/PATH/TO/YOUR/gtm-mcp-server/ with the actual absolute path to your project folder.

For example:

  • macOS: "/Users/wiefix/WORK/gtm-mcp-server/dist/index.js"
  • Windows: "C:\\Users\\YourName\\Documents\\gtm-mcp-server\\dist\\index.js"

PATH explanation: The PATH environment variable specifies directories where system executables (like node) are located. On macOS/Linux, these standard paths ensure the MCP server can find Node.js.

7. Restart Claude Desktop

After saving the configuration file, restart Claude Desktop to connect the MCP server.

🛠️ Available Tools

📊 gtm_account

GTM account management

  • get - get account details
  • list - list all accounts
  • update - update account settings

📦 gtm_container

GTM container management

  • get - get container details
  • list - list containers in account
  • create - create new container
  • update - update container
  • delete - delete container

🚀 gtm_workspace

GTM workspace management

  • get - get workspace details
  • list - list workspaces in container
  • create - create new workspace
  • update - update workspace
  • delete - delete workspace

📁 gtm_folder

Folder management for organizing elements

  • get - get folder details
  • list - list folders in workspace
  • create - create new folder
  • update - update folder
  • delete - delete folder

🏷️ gtm_tag

GTM tag management

  • get - get tag details
  • list - list tags in workspace
  • create - create new tag
  • update - update tag
  • delete - delete tag

⚡ gtm_trigger

GTM trigger management

  • get - get trigger details
  • list - list triggers in workspace
  • create - create new trigger
  • update - update trigger
  • delete - delete trigger

🔢 gtm_variable

GTM variable management

  • get - get variable details
  • list - list variables in workspace
  • create - create new variable
  • update - update variable
  • delete - delete variable

🔧 gtm_builtin_variable

GTM built-in variable management

  • list - list built-in variables
  • create - enable built-in variable (pageUrl, pageTitle, etc.)
  • delete - disable built-in variable

💬 Usage Examples

After setup, you can ask Claude:

Basic navigation:

  • "Show all my GTM accounts"
  • "List containers in account 123456"
  • "Show workspaces in container 456789"

Organization:

  • "Create folder 'Analytics Tags' for organizing tags"
  • "List all folders in workspace"

Working with tags:

  • "Create Google Analytics tag with Measurement ID GA_MEASUREMENT_ID"
  • "Show all tags in workspace 7"
  • "Update tag with ID 15 with new settings"
  • "Delete unused tag"

Triggers:

  • "Create trigger for all page views"
  • "Create click trigger for button with class 'download-btn'"
  • "List all triggers"

Variables:

  • "Enable built-in variable Page URL"
  • "Create custom variable for GA Measurement ID"
  • "Show all variables in workspace"

🔧 Troubleshooting

Authorization Errors

  • Make sure credentials.json is in the project root
  • Verify that Google Tag Manager API is enabled in your Google Cloud project
  • Check that your email is added as a test user in OAuth consent screen
  • Try running npm run auth again

API Errors

  • Ensure your Google account has access to GTM accounts
  • Check access permissions in GTM interface
  • Verify that the API is enabled and credentials are correct

Connection Errors

  • Restart Claude Desktop after making configuration changes
  • Verify correct absolute paths in claude_desktop_config.json
  • Check that the dist/index.js file exists (run npm run build if missing)

📁 File Structure

gtm-mcp-server/
├── credentials.json          # Your Google OAuth credentials (downloaded from Google Cloud)
├── gtm-config.json          # Access tokens (auto-created after successful authorization)
├── src/                     # TypeScript source code
├── dist/                    # Compiled JavaScript (created by npm run build)
├── package.json             # Project dependencies and scripts
└── README.md               # This instruction file

⚠️ Security

  • Files credentials.json and gtm-config.json contain sensitive authentication data
  • These files are automatically added to .gitignore to prevent accidental commits
  • Never publish these files in public repositories or share them
  • Keep your Google Cloud project credentials secure

🔄 Development

# Development mode with auto-reload
npm run dev

# Build project for production
npm run build

# Code linting and formatting
npm run lint

# Re-run authorization if needed
npm run auth

📞 Support

If you encounter problems:

  1. Double-check all setup steps - make sure you followed the exact sequence
  2. Verify Node.js version - ensure you're using Node.js v20.19.5 or higher
  3. Check Google Cloud setup:
    • Project created and Tag Manager API enabled
    • OAuth credentials created as Desktop app
    • Your email added as test user
  4. Verify file paths in Claude Desktop config are absolute and correct
  5. Check logs in Claude Desktop terminal for error messages
  6. Rebuild the project with npm run build if needed

🎯 Quick Verification

To verify everything works:

  1. Complete all setup steps above
  2. Restart Claude Desktop
  3. Open a new chat in Claude
  4. Ask: "List my GTM accounts"
  5. You should see your Google Tag Manager accounts listed

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选