Google Tag Manager MCP
Google Tag Manager MCP
English | Русский
A1 Google Tag Manager MCP 让 AI 应用可以用自然语言检查和维护 Google Tag Manager 容器。查看页面上的触发情况,在草稿工作区中处理代码、触发器和变量,然后在准备好时慎重地编译并发布一个版本。
它通过你的 Google 账号连接到 Google Tag Manager API v2。与让 AI 猜测 GTM 配置不同,它操作的是你选择的具体容器、工作区和版本。
19 个工具。 10 个操作只读取 GTM 数据;4 个创建草稿或更改内置变量;5 个可以修改、删除、编译或发布线上配置。
草稿优先。 代码、触发器和变量都在工作区中创建。发布是一个独立的、明确具有破坏性的操作。
感知配额。 GTM 允许每个项目每秒 0.25 个请求;服务器将请求间隔至少 4.2 秒,而不是压垮 API。
你的 Google 访问权限。 服务器使用你的 OAuth 凭据,并且只请求读取、编辑、版本化和发布所需的 Tag Manager 作用域。
从一个只读问题开始:
我的容器中有哪些代码会在网页浏览触发器上触发?
一分钟看到效果
你: 列出我的 GTM 容器,并显示哪些代码会在网页浏览时触发。
助手: 列出容器、其工作区、相关触发器以及附加到这些触发器上的代码。不会更改任何内容。
你: 在
GTM-ABC123的默认工作区中,为衡量 IDG-XXXXXXX在所有网页上准备一个 GA4 配置代码。助手: 显示工作区、建议的代码和触发器配置,然后在创建草稿之前请求确认。
你: 确认草稿。
助手: 在工作区中创建该代码。它不会发布容器;编译和发布版本仍然是单独的步骤。
Related MCP server: unboundai-gtm-mcp-server
目录
快速开始
你需要 Node.js 20 以上版本、一个有 GTM 容器访问权限的 Google 账号,以及来自一个已启用 Tag Manager API 的 Google Cloud 项目的 OAuth 凭据。
将服务器添加到你的 AI 应用中。
从上面的只读问题开始。
在应用中:
打开 设置 → 插件 → MCP 服务器。
选择 添加服务器。
添加
npx -y mcp-google-tagmanager@latest以及下面的三个环境变量。
变量 | 值 |
| 你的 Google OAuth 客户端 ID |
| 你的 Google OAuth 客户端密钥 |
| 你的 Google OAuth 刷新令牌 |
从命令行:
codex mcp add google-tagmanager \
--env GOOGLE_TAGMANAGER_CLIENT_ID=your_client_id \
--env GOOGLE_TAGMANAGER_CLIENT_SECRET=your_client_secret \
--env GOOGLE_TAGMANAGER_REFRESH_TOKEN=your_refresh_token \
-- npx -y mcp-google-tagmanager@latestcodex mcp listclaude mcp add \
--env GOOGLE_TAGMANAGER_CLIENT_ID=your_client_id \
--env GOOGLE_TAGMANAGER_CLIENT_SECRET=your_client_secret \
--env GOOGLE_TAGMANAGER_REFRESH_TOKEN=your_refresh_token \
--transport stdio \
--scope user \
google-tagmanager \
-- npx -y mcp-google-tagmanager@latestclaude mcp list打开 设置 → 开发者 → 编辑配置。
将以下条目添加到
mcpServers:
{
"mcpServers": {
"google-tagmanager": {
"command": "npx",
"args": ["-y", "mcp-google-tagmanager@latest"],
"env": {
"GOOGLE_TAGMANAGER_CLIENT_ID": "your_client_id",
"GOOGLE_TAGMANAGER_CLIENT_SECRET": "your_client_secret",
"GOOGLE_TAGMANAGER_REFRESH_TOKEN": "your_refresh_token"
}
}
}
}如果 编辑配置 不可用,请在 macOS 上编辑 ~/Library/Application Support/Claude/claude_desktop_config.json,或在 Windows 上编辑 %APPDATA%\Claude\claude_desktop_config.json。
在 macOS/Linux 上,将用户级服务器添加到 ~/.cursor/mcp.json;在 Windows 上,添加到 %USERPROFILE%\.cursor\mcp.json:
{
"mcpServers": {
"google-tagmanager": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mcp-google-tagmanager@latest"],
"env": {
"GOOGLE_TAGMANAGER_CLIENT_ID": "your_client_id",
"GOOGLE_TAGMANAGER_CLIENT_SECRET": "your_client_secret",
"GOOGLE_TAGMANAGER_REFRESH_TOKEN": "your_refresh_token"
}
}
}
}从命令面板运行 MCP: Open User Configuration 并添加:
{
"servers": {
"google-tagmanager": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mcp-google-tagmanager@latest"],
"env": {
"GOOGLE_TAGMANAGER_CLIENT_ID": "${input:gtm_client_id}",
"GOOGLE_TAGMANAGER_CLIENT_SECRET": "${input:gtm_client_secret}",
"GOOGLE_TAGMANAGER_REFRESH_TOKEN": "${input:gtm_refresh_token}"
}
}
},
"inputs": [
{ "type": "promptString", "id": "gtm_client_id", "description": "Google OAuth client ID" },
{ "type": "promptString", "id": "gtm_client_secret", "description": "Google OAuth client secret", "password": true },
{ "type": "promptString", "id": "gtm_refresh_token", "description": "Google OAuth refresh token", "password": true }
]
}使用 MCP: List Servers 检查。
你可以让它做什么
了解当前配置
列出我可以访问的 GTM 账号和容器。
在此工作区中,哪些代码会在网页浏览时触发?
显示此代码的触发器和变量配置。
启用了哪些内置变量?
在草稿中准备跟踪变更
为结账跟踪变更创建工作区。
为特定事件准备 GA4 代码和触发器。
启用此触发器所需的点击变量。
在向我显示完整替换配置后更新此代码。
慎重地发布版本
将此工作区编译为名为
April release的版本。显示编译错误(如果有)。
在我确认版本及其变更后发布版本
42。
GTM 变更是如何关联的
GTM 有一条清晰的发布路径:
一个账号包含一个或多个容器。
容器包含用于草稿变更的工作区。
代码、触发器和变量属于某个工作区。
编译工作区会创建容器版本并删除源工作区。GTM 会提供一个替代工作区。
发布会使所选容器版本生效。
此服务器可以检查每个步骤。它不会将草稿视为发布:创建版本和发布是独立的操作。
哪些操作会改变配置
操作 | 行为 | 确认边界 |
列出账号、容器、工作区、代码、触发器、变量和版本 | 读取 GTM 配置 | 无变更 |
创建容器或工作区 | 添加新的 GTM 对象 | 更改 GTM |
创建代码、触发器或变量 | 向工作区添加草稿对象 | 更改草稿工作区 |
启用或禁用内置变量 | 更改工作区配置 | 更改草稿工作区 |
更新代码、触发器或变量 | 替换整个资源,受其指纹保护 | 可能具有破坏性 |
删除代码、触发器或变量 | 删除所选对象 | 破坏性 |
编译工作区 | 创建版本并删除源工作区 | 破坏性 |
发布版本 | 使所选版本生效 | 破坏性 |
原始 API 请求 | 可在没有专用工具的情况下调用 API 方法 | 可能具有破坏性 |
AI 客户端自行决定如何请求确认。服务器会标记只读、写入和破坏性操作,以便客户端区分检查与真实变更。
获取访问权限
服务器使用 Google OAuth 2.0。Google Tag Manager 不为此类用户数据提供 API 密钥。
创建或选择一个 Google Cloud 项目,并启用 Tag Manager API。未启用该 API 的项目不会获得配额。
配置 OAuth 同意屏幕并创建 OAuth 客户端。桌面应用客户端适合本地使用。
授权你的 Google 账号并获取刷新令牌。如果你启用 使用你自己的 OAuth 凭据,OAuth 2.0 Playground 可以完成此操作。
一起请求以下作用域:
https://www.googleapis.com/auth/tagmanager.readonly https://www.googleapis.com/auth/tagmanager.edit.containers https://www.googleapis.com/auth/tagmanager.edit.containerversions https://www.googleapis.com/auth/tagmanager.publish
这些作用域是独立的:读取、编辑、编译版本和发布各自需要相应的权限。请将客户端密钥和刷新令牌视为密码。
配置
变量 | 是否必需 | 描述 |
| 是* | OAuth 客户端 ID。 |
| 是* | OAuth 客户端密钥。 |
| 是* | OAuth 刷新令牌。 |
| 是* | OAuth 三件套的短期替代方案。 |
| 否 | Tag Manager API 基础 URL 覆盖。 |
| 否 | 单次请求超时;默认 |
| 否 | 临时故障时的最大重试次数;默认 |
| 否 | 最低请求间隔;默认 |
* 提供 OAuth 三件套或访问令牌中的任一种。访问令牌大约一小时后过期,且不会自动刷新。
数据与遥测
服务器在本地运行,并向 Google 发送 GTM API 请求和 OAuth 刷新请求。其匿名遥测数据包含随机安装 ID、包版本、AI 客户端和 Node.js/操作系统版本以及工具名称。它不会发送 OAuth 令牌、GTM 数据、工具参数或提示词。
使用以下命令禁用 A1 MCP 服务器的遥测:
ASKADS_TELEMETRY=0限制与后台工作
GTM 有速率限制。 API 允许每个项目每秒 0.25 个请求,因此服务器将调用间隔至少 4.2 秒。广泛的审计因此可能需要较长时间。
临时限制会谨慎重试。
429和 Google 配额403响应使用指数退避和Retry-After。读取在网络和5xx故障后重试;写入在不确定的故障后不会重放。没有后台监控。 服务器只会在你的 AI 应用调用它时运行。如果应用支持计划任务,它可以定期检查容器或其线上版本。
工作区在编译后会消失。 在调用
create_version之前,请保存工作区中需要的任何内容,并检查返回的替代工作区路径。
技术文档
MCP 能力目录 — 面向每个工具的任务导向页面。
支持
Available Tools
25 toolsauth_statusGoogle connection statusARead-onlyIdempotent
Shows whether this server is connected to Google: token presence and source (env variables or a stored in-chat login), expiry, the Google account email, granted vs missing OAuth scopes, where the credentials file lives and where the OAuth client comes from. Makes no network calls and never returns the token itself. Call it first when other tools report the server is not connected.
Inputs: no named parameters.
create_containerCreate a containerA
Creates a new container in a GTM account. usage_context declares the platform, e.g. ["web"]; other values include androidSdk5, iosSdk5, server. Returns the created Container with its server-assigned containerId and publicId. Requires the tagmanager.edit.containers scope.
Inputs: name (required), account_id (required), usage_context (required).
create_entityCreate a tag, trigger or variableA
Creates a tag, trigger or variable in a workspace. body is the resource JSON: minimally { name, type } plus type-specific parameter entries; tags also take firingTriggerId (array of trigger id strings). Example tag body: { "name": "GA4 event", "type": "gaawe", "parameter": [...], "firingTriggerId": ["12"] }. Returns the created resource with its server-assigned id and fingerprint. Requires the tagmanager.edit.containers scope.
Inputs: body (required), account_id (required), entity_type (required), container_id (required), +1 more.
create_versionCreate a container version from a workspaceADestructive
Compiles a workspace into an immutable Container Version (the unit that gets published). SIDE EFFECT: the source workspace is DELETED and replaced by a fresh one — the response's newWorkspacePath points to the replacement; use it for any further edits, or old workspace paths will 404. Returns { containerVersion (with containerVersionId and full tag/trigger/variable snapshots), syncStatus, newWorkspacePath }. A compile failure comes back as compilerError=true with HTTP 200 and is reported as an error. Requires the tagmanager.edit.containerversions scope (edit.containers is NOT sufficient).
Inputs: account_id (required), container_id (required), workspace_id (required), name, +1 more.
create_workspaceCreate a workspaceA
Creates a new workspace in a container — an isolated draft where tags, triggers and variables are edited before being compiled into a version. Returns the created Workspace with its server-assigned workspaceId. Requires the tagmanager.edit.containers scope.
Inputs: name (required), account_id (required), container_id (required), description.
delete_entityDelete a tag, trigger or variableADestructiveIdempotent
Deletes a tag, trigger or variable by its API path. The response is empty on success. Requires the tagmanager.edit.containers scope.
Inputs: path (required).
finish_loginFinish the Google loginAIdempotent
Second step: waits up to 20 s for the browser consent to finish, saves the tokens to an owner-only file and verifies the login with a read-only identity call, returning the account email and the granted scopes. After success every tool works immediately — no client restart. If the user granted only part of the requested permissions, the login is still saved and missingScopes lists what will not work. Logging in under a different Google account replaces the previous login (its refresh token is revoked best-effort) and the response carries previousAccountEmail so the change never goes unnoticed.
Inputs: no named parameters.
get_accountGet a GTM accountARead-onlyIdempotent
Gets one Google Tag Manager account by id. Returns the Account resource: { accountId, name, path, fingerprint, shareData }.
Inputs: account_id (required).
get_containerGet a containerARead-onlyIdempotent
Gets one container by account id + container id. Returns the Container resource including publicId (the GTM-XXXXXX snippet id), usageContext and fingerprint.
Inputs: account_id (required), container_id (required).
get_resourceGet any resource by pathARead-onlyIdempotent
Generic getter for any GTM resource by its API-relative path — tags, triggers, variables, versions, containers, workspaces. Prefer echoing the path field from a previous response over assembling the string yourself. Returns the full resource JSON including its current fingerprint (needed for update_entity).
Inputs: path (required).
get_workspaceGet a workspaceARead-onlyIdempotent
Gets one workspace by account id + container id + workspace id. Returns the Workspace resource with its fingerprint.
Inputs: account_id (required), container_id (required), workspace_id (required).
list_accountsList GTM accountsARead-onlyIdempotent
Lists all Google Tag Manager accounts the authorized user can access. Returns { account: [{ accountId, name, path, fingerprint }], nextPageToken }. All ids are strings. This is the entry point: every other tool needs an accountId (or a path) from here.
Inputs: page_token.
list_containersList containersARead-onlyIdempotent
Lists the containers of a GTM account. Returns { container: [{ containerId, name, publicId (e.g. GTM-XXXXXX), usageContext, path, fingerprint, tagManagerUrl }], nextPageToken }.
Inputs: account_id (required), page_token.
list_tagsList tagsARead-onlyIdempotent
Lists the tags of a workspace. Returns { tag: [{ tagId, name, type (e.g. html, gaawe), parameter: [{ type, key, value, list, map }], firingTriggerId, blockingTriggerId, paused, path, fingerprint, tagManagerUrl }], nextPageToken }.
Inputs: account_id (required), container_id (required), workspace_id (required), page_token.
list_triggersList triggersARead-onlyIdempotent
Lists the triggers of a workspace. Returns { trigger: [{ triggerId, name, type (e.g. pageview, click, customEvent), filter/customEventFilter (conditions of { type, parameter }), path, fingerprint }], nextPageToken }.
Inputs: account_id (required), container_id (required), workspace_id (required), page_token.
list_variablesList variablesARead-onlyIdempotent
Lists the user-defined variables of a workspace (built-in variables live in manage_built_in_variables). Returns { variable: [{ variableId, name, type (e.g. v = data layer, jsm = custom JS, c = constant), parameter, path, fingerprint }], nextPageToken }.
Inputs: account_id (required), container_id (required), workspace_id (required), page_token.
list_workspacesList workspacesARead-onlyIdempotent
Lists the workspaces of a container. Returns { workspace: [{ workspaceId, name, description, path, fingerprint }], nextPageToken }. Workspaces are mandatory in GTM v2: every tag/trigger/variable operation needs a workspaceId, and a "Default Workspace" always exists — call this first.
Inputs: account_id (required), container_id (required), page_token.
logoutDisconnect from GoogleADestructive
Revokes the stored token at Google (oauth2.googleapis.com/revoke) and deletes the local credentials file. Tokens supplied via env variables are NOT touched — remove them from the MCP client config manually; envTokenStillSet in the response says whether any are still in effect.
Inputs: no named parameters.
manage_built_in_variablesList/enable/disable built-in variablesAIdempotent
Manages a workspace's built-in variables (pageUrl, clickText, event, ...). These are toggles, not records: action "list" returns the currently enabled ones ({ builtInVariable: [...] }), "enable" and "disable" take types (BuiltInVariableType enum values) and switch them on/off. Enable/disable require the tagmanager.edit.containers scope.
Inputs: action (required), account_id (required), container_id (required), workspace_id (required), +1 more.
publish_versionPublish, inspect or fetch the live container versionADestructive
Container-version operations. action "publish" pushes a version live (replacing the currently published one; requires the tagmanager.publish scope; version_id required, fingerprint recommended). action "get" fetches one version by version_id. action "live" fetches the currently published version of the container (no version_id needed). Publish responses can carry compilerError=true with HTTP 200 — reported as an error. Returns the ContainerVersion (publish wraps it as { containerVersion, compilerError }).
Inputs: action (required), account_id (required), container_id (required), version_id, +1 more.
raw_requestRaw Tag Manager API callADestructive
Escape hatch to call any Google Tag Manager API v2 path directly, for endpoints without a dedicated tool (environments, folders, templates, zones, workspace :sync / :quick_preview, version_headers, ...). path is relative to /tagmanager/v2/, e.g. "accounts/1/containers/2/environments". query values may be arrays for repeated params. Requests go through the same OAuth, rate limiter and retries as every other tool.
Inputs: path (required), body, query, method.
set_clientSave the OAuth clientAIdempotent
Saves the OAuth client credentials from the JSON file downloaded from Google Cloud Console ('Download JSON' on a Desktop-app client). Pass the file PATH — the secret must never be pasted into the chat. The client is stored once in the shared ~/.config/mcp-google-auth/client.json (owner-only) and reused by every mcp-google-* server; tokens stay per-server. After this, call start_login.
Inputs: path (required).
setup_instructionsSetup instructionsARead-onlyIdempotent
This server ships with a built-in OAuth client, so connecting normally needs only start_login + finish_login; call this for the details or to switch to your own client. The checklist adapts to the client in use: with the built-in client it is just the two login calls, and it adds the steps for your OWN client — creating a Google Cloud project and a Desktop-app OAuth client, publishing the consent screen (mandatory — Testing-mode refresh tokens die after 7 days), downloading the client JSON and handing its PATH to set_client. Works without any credentials; with your own client already configured it shortens to 'enable the API + log in' (one client serves the whole mcp-google-* line). Never asks the user to paste secrets into the chat.
Inputs: no named parameters.
start_loginStart the Google loginAIdempotent
First step of connecting from the chat, without editing config files or restarting the client. Returns authorizeUrl — show it to the user as a clickable link and ask them to open it in the browser ON THIS MACHINE, pick the Google account and approve access. A one-shot listener on 127.0.0.1 catches Google's redirect; the code is exchanged locally and never passes through the chat. Does not open the browser itself. The attempt lives 10 minutes; when the browser shows the success page, call finish_login.
Inputs: no named parameters.
update_entityUpdate a tag, trigger or variableADestructiveIdempotent
Updates a tag, trigger or variable by its API path. PUT semantics: this is a FULL REPLACE, not a patch — fetch the current resource with get_resource, modify it, and send the whole object back. Pass the resource's last-seen fingerprint for optimistic-concurrency safety; a mismatch fails the request. Requires the tagmanager.edit.containers scope.
Inputs: body (required), path (required), fingerprint.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 25 tools
Most tools target distinct resources and actions (list/get/create per account, container, workspace, tag, trigger, variable), and the auth lifecycle tools are clearly separate. However, get_resource overlaps with get_container/get_workspace, and create_entity/update_entity/delete_entity share conceptual ground with the specific container/workspace CRUD tools — descriptions clarify the boundaries but some confusion is possible.
Strong snake_case verb_noun pattern throughout (list_accounts, get_container, create_workspace, delete_entity). Minor deviations: setup_instructions and auth_status are noun phrases rather than verb_object, logout lacks an object, and publish_version actually performs publish/get/live actions, making the name slightly misleading.
25 tools sits at the top of a reasonable band; the deep GTM hierarchy (account > container > workspace > tags/triggers/variables/versions) plus a required OAuth flow justifies most tools. It is on the heavy side, but each tool earns its place and there is little gratuitous duplication.
Core lifecycle is well covered: auth, accounts, containers, workspaces, tags/triggers/variables CRUD, version create/publish, and built-in variables. Gaps exist (no delete/update for containers or workspaces, no dedicated environments/folders/templates/zones tools), but the raw_request escape hatch lets agents reach these endpoints.
Maintenance
Related MCP Connectors
Hosted Google Tag Manager MCP server, with each action switched on or off per account.
Google Ads MCP server — manage campaigns, keywords, and metrics.
Read and edit GA4, Search Console and Google Tag Manager from any MCP client. 29 tools.
Hosted Google Analytics 4 MCP server, with each action switched on or off per account.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP Server that provides a conversational interface to Google Tag Manager API, allowing users to manage tags, triggers, variables, and containers through natural language.-
- AlicenseAqualityDmaintenanceMCP server for Google Tag Manager API, enabling users to manage containers, tags, and triggers through natural language using Google Application Default Credentials.1854 npmApache 2.0
- AlicenseNot gradedqualityDmaintenanceMCP server for Google Tag Manager API v2, enabling programmatic management of accounts, containers, workspaces, tags, triggers, variables, and version workflows.34 npm16MIT
- FlicenseNot gradedqualityBmaintenanceA remote MCP server for Google Tag Manager that enables AI assistants to manage GTM accounts, containers, tags, triggers, variables, and more via OAuth or service account authentication.1-