metkamedia/gtm-mcp-server
If you are the rightful owner of gtm-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a comprehensive guide to setting up and using a Local Model Context Protocol (MCP) server for Google Tag Manager, enabling interaction with GTM accounts, containers, tags, triggers, and variables.
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
- š Go to Google Cloud Console
- š Create a new project (important: create a new project specifically for this)
- š§ 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
- š On the Tag Manager API page, click "Create Credentials" button
- ā In "What data will you be accessing?" select "User data"
- š± In "OAuth Client ID" section:
- Application type: select "Desktop app"
- Give it any name you want
- š„ Download the JSON file and save it as
credentials.json
in the project root
4. Configure Test Users
- š¤ Go to "APIs & Services" > "Credentials" (left sidebar)
- š Find your newly created "OAuth 2.0 Client ID" and click on it
- š„ Go to "Audience" tab, scroll down to "Test Users" section
- ā 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 detailslist
- list all accountsupdate
- update account settings
š¦ gtm_container
GTM container management
get
- get container detailslist
- list containers in accountcreate
- create new containerupdate
- update containerdelete
- delete container
š gtm_workspace
GTM workspace management
get
- get workspace detailslist
- list workspaces in containercreate
- create new workspaceupdate
- update workspacedelete
- delete workspace
š gtm_folder
Folder management for organizing elements
get
- get folder detailslist
- list folders in workspacecreate
- create new folderupdate
- update folderdelete
- delete folder
š·ļø gtm_tag
GTM tag management
get
- get tag detailslist
- list tags in workspacecreate
- create new tagupdate
- update tagdelete
- delete tag
ā” gtm_trigger
GTM trigger management
get
- get trigger detailslist
- list triggers in workspacecreate
- create new triggerupdate
- update triggerdelete
- delete trigger
š¢ gtm_variable
GTM variable management
get
- get variable detailslist
- list variables in workspacecreate
- create new variableupdate
- update variabledelete
- delete variable
š§ gtm_builtin_variable
GTM built-in variable management
list
- list built-in variablescreate
- 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 (runnpm 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
andgtm-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:
- Double-check all setup steps - make sure you followed the exact sequence
- Verify Node.js version - ensure you're using Node.js v20.19.5 or higher
- Check Google Cloud setup:
- Project created and Tag Manager API enabled
- OAuth credentials created as Desktop app
- Your email added as test user
- Verify file paths in Claude Desktop config are absolute and correct
- Check logs in Claude Desktop terminal for error messages
- Rebuild the project with
npm run build
if needed
šÆ Quick Verification
To verify everything works:
- Complete all setup steps above
- Restart Claude Desktop
- Open a new chat in Claude
- Ask: "List my GTM accounts"
- You should see your Google Tag Manager accounts listed