GTM MCP Server
Provides tools for reading and managing Google Tag Manager containers, tags, triggers, variables, workspaces, environments, versions, folders, templates, and more through the GTM API v2.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@GTM MCP ServerList my GTM accounts"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
GTM MCP Server
A local MCP server that lets any MCP-compatible AI assistant — Claude Code, GitHub Copilot, Cursor, Windsurf, or VS Code — read and manage your Google Tag Manager containers, tags, triggers, variables, and more through the GTM API v2.
Everything runs on your machine. No data leaves your laptop except direct Google API calls authenticated with your own credentials.
Quick start
Prerequisites
Node.js 18+ — check with
node -vnpm — comes with Node
A Google Cloud project with the Tag Manager API enabled (see Step 1 below)
Step 1 — Create Google Cloud OAuth credentials
You only need to do this once. Everyone on the team can use the same GCP project, or create their own.
Go to Google Cloud Console
Create a new project (or pick an existing one)
Enable the Tag Manager API:
Go to APIs & Services > Library
Search for "Tag Manager API"
Click Enable
Create OAuth credentials:
Go to APIs & Services > Credentials
Click + Create Credentials > OAuth client ID
If prompted, configure the OAuth consent screen first:
User type: Internal (if using a Google Workspace org) or External
Fill in the required fields (app name, support email)
Add scopes: search for "Tag Manager" and add all Tag Manager scopes
Add yourself as a test user (if External)
Back in Credentials, create the OAuth client:
Application type: Desktop app
Name: anything (e.g. "GTM MCP Server")
Copy the Client ID and Client Secret — you'll need them next
Step 2 — Clone and install
git clone https://github.com/laiskickow/gtm-mcp-server.git
cd gtm-mcp-server
npm install
npm run buildStep 3 — Get your refresh token
The included helper script opens a browser auth flow and gives you a refresh token.
GTM_CLIENT_ID="your-client-id" GTM_CLIENT_SECRET="your-client-secret" npm run get-tokenThis will:
Print a URL — open it in your browser
Sign in with your Google account and approve access
Print your refresh token in the terminal — copy it
Step 4 — Create your .env file
cp .env.example .envEdit .env and paste your values:
GTM_CLIENT_ID=your-client-id.apps.googleusercontent.com
GTM_CLIENT_SECRET=GOCSPX-your-secret
GTM_REFRESH_TOKEN=1//your-refresh-tokenThe
.envfile is gitignored — your credentials stay local and are never committed.
Step 5 — Connect to your AI tool
Pick the tool you use. In every example below, replace /full/path/to with the actual path where you cloned the repo (e.g. /Users/yourname).
Claude Code
Add to your project .mcp.json (in your working directory) or user-level ~/.claude/.mcp.json:
{
"mcpServers": {
"gtm": {
"command": "node",
"args": ["/full/path/to/gtm-mcp-server/dist/index.js"],
"env": {
"GTM_CLIENT_ID": "your-client-id",
"GTM_CLIENT_SECRET": "your-client-secret",
"GTM_REFRESH_TOKEN": "your-refresh-token"
}
}
}
}Or use the start.sh wrapper which reads from .env automatically:
{
"mcpServers": {
"gtm": {
"command": "/full/path/to/gtm-mcp-server/start.sh"
}
}
}GitHub Copilot (VS Code)
Add to your workspace .vscode/mcp.json or user settings (Cmd+Shift+P > "Preferences: Open User Settings (JSON)"):
{
"mcp": {
"servers": {
"gtm": {
"type": "stdio",
"command": "node",
"args": ["/full/path/to/gtm-mcp-server/dist/index.js"],
"env": {
"GTM_CLIENT_ID": "your-client-id",
"GTM_CLIENT_SECRET": "your-client-secret",
"GTM_REFRESH_TOKEN": "your-refresh-token"
}
}
}
}
}Enable MCP in Copilot: go to Settings > GitHub Copilot > MCP and tick "Enable MCP" if it isn't already on.
Cursor
Add to Settings > MCP Servers > Add Server, or edit ~/.cursor/mcp.json:
{
"mcpServers": {
"gtm": {
"command": "node",
"args": ["/full/path/to/gtm-mcp-server/dist/index.js"],
"env": {
"GTM_CLIENT_ID": "your-client-id",
"GTM_CLIENT_SECRET": "your-client-secret",
"GTM_REFRESH_TOKEN": "your-refresh-token"
}
}
}
}Windsurf
Add to ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"gtm": {
"command": "node",
"args": ["/full/path/to/gtm-mcp-server/dist/index.js"],
"env": {
"GTM_CLIENT_ID": "your-client-id",
"GTM_CLIENT_SECRET": "your-client-secret",
"GTM_REFRESH_TOKEN": "your-refresh-token"
}
}
}
}Step 6 — Verify it works
Restart your AI tool (in Claude Code run /mcp to refresh servers). Then ask:
"List my GTM accounts"
You should see your GTM accounts listed. Done!
Related MCP server: Google Tag Manager MCP Server
Alternative: Service Account auth
If you prefer a service account (e.g. for a shared container):
In Google Cloud Console, go to IAM & Admin > Service Accounts
Create a service account, download the JSON key
Grant the service account access in GTM (Admin > User Management)
Set in
.env:GTM_SERVICE_ACCOUNT_KEY=/path/to/service-account-key.json
Available tools
Once connected, your AI assistant has access to all GTM API v2 resources:
Resource | Actions |
Accounts | list, get, update |
Containers | list, get, create, update, delete, get snippet |
Workspaces | list, get, create, update, delete, sync, quick preview, create version, get status |
Tags | list, get, create, update, delete, revert |
Triggers | list, get, create, update, delete, revert |
Variables | list, get, create, update, delete, revert |
Built-in Variables | list, create, delete, revert |
Folders | list, get, create, update, delete, move entities |
Environments | list, get, create, update, delete |
Versions | get, publish, list headers, set latest, delete, undelete |
Templates | list, get, create, update, delete, revert |
User Permissions | list, get, create, update, delete |
Zones | list, get, create, update, delete, revert |
Clients (server-side) | list, get, create, update, delete, revert |
Destinations | list, get, link, unlink |
Transformations | list, get, create, update, delete, revert |
Gtag Configs | list, get, create, update, delete |
Plus convention and preset tools:
gtm_naming_guide— show the naming standardgtm_validate_name— check a tag namegtm_build_tag_name/gtm_build_trigger_name/gtm_build_variable_name— generate compliant namesgtm_list_presets/gtm_preview_preset/gtm_deploy_preset— reusable tracking bundles
Tag naming convention
All tags, triggers, and variables follow a shared naming pattern:
Tags: [app]_[category]_[action]_[detail]
e.g.
mcui_data_create_rule-group,golf_action_click_kill-switch
Triggers: trigger_[app]_[event]_[detail?]
e.g.
trigger_golf_click_odds-cell
Variables: [scope]_[type]_[name]
e.g.
user_dl_role,app_const_version
Registered apps: golf, mcui, bopui, ivory, shared. Add yours in src/conventions.ts.
Tracking presets
Reusable bundles you can deploy to any workspace. Preview before deploying with gtm_preview_preset.
Preset | Creates |
| DataLayer init, page view trigger, core variables |
| Error listener, error event trigger, error variables |
| User action trigger, category/name/target variables |
| API call trigger, endpoint/duration/status variables |
| Data operation trigger, entity type/count variables |
| Workflow step trigger, step name/index/status variables |
Troubleshooting
Problem | Fix |
"No valid authentication configuration found" | Check your |
"invalid_grant" or "Token has been revoked" | Re-run |
Server not showing up | Check the path in your MCP config is absolute and points to |
"Cannot find module" errors | Run |
Google consent screen says "unverified" | Normal for internal/test apps — click "Advanced" > "Go to (app name)" |
Copilot doesn't show MCP tools | Enable MCP in VS Code: Settings > GitHub Copilot > MCP > tick "Enable MCP" |
Cursor/Windsurf not connecting | Restart the editor after saving the MCP config file |
Project structure
gtm-mcp-server/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── auth.ts # Google auth (OAuth2 / service account)
│ ├── gtm-client.ts # GTM API client wrapper
│ ├── conventions.ts # Naming conventions + validation
│ └── tools/ # One file per GTM resource
├── get-token.ts # OAuth refresh token helper
├── start.sh # Wrapper that loads .env
├── .env.example # Template for credentials
├── package.json
└── tsconfig.jsonTool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Read and edit GA4, Search Console and Google Tag Manager from any MCP client. 29 tools.
Let AI manage your Google Tag Manager containers — tags, triggers, variables, and more.
SEO & marketing toolkit for AI agents: GA4, Search Console, AdSense, GTM, PageSpeed, Trends.
- AdLoopOAuthcom.getadloop
Google Ads, GA4 and Tag Manager in your AI client, with a preview before every change.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceEnables interaction with Google Tag Manager through its API with built-in Google OAuth authentication. Allows managing GTM containers, tags, triggers, and variables through natural language.448210Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to manage Google Tag Manager accounts, containers, workspaces, tags, triggers, variables, and versions via the Tag Manager API v2.2Apache 2.0
- 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-
- AlicenseAqualityBmaintenanceAn MCP server for the Google Tag Manager API v2 that enables AI assistants to query GTM accounts, containers, tags, triggers, variables, and unpublished changes.242Apache 2.0
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/laiskickow/gtm-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server