GTM MCP
Run from the gtm-mcp repository root unless --prefix is used.
Execute setup
- •Install dependencies.
bash
npm install
- •Run interactive setup.
bash
npm run setup
- •Ensure
.envvalues are unquoted. Use:GOOGLE_CLIENT_ID=...GOOGLE_CLIENT_SECRET=...GOOGLE_REDIRECT_URI=http://127.0.0.1:8085GTM_MCP_TOKEN_PATH=.gtm-mcp/tokens.json
Register MCP servers
Choose only what the user needs.
- •Codex global registration:
bash
npm run register:codex
- •Claude user registration (default):
bash
npm run register:claude
- •Claude user registration (explicit):
bash
npm run register:claude:user
- •Claude project registration:
bash
npm run register:claude:project
- •Claude local registration:
bash
npm run register:claude:local
If called from another directory, register with:
bash
npm --prefix /absolute/path/to/gtm-mcp run register:codex npm --prefix /absolute/path/to/gtm-mcp run register:claude
Run first OAuth flow
- •Open a new Codex/Claude session after MCP registration.
- •Call
oauth_get_consent_url. - •Open returned URL in an external browser.
- •Approve and copy the authorization
code. - •Call
oauth_exchange_codewith the code. - •Verify with
oauth_status.
Use GTM MCP tools in practice
After OAuth is complete, prefer this sequence.
- •Discover resources.
- •
gtm_list_accounts - •
gtm_list_containerswithaccountId - •
gtm_list_workspaceswithaccountId,containerId
- •
- •Inspect existing setup.
- •
gtm_list_tags - •
gtm_list_triggers - •
gtm_list_variables
- •
- •Create/update resources in workspace.
- •
gtm_create_tag/gtm_update_tag - •
gtm_create_trigger/gtm_update_trigger - •
gtm_create_variable/gtm_update_variable
- •
- •Delete only when explicitly requested.
- •
gtm_delete_tag - •
gtm_delete_trigger - •
gtm_delete_variable
- •
Common payload shape reminders:
- •
accountId,containerId,workspaceIdaccept raw IDs or full path fragments. - •
tag,trigger,variableare passed as JSON objects from GTM API schema. - •For unsupported endpoints, use
gtm_request.
gtm_request examples:
- •List accounts:
- •
{ "method": "GET", "path": "/accounts" }
- •
- •List container versions:
- •
{ "method": "GET", "path": "/accounts/{accountId}/containers/{containerId}/versions" }
- •
Troubleshoot quickly
- •
Error 400: invalid_requeston Google sign-in:- •Remove quotes from
client_idandredirect_uri. - •Ensure redirect URI is exactly
http://127.0.0.1:8085in both Google Cloud and.env.
- •Remove quotes from
- •MCP not visible:
- •Re-run the corresponding
register:*command. - •Start a new Codex/Claude session.
- •Re-run the corresponding
- •Existing
gtmentry not updated:- •Current scripts skip when same name exists.
- •Remove manually then re-run register command if update is required.