SuperAPI AI Directory

google-tag-manager-mcp-server

Interface to the Google Tag Manager API.

Open website

About this tool

Purpose

This MCP server provides an interface to Google Tag Manager, enabling MCP-capable clients to access the Google Tag Manager API through tool calls. The project is developed and maintained by the Stape team and is licensed under Apache 2.0.

Main capabilities

The server comes in two forms: a hosted server and a local CLI. Both provide the same 20 GTM tools; the difference lies in who handles Google authentication. The tools access Google through a GtmAuthProvider (getAccessToken(): Promise<string>) rather than being bound to a specific session, so the same set of tools can support both servers at once and can also be used for a self-hosted server with private authentication.

How to use

Hosted server

The hosted server is a remote HTTP-based MCP endpoint, at the address https://gtm-mcp.stape.io/mcp。能够自行完成 Clients with the Google OAuth flow (Claude Desktop, Claude Code, VS Code, Copilot CLI, Cursor, ChatGPT) can connect directly to this URL, signing in with Google on first connection; other clients (Antigravity, stdio-only clients) can access the remote HTTP MCP server through mcp-remote, a small bridge tool. After changing the client configuration, the client must be restarted.

Key points for configuring each client:

  • Claude Desktop: Can be added via a custom connector (Customize → Connectors → Add custom connector), with a name such as gtm-mcp-server and the URL https://gtm-mcp.stape.io/mcp;若询问认证方式选择 Sign in now; if asked for an OAuth client, choose Register automatically (the server does not support Use Claude's published identity). For Team and Enterprise editions, an Owner adds it in the organization settings, and members then each connect and sign in with their own Google account. This connector is also available on claude.ai. It can also be configured via claude_desktop_config.json using mcp-remote.
  • Claude Code: Directly supports HTTP and the OAuth handshake, with no bridge needed. After adding it, run /mcp within Claude Code (or run claude mcp login gtm-mcp-server from the shell) and sign in with Google; claude mcp list shows the connection status. By default it is added only to the current project; add --scope user to use it globally; --scope project writes to the project's .mcp.json, which suits the hosted server (contains no secrets, and each member signs in with their own Google account), but is not suitable for the local CLI (whose entry contains credentials).
  • VS Code: The MCP client natively supports HTTP servers and their OAuth flow, with no need for mcp-remote. Add the configuration to .vscode/mcp.json (the current workspace) or to the file opened by MCP: Open User Configuration (all workspaces). When the server first starts, VS Code will ask you to sign in with Google. GitHub Copilot Chat in VS Code uses VS Code's own MCP client and reads the same configuration, so no separate configuration is needed.
  • Copilot CLI: Natively completes OAuth for remote HTTP servers; sign in with Google when prompted. The configuration is written to ~/.copilot/mcp-config.json and can be checked with copilot mcp get gtm-mcp-server; in an interactive session, /mcp add can also be done through a form.
  • Cursor: Directly supports HTTP and the OAuth flow, with no need for mcp-remote. Add the configuration to .cursor/mcp.json (current project) or ~/.cursor/mcp.json (all projects), then sign in with Google in the server entry under Customize in the Cursor sidebar.
  • Antigravity: Its OAuth support for remote HTTP servers currently cannot pass the token to the server (antigravity-cli#25), so hosted servers need to use mcp-remote. Add the configuration to ~/.gemini/config/mcp_config.json, shared by the editor and CLI; in the editor it can be opened from the agent panel via … → MCP Servers → Manage MCP Servers → View raw config, or run agy mcp add from the Antigravity CLI (an entry with the same name will be replaced). mcp-remote will open Google sign-in in the browser on first connection.
  • ChatGPT: On the web version, go to Plugins, select +, then select Add custom MCP server. Enter a name (e.g., gtm-mcp-server), and under Connection set the server URL to https://gtm-mcp.stape.io/mcp,认证设为 OAuth (the server supports dynamic client registration, so no client ID or secret is needed). After confirming the risk warning, select Create as a plugin, install it from your personal plugins, sign in with Google, and select it with @ in the prompt box. ChatGPT can only access public servers, so there is no local CLI option and only hosted servers are supported; workspace administrators can restrict custom MCP servers.
  • Other MCP clients: If they support remote HTTP MCP servers with OAuth, point them directly at https://gtm-mcp.stape.io/mcp;否则使用 mcp-remote to bridge to a hosted server, or use the local CLI directly and provide your own credentials.

Local CLI

The local CLI does not go through the OAuth flow and does not transmit data via someone else's server; you need to provide a service account key or refresh token yourself. In Claude Desktop, it can be configured via Settings → Developer → Edit Config. All credential options are listed in the CLI README.

Troubleshooting

  • Authentication errors: If a tool returns a 401/403 error, you can have the assistant run gtm_auth_status. It will report whether the current Google token is accepted, when it expires, and which Tag Manager scopes are missing, without leaking the token.
  • MCP server name length limit: Some MCP clients (such as Cursor AI) have a 60-character limit on the combined length of the server name and tool names. If a longer server name is used in the configuration (such as gtm-mcp-server-your-additional-long-name), some tools may be filtered out. It is recommended to use a shorter server name (such as gtm-mcp-server).
  • Clearing the MCP cache: If connecting via mcp-remote (Antigravity, Claude Desktop configured that way, or other clients using the mcp-remote block), credential information is stored in ~/.mcp-auth (or the location pointed to by MCP_REMOTE_CONFIG_DIR). If problems persist, clear that cache and restart the MCP client.

Testing changes locally

Changes fall into two categories:

  • Changes to packages/core or packages/cli: This is the tool logic itself (schema, GTM API calls, error handling), and the vast majority of fixes or additions are here. No Google Cloud OAuth client or Worker setup is needed; just build from source and run the CLI directly with existing credentials. Point the MCP client at the local build instead of npx; the credential options are the same as in the Claude Desktop local CLI example; getting an access token from the OAuth Playground is the fastest way to test a single change.
  • apps/worker's changes: only the hosted server's own code is needed, including the OAuth flow, routing, session handling, approval and status pages. This will run that code locally using your own Google Cloud OAuth credentials, rather than gtm-mcp.stape.io. Steps: create or select a project in the Google Cloud Console and enable the Tag Manager API; configure the OAuth consent screen (External is fine; when the app is in Testing publishing status, only test users can sign in); add your own Google account under Audience > Test users; create a Web application type in APIs & Services > Credentials > Create Credentials > OAuth client ID; add to Authorized redirect URIs http://localhost:8788/callback(Authorized JavaScript origins can be left blank; this flow is server-side only, with no browser JS directly calling Google); after saving, copy the generated Client ID and Client secret; copy the example file and fill in the above values (.dev.vars is already git-ignored, for local use only, and will not be committed). npm run build compiles the core package that the Worker bundle depends on; npm run dev runs in http://localhost:8788 to start the Worker. Claude Desktop's custom connector requires a publicly reachable URL, so pointing to localhost can only use mcp-remote. After restarting Claude Desktop, a browser will open for the Google OAuth flow; sign in with the account added as a test user in step 1. Note: if you have previously connected to the hosted server (or switched between local and hosted), first clear the mcp-remote cache and fully restart the MCP client, otherwise a stale or cached connection may be reused.

Release and development

Versions and changelogs are managed via Changesets. Add a changeset along with the changes that should be released. After merging to main, the release workflow opens a "Version Packages" PR; merging that PR publishes to npm, first core, then the CLI that depends on it. The Worker is private, is never published, and is deployed on every push to main. Pull requests run all the above checks plus the Worker bundle check, and flag changes to published packages that lack a changeset. In apps/worker, @modelcontextprotocol/sdk and agents are both pinned to exact versions. The SDK identifies tool schemas via instanceof, so the entire workspace must resolve to a single copy, and the agents release pins the SDK version it was built against. The two need to be upgraded together and deployed deliberately.

Repository structure

An npm workspace containing one app and two published packages.

Applicable scenarios and limitations

Suitable for users who need to operate Google Tag Manager through an MCP client, with the option of a hosted server (convenient, built-in OAuth) or a local CLI (data does not pass through someone else's server, uses your own credentials). Limitations include: ChatGPT only supports the hosted server; Antigravity's OAuth support for remote HTTP servers is not yet complete and requires mcp-remote; some clients have server name length limits; local testing of Worker changes requires setting up your own Google Cloud OAuth client.