MCP server for Google Tag Manager
Project description
GTM MCP Server
A Model Context Protocol (MCP) server that enables Claude to interact with Google Tag Manager.
Table of Contents
- Features
- Quick Start
- Complete Setup Guide
- Available Tools
- How Authentication Works
- Upgrade
- Troubleshooting
- Security Notes
- Development
- License
- Contributing
- Getting Help
Features
- List GTM accounts and containers
- Manage tags, triggers, and variables
- Create and publish container versions
- Full workspace management
🚀 Quick Start
Prerequisites
- Python 3.10 or higher
- Claude Desktop (or any MCP-compatible client like Cursor)
- A Google account with access to Google Tag Manager
📋 Complete Setup Guide
Part 1: Install the Package
pip install gtm-mcp
See PyPi
Part 2: Choose Your Authentication Method
GTM MCP supports two authentication methods. Choose the one that best fits your needs:
Method A: Application Default Credentials (Recommended for Servers)
Best for:
- ✅ Server environments and automation
- ✅ No browser interaction required
- ✅ Flexible credential sources
- ✅ Better for CI/CD pipelines
- ✅ Works on Google Cloud (GCE, GKE, Cloud Run)
Pros:
- No OAuth consent screen setup required
- No browser popup for authorization
- Automatic credential discovery from multiple sources
- Automatic token refresh
- Works with gcloud CLI, service account files, or cloud environment
Cons:
- Requires initial credential setup (service account or gcloud CLI)
- Need to manually grant service account access to GTM
→ Go to Application Default Credentials Setup
Method B: OAuth 2.0 (Original Method)
Best for:
- ✅ Personal desktop use
- ✅ Interactive environments
- ✅ When you want user-level permissions
Pros:
- Uses your personal Google account
- Natural authorization flow
- Direct access through browser
Cons:
- Requires OAuth consent screen setup
- Requires browser interaction on first use
- More complex initial setup
Application Default Credentials Setup (Method A)
Application Default Credentials (ADC) is Google's recommended way to authenticate applications. It automatically discovers credentials from multiple sources in the following order:
- GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to a service account JSON file
- gcloud CLI credentials (
gcloud auth application-default login) - Cloud environment service accounts (GCE, GKE, Cloud Run, etc.)
Choose the option that works best for you:
Option 1: Service Account File (Most Common)
Step 1: Create a Google Cloud Project
- Go to Google Cloud Console
- Click on the project dropdown (top left)
- Click "New Project"
- Enter a project name (e.g., "GTM MCP Service")
- Click "Create"
- Wait for the project to be created and select it
Step 2: Enable Tag Manager API
- In your project, go to "APIs & Services" → "Library"
- Search for "Tag Manager API"
- Click on it and click "Enable"
- Wait for it to enable (may take a minute)
Step 3: Create Service Account
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "Service Account"
- Fill in the service account details:
- Service account name: gtm-mcp-service
- Service account ID: (auto-filled)
- Description: Service account for GTM MCP Server
- Click "Create and Continue"
- Skip the optional steps and click "Done"
Step 4: Create and Download Service Account Key
- Click on the service account you just created
- Go to the "Keys" tab
- Click "Add Key" → "Create New Key"
- Select "JSON" format
- Click "Create"
- The JSON file will download automatically
- Save this file securely - you'll need its path later
- Copy the service account email from the JSON file (looks like:
gtm-mcp-service@your-project.iam.gserviceaccount.com)
Step 5: Grant Service Account Access to GTM
- Go to Google Tag Manager
- Select your GTM account
- Click "Admin" in the top navigation
- Under "Account", click "User Management"
- Click the "+" button to add a user
- Enter the service account email from Step 4
- Select appropriate permissions:
- Read: For read-only access
- Edit: For creating/modifying tags, triggers, variables
- Approve: For publishing container versions
- Publish: For full publishing rights
- Click "Invite"
Step 6: Configure Claude Desktop (Service Account File)
Edit your Claude Desktop config file:
- Linux:
~/.config/Claude/claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Add your configuration:
{
"mcpServers": {
"gtm-mcp": {
"command": "gtm-mcp",
"env": {
"GTM_AUTH_METHOD": "service_account",
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account-key.json"
}
}
}
}
Important: Replace /path/to/your/service-account-key.json with the actual path to your downloaded JSON file.
Example paths:
- Linux/macOS:
/home/username/gtm-service-account.json - Windows:
C:\\Users\\YourName\\gtm-service-account.json
Option 2: gcloud CLI Credentials (Simplest for Local Development)
If you have the Google Cloud SDK installed and want to use your own Google account credentials:
Step 1: Install Google Cloud SDK
If not already installed, follow the Google Cloud SDK installation guide.
Step 2: Authenticate with Application Default Credentials
gcloud auth application-default login
This will open a browser window to authenticate with your Google account and save credentials locally.
Step 3: Grant Your Account Access to GTM
Ensure your Google account has the appropriate permissions in Google Tag Manager (see Step 5 in Option 1, but use your Google account email instead of a service account email).
Step 4: Configure Claude Desktop (gcloud CLI)
Edit your Claude Desktop config file:
{
"mcpServers": {
"gtm-mcp": {
"command": "gtm-mcp",
"env": {
"GTM_AUTH_METHOD": "service_account"
}
}
}
}
Note: No GOOGLE_APPLICATION_CREDENTIALS is needed when using gcloud CLI credentials.
Option 3: Cloud Environment (GCE, GKE, Cloud Run)
If you're running in a Google Cloud environment, ADC will automatically use the attached service account.
Step 1: Attach Service Account to Your Resource
When creating your GCE instance, GKE pod, or Cloud Run service, attach a service account with the necessary permissions.
Step 2: Grant Service Account Access to GTM
Follow Step 5 from Option 1 to grant the service account access to your GTM account.
Step 3: Configure Your Application
Set the environment variable:
GTM_AUTH_METHOD=service_account
No GOOGLE_APPLICATION_CREDENTIALS is needed - ADC will automatically discover the attached service account.
Restart and Test
- Restart Claude Desktop completely
- Ask Claude: "List my GTM accounts"
- ADC will authenticate automatically - no browser popup needed!
OAuth 2.0 Setup (Method B)
Step 1: Create a Google Cloud Project
- Go to Google Cloud Console
- Click on the project dropdown (top left)
- Click "New Project"
- Enter a project name (e.g., "My GTM MCP Server")
- Click "Create"
- Wait for the project to be created and select it
Step 2: Enable Tag Manager API
- In your project, go to "APIs & Services" → "Library"
- Search for "Tag Manager API"
- Click on it and click "Enable"
- Wait for it to enable (may take a minute)
Step 3: Configure OAuth Consent Screen
- Go to "APIs & Services" → "OAuth consent screen"
- Select "External" (unless you have a Google Workspace)
- Click "Create"
- Fill in required fields:
- App name: My GTM MCP (or whatever you like)
- User support email: Your email
- Developer contact email: Your email
- Click "Save and Continue"
- Click "Update" then "Save and Continue"
- Add your email as a test user
- Click "Save and Continue"
Step 4: Create OAuth Credentials
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "OAuth client ID"
- Select "Desktop app" as the application type
- Enter a name: "GTM MCP Desktop Client"
- Click "Create"
- IMPORTANT: A dialog appears with your credentials - DO NOT CLOSE IT YET
Step 5: Save Your Credentials
From the dialog that appeared:
- Copy the Client ID (looks like:
123456789-abc123.apps.googleusercontent.com) - Copy the Client secret (looks like:
GOCSPX-...) - Note your Project ID from the Google Cloud Console (top bar, next to project name)
- Save these somewhere safe - you'll need them in the next step
You can also download the JSON file, but you only need the three values above.
Step 6: Configure Claude Desktop (OAuth 2.0)
⬆ top Edit your Claude Desktop config file:
- Linux:
~/.config/Claude/claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Claude Code:
~/.claude.json
Add your credentials:
{
"mcpServers": {
"gtm-mcp": {
"command": "gtm-mcp",
"env": {
"GTM_AUTH_METHOD": "oauth",
"GTM_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
"GTM_CLIENT_SECRET": "GOCSPX-your-client-secret",
"GTM_PROJECT_ID": "your-project-id"
}
}
}
}
Replace the values with your actual credentials from Step 5.
Note:
- If you have other MCP servers configured, just add the
"gtm-mcp"entry to the existing"mcpServers"object.- The
GTM_AUTH_METHODcan be omitted asoauthis the default for backward compatibility.
Step 7: Restart and Authorize (OAuth 2.0)
-
Restart Claude Desktop completely (close and reopen)
-
Ask Claude to use a GTM tool (e.g., "List my GTM accounts")
-
First-time authorization - a browser window will open automatically:
- Sign in with your Google account
- You'll see "Google hasn't verified this app" warning
- Click "Advanced" → "Go to [Your App Name] (unsafe)"
- This is safe because you created the app yourself
- Grant the requested permissions
- You'll see "The authentication flow has completed"
- Return to Claude Desktop
-
Your authorization is saved locally - you won't need to do this again!
🛠️ Available Tools
⬆ top
Once configured, Claude will have access to these GTM tools:
| Tool | Description |
|---|---|
gtm_list_accounts |
List all your GTM accounts |
gtm_list_containers |
List containers in an account |
gtm_list_tags |
List tags in a workspace |
gtm_get_tag |
Get detailed configuration of a specific tag |
gtm_create_tag |
Create a new tag |
gtm_update_tag |
Update an existing tag |
gtm_list_triggers |
List triggers in a workspace |
gtm_create_trigger |
Create a new trigger |
gtm_list_variables |
List variables in a workspace |
gtm_create_variable |
Create a new variable (constant, data layer, cookie, URL, etc.) |
gtm_publish_container |
Create and publish a new container version |
🔐 How Authentication Works
⬆ top
This MCP server supports two authentication methods:
Method A: Application Default Credentials (ADC)
With Application Default Credentials (ADC) authentication:
- ADC automatically discovers credentials from multiple sources:
GOOGLE_APPLICATION_CREDENTIALSenvironment variable pointing to a service account JSON file- Google Cloud SDK credentials (
gcloud auth application-default login) - Service account attached to GCE/GKE/Cloud Run instances
- Other Google Cloud environments
- Grant the account access to your GTM account
- Automatic authentication - no browser interaction required
- Tokens are managed automatically by Google's auth library
Benefits:
- ✅ No browser interaction required
- ✅ Perfect for server environments
- ✅ Automatic token refresh
- ✅ Flexible credential sources
- ✅ Works seamlessly in Google Cloud environments
- ✅ Simple for local development with gcloud CLI
How it works:
When you set GTM_AUTH_METHOD=service_account, the library uses google.auth.default() to automatically discover credentials. This is the same approach used by the official Google Analytics MCP server and is Google's recommended authentication method.
Method B: OAuth 2.0 Authentication (Default)
With OAuth 2.0 authentication:
- You create OAuth credentials in your own Google Cloud project
- You configure those credentials in Claude Desktop
- First use: Browser opens to authorize access to your GTM account
- Your tokens are saved locally on your machine (
~/.gtm-mcp/token.json) for future use
Benefits:
- ✅ You maintain full control over the OAuth app
- ✅ No shared credentials between users
- ✅ You can revoke access anytime
- ✅ Your credentials stay private
- ✅ Compliant with Google's OAuth policies
Upgrade
Run pip install --upgrade gtm-mcp
❓ Troubleshooting
Application Default Credentials (ADC) Issues
"Failed to load Application Default Credentials" Error
Problem: The MCP server can't discover any credentials using ADC.
Solution: Choose one of these credential sources:
-
Using a service account file:
- Set
GOOGLE_APPLICATION_CREDENTIALSto the path of your service account JSON file - Ensure the path is absolute and points to a valid JSON file
- On Windows, use double backslashes:
C:\\Users\\... - Restart Claude Desktop after editing the config
- Set
-
Using gcloud CLI:
- Run
gcloud auth application-default login - Follow the browser flow to authenticate
- Ensure your Google account has GTM access
- Restart Claude Desktop
- Run
-
Running on Google Cloud:
- Ensure your GCE/GKE/Cloud Run resource has a service account attached
- Grant the service account access to your GTM account
"Service account has no access" Error
Problem: The service account or user account can't access your GTM account.
Solution:
- Go to GTM → Admin → User Management
- Verify the account email is listed with appropriate permissions
- For service accounts: add the service account email from your JSON file
- For gcloud CLI: add your Google account email
- Grant at least "Read" permission (or higher based on your needs)
Which Authentication Method Am I Using?
Check your claude_desktop_config.json:
- If you see
GTM_AUTH_METHOD: "service_account"→ Application Default Credentials (ADC) - If you see
GTM_CLIENT_ID,GTM_CLIENT_SECRET→ OAuth 2.0 - If no
GTM_AUTH_METHODis set → OAuth 2.0 (default)
OAuth 2.0 Issues
"Missing required OAuth credentials" Error
Problem: The MCP server can't find your OAuth credentials.
Solution: Make sure you:
- Set
GTM_AUTH_METHOD=oauth(or omit it, as oauth is default) - Set
GTM_CLIENT_ID,GTM_CLIENT_SECRET, andGTM_PROJECT_IDcorrectly inclaude_desktop_config.json - Restarted Claude Desktop after editing the config
- Used the correct format (no extra quotes in JSON)
- The config file is valid JSON (use a JSON validator if unsure)
"Google hasn't verified this app" Warning
Problem: Google shows a security warning during first authorization.
Solution: This is completely normal for personal OAuth apps. Since you created the OAuth app yourself, Google shows this warning.
To proceed: Click "Advanced" → "Go to [App Name] (unsafe)"
This is safe because you control the app.
General Issues
Can't Access GTM Accounts
Possible causes:
- Your Google account doesn't have access to any GTM accounts (OAuth)
- Service account doesn't have GTM permissions (Service Account)
- You didn't grant all requested permissions during authorization (OAuth)
- Tag Manager API isn't enabled in your Google Cloud project
Solution:
- Verify your Google account or service account has GTM access
- For OAuth: Re-authorize by deleting
~/.gtm-mcp/token.jsonand trying again - For ADC/Service Account: Check GTM user management for the service account or user account email
- Check that Tag Manager API is enabled in Google Cloud Console
Connection Issues
Debugging steps:
- Verify Claude Desktop is completely restarted
- Check Claude Desktop logs for MCP server errors
- Verify
gtm-mcpcommand works: rungtm-mcpin terminal - Check your config file is valid JSON
- Ensure all required environment variables are set correctly
Package Not Found After Install
Problem: gtm-mcp command not found after installation.
Solution:
# Ensure pip install location is in PATH
pip install --user gtm-mcp
# Or use pipx for isolated installation
pipx install gtm-mcp
Revoking Access
For OAuth 2.0:
- Go to Google Account Permissions
- Find your app name in the list
- Click "Remove access"
- Delete the local token file:
rm ~/.gtm-mcp/token.json
You can re-authorize anytime by using any GTM tool in Claude again.
For Application Default Credentials (ADC):
If using a service account file:
- Go to GTM → Admin → User Management
- Find the service account email
- Click the remove button to revoke access
- Optionally delete the service account key from Google Cloud Console
If using gcloud CLI:
- Go to GTM → Admin → User Management
- Find your Google account email
- Click the remove button to revoke access
- Optionally revoke ADC locally:
gcloud auth application-default revoke
🔒 Security Notes
For OAuth 2.0:
- Your OAuth credentials are yours alone - keep them private
- Never share your Client Secret - treat it like a password
- Your access tokens are stored locally:
~/.gtm-mcp/token.json - You can regenerate credentials anytime in Google Cloud Console
- You can revoke access anytime from your Google account settings
For Application Default Credentials (ADC):
- Keep your JSON key file secure - it provides full access
- Never commit the JSON file to version control - add it to
.gitignore - Use restrictive file permissions -
chmod 600 service-account.jsonon Unix/Linux - Store the file in a secure location with limited access
- You can create new keys and delete old ones in Google Cloud Console
- Regularly rotate service account keys for better security
General:
- This server only accesses GTM - no other Google services
- Credentials are only used for Google Tag Manager API authentication
- No credentials are sent to any third-party services
💻 Development
Running Tests
pip install -e ".[dev]"
pytest
📝 License
⬆ top see LICENSE file for details
🤝 Contributing
⬆ top Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
For bugs and feature requests, please open an issue.
🆘 Getting Help
⬆ top If you encounter issues:
- Check the Troubleshooting section above
- Review Claude Desktop logs for error messages
- Verify your Google Cloud project has Tag Manager API enabled
- Ensure environment variables are set correctly in the config
- Open an issue on GitHub with:
- Your operating system
- Python version (
python --version) - Error messages from Claude Desktop logs
- Steps to reproduce the issue
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unboundai_gtm_mcp-0.0.6.tar.gz.
File metadata
- Download URL: unboundai_gtm_mcp-0.0.6.tar.gz
- Upload date:
- Size: 50.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.11.5 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b00b5cc098fa519603e955591cafc30e4aea95bc049704da3f1a524e691082f4
|
|
| MD5 |
28ccfaab2cadbf962ff603a9d40d3f97
|
|
| BLAKE2b-256 |
36acb224103976ad82fccbe9d49e89818b3b0ae3d705e643916ea2e8547cfb55
|
File details
Details for the file unboundai_gtm_mcp-0.0.6-py3-none-any.whl.
File metadata
- Download URL: unboundai_gtm_mcp-0.0.6-py3-none-any.whl
- Upload date:
- Size: 51.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.11.5 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a7c6755bbb45eb3dec3e7a54aefab5555c3b78648a5354377b9e49c5dbec2cd
|
|
| MD5 |
a9536a0563da6ca0e56a5290f7b31dfb
|
|
| BLAKE2b-256 |
ece834ef63dc9ea210e3b4d3b23971df25b2c1163f773afa9ab03a6008a16296
|