gtm-mcp-server
A Model Context Protocol server for Google Tag Manager that uses service account authentication, providing tools to manage accounts, containers, workspaces, tags, triggers, variables, and versions.
README
GTM MCP Server
A Model Context Protocol (MCP) server for Google Tag Manager using service account authentication - no OAuth dance required.
Features
- No OAuth required - Uses Google Service Account for authentication
- Covers the core GTM workflow - Accounts, Containers, Workspaces, Tags, Triggers, Variables, Built-In Variables, and Versions (29 tools)
- Local & private - Runs entirely on your machine
- Works with Claude Desktop, Cursor, and other MCP clients
Quick Start
1. Create a Google Cloud Service Account
- Go to Google Cloud Console
- Select or create a project
- Enable the Tag Manager API:
- Go to APIs & Services → Library
- Search for "Tag Manager API"
- Click Enable
- Create a service account:
- Go to IAM & Admin → Service Accounts
- Click "Create Service Account"
- Give it a name (e.g., "gtm-mcp-server")
- Click Create and Continue (skip optional permissions)
- Click Done
- Create a key:
- Click on your new service account
- Go to Keys tab
- Add Key → Create new key → JSON
- Save the downloaded JSON file somewhere safe (e.g.,
~/.config/gtm-service-account.json)
2. Grant GTM Access to the Service Account
- Go to Google Tag Manager
- Click Admin (gear icon)
- Under Account, click "User Management"
- Click the + button to add a user
- Enter the service account email (looks like
name@project-id.iam.gserviceaccount.com) - Set appropriate permissions:
- Read - for listing/viewing only
- Edit - for creating/modifying tags, triggers, variables
- Publish - for publishing versions
- Admin - for full access including user management
3. Configure Your MCP Client
Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on Mac, %APPDATA%\Claude\claude_desktop_config.json on Windows):
{
"mcpServers": {
"gtm": {
"command": "npx",
"args": ["-y", "gtm-mcp-server"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account.json"
}
}
}
}
Cursor
Add to your Cursor MCP settings:
{
"mcpServers": {
"gtm": {
"command": "npx",
"args": ["-y", "gtm-mcp-server"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/service-account.json"
}
}
}
}
4. Restart Your Client
After saving the config, restart your MCP client. You should see the GTM tools available.
Available Tools
Account Management
gtm_list_accounts- List all accessible GTM accounts
Container Management
gtm_list_containers- List containers in an accountgtm_get_container- Get container details
Workspace Management
gtm_list_workspaces- List workspaces in a containergtm_create_workspace- Create a new workspacegtm_get_workspace_status- Show pending changes and merge conflicts in a workspacegtm_sync_workspace- Sync a workspace to the latest container version
Tag Management
gtm_list_tags- List all tags in a workspacegtm_get_tag- Get full tag details with parametersgtm_create_tag- Create a new taggtm_update_tag- Update an existing taggtm_delete_tag- Delete a tag
Trigger Management
gtm_list_triggers- List all triggers in a workspacegtm_get_trigger- Get full trigger detailsgtm_create_trigger- Create a new triggergtm_update_trigger- Update an existing triggergtm_delete_trigger- Delete a trigger
Variable Management
gtm_list_variables- List all variables in a workspacegtm_get_variable- Get full variable detailsgtm_create_variable- Create a new variablegtm_update_variable- Update an existing variablegtm_delete_variable- Delete a variable
Built-In Variable Management
gtm_list_built_in_variables- List enabled built-in variablesgtm_enable_built_in_variables- Enable built-in variables (e.g. Page URL, Click Classes)gtm_disable_built_in_variables- Disable built-in variables
Version Management
gtm_list_versions- List container versionsgtm_get_live_version- Get the currently live (published) versiongtm_create_version- Create a version from a workspacegtm_publish_version- Publish a version to make it live
All list tools return results one page at a time; when more results exist, the response includes a page_token to pass to the next call.
Usage Examples
Once configured, you can ask Claude things like:
- "List my GTM accounts"
- "Show me all containers in account 123456"
- "What tags are in my website container?"
- "Create a new pageview trigger called 'All Pages'"
- "Create a custom HTML tag that fires on all pages"
- "Create a version and publish it"
Troubleshooting
"GOOGLE_APPLICATION_CREDENTIALS not set"
Make sure the environment variable is set in your MCP client config and points to a valid JSON key file.
"Permission denied" errors
- Verify the service account email has been added to your GTM account
- Check that the permission level is sufficient for the operation
"API not enabled" errors
Make sure the Tag Manager API is enabled in your Google Cloud project.
Server not appearing in Claude Desktop
- Check that the paths in your config are correct
- Look at Claude Desktop's MCP logs for errors
- Try running
npx gtm-mcp-serverdirectly to see any error messages
Development
# Clone the repository
git clone https://github.com/alexstansfield/gtm-mcp-server.git
cd gtm-mcp-server
# Install dependencies
npm install
# Build
npm run build
# Watch mode for development
npm run dev
# Test with MCP Inspector
npx @modelcontextprotocol/inspector node dist/index.js
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。