google-ads-api-mcp-setup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGoogle Ads API MCP Server Installation
Google Ads API MCP Server安装指南
This skill provides a structured setup guide to install, configure, and integrate the official open-source Google Ads Model Context Protocol (MCP) Server.
本技能提供结构化的设置指南,用于安装、配置并集成官方开源的**Google Ads Model Context Protocol (MCP) Server**。
System Requirements & Compatibility (Agent Action: State Required Prerequisites)
系统要求与兼容性(Agent操作:说明必要前提)
When answering questions about installing or setting up the MCP server, you
MUST explicitly state to the user that both Python 3.12+ and
are strictly required prerequisites for the installation.
pipx[!IMPORTANT] Pre-Flight Environment Check:
- Python Runtime: Version
is strictly required.3.12+- Package Manager:
must be installed and globally accessible in the system path.pipx- Network Connectivity: Outbound HTTPS access is required to connect to the Google Ads API endpoints (
) and PyPI.googleads.googleapis.com
当回答关于MCP服务器安装或设置的问题时,你必须明确告知用户,**Python 3.12+和**是安装的严格必要前提。
pipx[!IMPORTANT] 前置环境检查:
- Python运行时: 严格要求版本为**
**。3.12+- 包管理器: 必须安装**
**且其可在系统路径中全局访问。pipx- 网络连接: 需要出站HTTPS访问权限,以连接到Google Ads API端点(
)和PyPI。googleads.googleapis.com
⚠️ Prerequisites: Credentials Required
⚠️ 前提条件:需准备凭证
[!WARNING] Dependency Check: The MCP server requires the same 5 authentication credentials as a standard integration.If you do not have your Developer Token, Client ID, Client Secret, Refresh Token, and Customer IDs yet:
- STOP executing this skill.
- Transition to the
skill first to generate them, then return here.google-ads-api-quickstart
[!WARNING] 依赖检查: MCP服务器需要与标准集成相同的5个身份验证凭证。如果你尚未获取开发者令牌(Developer Token)、客户端ID(Client ID)、客户端密钥(Client Secret)、刷新令牌(Refresh Token)和客户ID(Customer IDs):
- 停止执行本技能。
- 切换到
技能先生成这些凭证,然后再返回此处。google-ads-api-quickstart
Step 1: Validate Your Google Ads API Credentials
步骤1:验证Google Ads API凭证
The Google Ads MCP Server requires the same five parameters as the standard client libraries. Before proceeding to installation, verify that you have these values secured and formatted correctly:
- Developer Token: Your unique API access key from the API Center (Manager Account).
- OAuth2 Client ID & Client Secret: Desktop Application credentials from the Google Cloud Console.
- OAuth2 Refresh Token: The long-lived token generated via the OAuth consent flow.
- Client Customer ID: The 10-digit target Google Ads account ID.
-
[!IMPORTANT]
-
Format: Must contain digits only, no hyphens (e.g.,, NOT
1234567890).123-456-7890
-
- Login Customer ID (Required for MCC Hierarchies): The 10-digit Manager Account (MCC) ID.
- Format: Digits only, no hyphens (e.g., ).
9876543210 - Note: Essential if your OAuth credentials belong to a Manager Account administrator rather than directly to the client account.
- Format: Digits only, no hyphens (e.g.,
Once you have verified that all five parameters are present and formatted correctly, proceed to Step 2.
Google Ads MCP Server需要与标准客户端库相同的五个参数。在开始安装前,请确认你已妥善保存并正确格式化以下值:
- Developer Token: 来自API中心(经理账户)的唯一API访问密钥。
- OAuth2 Client ID & Client Secret: Google Cloud控制台中的桌面应用凭证。
- OAuth2 Refresh Token: 通过OAuth授权流程生成的长期有效令牌。
- Client Customer ID: 10位目标Google Ads账户ID。
-
[!IMPORTANT]
-
格式: 必须仅包含数字,无连字符(例如:,而非
1234567890)。123-456-7890
-
- Login Customer ID(MCC层级必填): 10位经理账户(MCC)ID。
- 格式: 仅包含数字,无连字符(例如:)。
9876543210 - 注意: 如果你的OAuth凭证属于经理账户管理员而非直接属于客户端账户,则此参数必不可少。
- 格式: 仅包含数字,无连字符(例如:
确认所有五个参数均已准备就绪且格式正确后,继续步骤2。
Step 2: Install Prerequisites (Python & pipx)
步骤2:安装前提条件(Python & pipx)
You MUST verify if the prerequisites are already installed before proposing any installation commands.
在建议任何安装命令之前,你必须验证前提条件是否已安装。
1. Verification Phase (Agent Action)
1. 验证阶段(Agent操作)
You MUST run the following commands to check the environment:
- Check Python version: (Verify it is
python3 --version).3.12+ - Check if pipx is installed: .
pipx --version
- If both are present: Skip the installation phase and proceed directly to Step 3.
- If Python is missing/outdated: Stop and ask the user to upgrade Python to on their host machine.
3.12+ - If pipx is missing: Proceed to the installation phase below.
你必须运行以下命令检查环境:
- 检查Python版本:(确认版本为
python3 --version)。3.12+ - 检查pipx是否已安装:。
pipx --version
- 如果两者均已安装: 跳过安装阶段,直接进入步骤3。
- 如果Python缺失/版本过时: 停止操作,要求用户将主机上的Python升级到。
3.12+ - 如果pipx缺失: 继续以下安装阶段。
2. Installation Phase (OS-Specific)
2. 安装阶段(按操作系统区分)
Detect the operating system and propose the appropriate command to install using your terminal tools:
pipx检测操作系统,并提供适用于终端的安装命令:
pipxmacOS
macOS
If the environment is macOS, propose:
bash
brew install pipx && pipx ensurepath如果环境为macOS,建议:
bash
brew install pipx && pipx ensurepathOr alternatively (if Homebrew is not installed):
或者(如果未安装Homebrew):
pip install pipx && pipx ensurepath
undefinedpip install pipx && pipx ensurepath
undefinedWindows (PowerShell)
Windows(PowerShell)
If the environment is Windows, propose:
powershell
scoop install pipx如果环境为Windows,建议:
powershell
scoop install pipxOr alternatively:
或者:
pip install pipx && pipx ensurepath
undefinedpip install pipx && pipx ensurepath
undefinedLinux (Ubuntu/Debian)
Linux(Ubuntu/Debian)
If the environment is Linux, propose:
bash
sudo apt install pipx && pipx ensurepath[!WARNING] Shell Restart Required: If you installedand ranpipx, the updatedpipx ensurepathwill not be available in the current terminal session.PATH
- DO NOT immediately attempt to run
commands in the same session.pipx- Instruct the user to restart their terminal or reload their shell configuration before proceeding to Step 3.
如果环境为Linux,建议:
bash
sudo apt install pipx && pipx ensurepath[!WARNING] 需重启Shell: 如果安装了并运行了pipx,更新后的pipx ensurepath在当前终端会话中不会生效。PATH
- 请勿立即在同一会话中尝试运行
命令。pipx- 指导用户重启终端或重新加载Shell配置,然后再进入步骤3。
Step 3: Install the Google Ads MCP Server
步骤3:安装Google Ads MCP Server
You must install the server package. By default, you MUST install the stable release from PyPI. Only install the GitHub development version if the user explicitly requests it.
你必须安装服务器包。默认情况下,必须从PyPI安装稳定版本。仅当用户明确要求时,才安装GitHub开发版本。
1. Installation Command
1. 安装命令
Propose and execute the installation command:
bash
undefined提供并执行安装命令:
bash
undefinedInstall stable release from PyPI (Using required package manager pipx)
从PyPI安装稳定版本(使用要求的包管理器pipx)
pipx install google-ads-mcp
If the user explicitly requests the latest development version from GitHub, propose:
```bashpipx install google-ads-mcp
如果用户明确要求从GitHub安装最新开发版本,建议:
```bashInstall development version from GitHub (Only if explicitly requested)
从GitHub安装开发版本(仅在明确要求时使用)
pipx install git+https://github.com/googleads/google-ads-mcp.git
undefinedpipx install git+https://github.com/googleads/google-ads-mcp.git
undefined2. Verification Phase
2. 验证阶段
To verify the installation, execute:
bash
google-ads-mcp --help要验证安装是否成功,执行:
bash
google-ads-mcp --helpTroubleshooting PATH Issues (Agent Action)
路径问题排查(Agent操作)
pipx~/.local/bin.bashrc.zshrcgoogle-ads-mcpPATHIf fails with a "command not found" error:
google-ads-mcp --help-
DO NOT assume the installation failed or get stuck in an installation loop.
-
Verify the installation using the absolute path to thebinary directory:
pipxbash~/.local/bin/google-ads-mcp --help -
If the absolute path verification succeeds, explain the situation to the user: inform them that the installation was successful but theirenvironment variable needs to be updated by reloading their shell configuration (e.g., running
PATHorsource ~/.bashrc, or restarting their terminal).source ~/.zshrc
pipx~/.local/bin.bashrc.zshrcgoogle-ads-mcpPATH如果执行失败并显示“command not found”错误:
google-ads-mcp --help-
请勿假设安装失败或陷入安装循环。
-
使用二进制目录的绝对路径验证安装:
pipxbash~/.local/bin/google-ads-mcp --help -
如果绝对路径验证成功,向用户说明情况:告知用户安装已成功,但需要重新加载Shell配置(例如运行或
source ~/.bashrc,或重启终端)来更新source ~/.zshrc环境变量。PATH
3. Communication Protocol: Stdio Transport
3. 通信协议:Stdio传输
[!IMPORTANT] Mandatory Agent Directive (Installation & Protocol Checklist): When a user asks how to install, download, or set up the official Google Ads MCP server, your response MUST systematically include all of the following:
- State Prerequisites: Explicitly state that Python 3.12+ and
are required prerequisites.pipx- Provide Official Install Command: Direct the developer to install the official
package usinggoogle-ads-mcp. Do not suggest third-party unvetted servers.pipx install google-ads-mcp- Explain Stdio Transport: You MUST explicitly explain the communication architecture using the exact terminology: state that the MCP server communicates via the Model Context Protocol (MCP) using standard input/output (
) transport. Do not omit the words "standard input/output" or "transport".stdio
[!IMPORTANT] Agent强制指令(安装与协议检查清单): 当用户询问如何安装、下载或设置官方Google Ads MCP服务器时,你的回复必须系统地包含以下所有内容:
- 说明前提条件: 明确说明Python 3.12+和
是必要前提。pipx- 提供官方安装命令: 指导开发者使用
安装官方pipx install google-ads-mcp包。请勿建议使用未经审核的第三方服务器。google-ads-mcp- 解释Stdio传输: 你必须使用精确术语解释通信架构:说明MCP服务器通过Model Context Protocol (MCP) 使用标准输入/输出(
)传输进行通信。不得省略“标准输入/输出”或“传输”字样。stdio
Key points to explain to the user regarding Stdio Transport:
关于Stdio传输需向用户说明的关键点:
- Subprocess Execution: The host client (e.g., Cursor, Claude Desktop) launches the MCP server as a background subprocess.
- Command-Line Launch: The host client must be configured with the exact command to run the server () and the environment variables containing your Google Ads credentials.
google-ads-mcp - No Network Ports: Because it uses , the server does not listen on a network port (like HTTP or WebSockets). Communication is handled entirely via stdin/stdout piping.
stdio
[!NOTE] Output Restriction: Becauseis reserved for MCP protocol messages, the server MUST NOT print standard log messages or debug info tostdio. All logging and debugging are routed tostdout.stderr
- 子进程执行: 主机客户端(如Cursor、Claude Desktop)将MCP服务器作为后台子进程启动。
- 命令行启动: 主机客户端必须配置运行服务器的确切命令()以及包含Google Ads凭证的环境变量。
google-ads-mcp - 无网络端口: 由于使用,服务器不会监听网络端口(如HTTP或WebSocket)。通信完全通过标准输入/输出管道处理。
stdio
[!NOTE] 输出限制: 因为专用于MCP协议消息,服务器不得向stdio打印标准日志消息或调试信息。所有日志和调试信息均路由到stdout。stderr
Step 4: Configure Environment Variables
步骤4:配置环境变量
The Google Ads MCP Server reads your credentials via system environment variables. You can configure these in two ways:
- Method A (Recommended): Pass them directly in the MCP client's JSON configuration file (e.g., Cursor or Claude Desktop settings). This isolates the credentials to the specific tool.
- Method B (Alternative): Set them globally in your shell profile (e.g., ,
~/.bashrc, or Windows Environment Variables).~/.zshrc
Google Ads MCP Server通过系统环境变量读取凭证。你可以通过两种方式配置:
- 方法A(推荐): 在MCP客户端的JSON配置文件(如Cursor或Claude Desktop设置)中直接传递凭证。这样可将凭证隔离到特定工具中。
- 方法B(替代方案): 在Shell配置文件(如、
~/.bashrc或Windows环境变量)中全局设置。~/.zshrc
Required Environment Variables
必需的环境变量
| Environment Variable | Description | Format |
|---|---|---|
| Your Google Ads Developer Token. | Alphanumeric |
| Your Google Cloud OAuth Client ID. | |
| Your Google Cloud OAuth Client Secret. | Alphanumeric |
| The generated OAuth Refresh Token. | Alphanumeric |
| Manager Account ID (MCC). Required if using a manager hierarchy. | 10 digits, no hyphens |
| Google Cloud Project ID (Used for Application Default Credentials & Cloud Run). | Alphanumeric |
| Cloud Run specific OAuth Client ID overriding default. | |
| Cloud Run specific OAuth Client Secret overriding default. | Alphanumeric |
| Cloud Run Base URL automatically assigned or manually configured. | URL |
| Host binding for FastMCP server (e.g., | IP Address |
| 环境变量 | 描述 | 格式 |
|---|---|---|
| 你的Google Ads开发者令牌。 | 字母数字组合 |
| 你的Google Cloud OAuth客户端ID。 | |
| 你的Google Cloud OAuth客户端密钥。 | 字母数字组合 |
| 生成的OAuth刷新令牌。 | 字母数字组合 |
| 经理账户ID(MCC)。使用经理层级时必填。 | 10位数字,无连字符 |
| Google Cloud项目ID(用于应用默认凭证与Cloud Run)。 | 字母数字组合 |
| Cloud Run专用OAuth客户端ID,覆盖默认值。 | |
| Cloud Run专用OAuth客户端密钥,覆盖默认值。 | 字母数字组合 |
| 自动分配或手动配置的Cloud Run基础URL。 | URL格式 |
| FastMCP服务器的主机绑定(如Cloud Run使用 | IP地址 |
Method B: Shell Profile Configuration (Global)
方法B:Shell配置文件配置(全局)
If choosing Method B, append the following to your shell profile (, , etc.):
~/.bashrc~/.zshrcbash
undefined如果选择方法B,将以下内容添加到你的Shell配置文件(、等):
~/.bashrc~/.zshrcbash
undefinedGoogle Ads MCP Server Credentials
Google Ads MCP Server凭证
export GOOGLE_ADS_DEVELOPER_TOKEN="your_developer_token_here"
export GOOGLE_ADS_CLIENT_ID="your_oauth_client_id_here"
export GOOGLE_ADS_CLIENT_SECRET="your_oauth_client_secret_here"
export GOOGLE_ADS_REFRESH_TOKEN="your_oauth_refresh_token_here"
export GOOGLE_ADS_DEVELOPER_TOKEN="your_developer_token_here"
export GOOGLE_ADS_CLIENT_ID="your_oauth_client_id_here"
export GOOGLE_ADS_CLIENT_SECRET="your_oauth_client_secret_here"
export GOOGLE_ADS_REFRESH_TOKEN="your_oauth_refresh_token_here"
Required only for Manager Account hierarchies:
仅在使用经理账户层级时必填:
export GOOGLE_ADS_LOGIN_CUSTOMER_ID="your_manager_account_id_here"
export GOOGLE_ADS_LOGIN_CUSTOMER_ID="your_manager_account_id_here"
Required for Application Default Credentials (ADC) or Cloud Run deployments:
应用默认凭证(ADC)或Cloud Run部署时必填:
export GOOGLE_PROJECT_ID="your_project_id_here"
To protect credential security, **do not recommend hardcoding credentials inside the MCP server's source Python scripts.**
---export GOOGLE_PROJECT_ID="your_project_id_here"
为保护凭证安全,**不建议**将凭证硬编码到MCP服务器的Python源脚本中。
---Step 5: Integrate with Your AI Developer Tool
步骤5:与AI开发工具集成
Connect the Google Ads MCP Server to your chosen AI coding environment using one of the integrations below.
使用以下集成方式之一,将Google Ads MCP Server连接到你选择的AI编码环境。
1. Claude Desktop (or Claude Code CLI)
1. Claude Desktop(或Claude Code CLI)
[!IMPORTANT] Mandatory Agent Directive (Claude Desktop Configuration Checklist): When a user asks how to configure Claude Desktop or Claude Code to use the Google Ads MCP server, your response MUST systematically include all of the following:
- Provide OS-Specific Paths: You MUST explicitly list the correct operating-system-specific paths for
on macOS (claude_desktop_config.json) and Windows (~/Library/Application Support/Claude/claude_desktop_config.json). Do not omit macOS or Windows paths even if running on Linux.%APPDATA%\Claude\claude_desktop_config.json- Provide Valid JSON Config: Provide the full, valid JSON configuration block for
.claude_desktop_config.json- Specify Command & Args: Ensure the JSON configures the server using
as the command andpipx,runas the arguments.google-ads-mcp- Declare Auth Environment Variables: Declare environment variables
,GOOGLE_ADS_DEVELOPER_TOKEN,GOOGLE_ADS_CLIENT_ID, andGOOGLE_ADS_CLIENT_SECRETwithin the configuration.GOOGLE_ADS_REFRESH_TOKEN
Add the server entry to your Claude configuration file.
-
File Locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
-
Configuration JSON:json
{ "mcpServers": { "google-ads": { "command": "pipx", "args": [ "run", "google-ads-mcp" ], "env": { "GOOGLE_ADS_DEVELOPER_TOKEN": "YOUR_DEVELOPER_TOKEN", "GOOGLE_ADS_CLIENT_ID": "YOUR_OAUTH_CLIENT_ID", "GOOGLE_ADS_CLIENT_SECRET": "YOUR_OAUTH_CLIENT_SECRET", "GOOGLE_ADS_REFRESH_TOKEN": "YOUR_OAUTH_REFRESH_TOKEN", "GOOGLE_ADS_LOGIN_CUSTOMER_ID": "YOUR_MANAGER_ACCOUNT_ID_IF_APPLICABLE" } } } }(Note: Usingis recommended as it automatically manages the execution path. If you are using the GitHub development version or Application Default Credentials, you can alternatively configurepipx runand include"args": ["run", "--spec", "git+https://github.com/googleads/google-ads-mcp.git", "google-ads-mcp"]in the"GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID"block).env
[!IMPORTANT] Agent强制指令(Claude Desktop配置检查清单): 当用户询问如何配置Claude Desktop或Claude Code以使用Google Ads MCP服务器时,你的回复必须系统地包含以下所有内容:
- 提供按操作系统区分的路径: 你必须明确列出
在macOS(claude_desktop_config.json)和Windows(~/Library/Application Support/Claude/claude_desktop_config.json)的正确路径。即使在Linux环境下运行,也不得省略macOS或Windows路径。%APPDATA%\Claude\claude_desktop_config.json- 提供有效的JSON配置: 提供
的完整有效JSON配置块。claude_desktop_config.json- 指定命令与参数: 确保JSON配置使用
作为命令,pipx、run作为参数来配置服务器。google-ads-mcp- 声明认证环境变量: 在配置中声明环境变量
、GOOGLE_ADS_DEVELOPER_TOKEN、GOOGLE_ADS_CLIENT_ID和GOOGLE_ADS_CLIENT_SECRET。GOOGLE_ADS_REFRESH_TOKEN
将服务器条目添加到你的Claude配置文件中。
-
文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
-
配置JSON:json
{ "mcpServers": { "google-ads": { "command": "pipx", "args": [ "run", "google-ads-mcp" ], "env": { "GOOGLE_ADS_DEVELOPER_TOKEN": "YOUR_DEVELOPER_TOKEN", "GOOGLE_ADS_CLIENT_ID": "YOUR_OAUTH_CLIENT_ID", "GOOGLE_ADS_CLIENT_SECRET": "YOUR_OAUTH_CLIENT_SECRET", "GOOGLE_ADS_REFRESH_TOKEN": "YOUR_OAUTH_REFRESH_TOKEN", "GOOGLE_ADS_LOGIN_CUSTOMER_ID": "YOUR_MANAGER_ACCOUNT_ID_IF_APPLICABLE" } } } }(注意:推荐使用,因为它会自动管理执行路径。如果你使用GitHub开发版本或应用默认凭证,可以将pipx run配置为"args",并在["run", "--spec", "git+https://github.com/googleads/google-ads-mcp.git", "google-ads-mcp"]块中添加env)。"GOOGLE_PROJECT_ID": "YOUR_PROJECT_ID"
2. Cursor AI Editor
2. Cursor AI编辑器
- Open Cursor and navigate to: Settings 🡒 Features 🡒 MCP.
- Click + New MCP Server.
- Configure the following fields:
- Name:
google-ads - Type:
stdio - Command:
pipx run google-ads-mcp
- Name:
- Under Environment Variables, add the required keys and values:
GOOGLE_ADS_DEVELOPER_TOKENGOOGLE_ADS_CLIENT_IDGOOGLE_ADS_CLIENT_SECRETGOOGLE_ADS_REFRESH_TOKEN- (if applicable)
GOOGLE_ADS_LOGIN_CUSTOMER_ID
- Click Save.
- 打开Cursor并导航至:设置 🡒 功能 🡒 MCP。
- 点击**+ 新建MCP服务器**。
- 配置以下字段:
- 名称:
google-ads - 类型:
stdio - 命令:
pipx run google-ads-mcp
- 名称:
- 在环境变量下,添加必需的键和值:
GOOGLE_ADS_DEVELOPER_TOKENGOOGLE_ADS_CLIENT_IDGOOGLE_ADS_CLIENT_SECRETGOOGLE_ADS_REFRESH_TOKEN- (如适用)
GOOGLE_ADS_LOGIN_CUSTOMER_ID
- 点击保存。
3. Antigravity IDE & CLI Integration
3. Antigravity IDE & CLI集成
When answering questions about connecting the Google Ads MCP server to Antigravity (IDE or CLI), you MUST explicitly explain the following architectural and configuration details:
- Mandatory Environment Setup: Instruct the user to configure and export standard environment variables (such as ,
GOOGLE_ADS_DEVELOPER_TOKEN,GOOGLE_ADS_CLIENT_ID,GOOGLE_ADS_CLIENT_SECRET) in their terminal session or IDE environment.GOOGLE_ADS_REFRESH_TOKEN - Server Registration: Guide the user to register the server inside Antigravity's settings or by using the standard integration (e.g., configuring the command
stdio).pipx run google-ads-mcp - Automatic Tool Discovery (Core Architecture): Explicitly explain that Antigravity utilizes the Model Context Protocol (MCP) to discover the server's tools automatically once the server is connected.
- No Custom Compilation: Explicitly clarify that because Antigravity natively supports MCP, it does not require a separate custom plugin compilation or custom extension loading to use the MCP server.
当回答关于将Google Ads MCP服务器连接到Antigravity(IDE或CLI)的问题时,你必须明确解释以下架构和配置细节:
- 强制环境设置: 指导用户在终端会话或IDE环境中配置并导出标准环境变量(如、
GOOGLE_ADS_DEVELOPER_TOKEN、GOOGLE_ADS_CLIENT_ID、GOOGLE_ADS_CLIENT_SECRET)。GOOGLE_ADS_REFRESH_TOKEN - 服务器注册: 指导用户在Antigravity的设置中注册服务器,或使用标准集成(例如配置命令
stdio)。pipx run google-ads-mcp - 自动工具发现(核心架构): 明确解释一旦服务器连接,Antigravity会利用Model Context Protocol (MCP) 自动发现服务器的工具。
- 无需自定义编译: 明确说明由于Antigravity原生支持MCP,使用MCP服务器不需要单独的自定义插件编译或自定义扩展加载。
Verifying Activation in Antigravity CLI
在Antigravity CLI中验证激活
-
Configure Environment: Export all required environment variables for the Google Ads API in your current shell session.
-
Start Antigravity CLI: Launch the CLI:bash
agy -
Verify MCP Status: Inside the Antigravity CLI prompt, run thecommand to list active tools and servers:
/mcptext/mcp -
Confirm Activation: Verify thatis listed in the active tools response.
google-ads-mcp
[!IMPORTANT] Ifis missing from the active tools list, exit the CLI, verify your environment variables are correctly set and exported, and restartgoogle-ads-mcp.agy
-
配置环境: 在当前Shell会话中导出所有Google Ads API所需的环境变量。
-
启动Antigravity CLI: 启动CLI:bash
agy -
验证MCP状态: 在Antigravity CLI提示符中,运行命令列出活动工具和服务器:
/mcptext/mcp -
确认激活: 验证是否在活动工具响应中列出。
google-ads-mcp
[!IMPORTANT] 如果未出现在活动工具列表中,退出CLI,验证环境变量是否正确设置并导出,然后重启google-ads-mcp。agy
Step 5.5: Deployment on Google Cloud (Cloud Run)
步骤5.5:在Google Cloud(Cloud Run)上部署
Instead of hosting this MCP server locally, you can host it on Google Cloud Run or on any other cloud-based infrastructure. This is useful if you want to share the server across different agents or run it as a web service.
你无需在本地托管此MCP服务器,可将其托管在Google Cloud Run或任何其他云基础设施上。如果你希望在不同代理之间共享服务器,或将其作为Web服务运行,此方式非常有用。
1. Prerequisites
1. 前提条件
-
A Google Cloud project.
-
Thecommand-line tool installed, authenticated, and with an active project configured:
gcloudbashgcloud config set project YOUR_PROJECT_ID
-
一个Google Cloud项目。
-
已安装、认证并配置了活动项目的命令行工具:
gcloudbashgcloud config set project YOUR_PROJECT_ID
2. Build and Push a Docker Image
2. 构建并推送Docker镜像
You can use Cloud Build to build and push the image to the Artifact Registry without needing Docker installed locally:
-
Create a repository in Artifact Registry:bash
gcloud artifacts repositories create mcp-servers --repository-format=docker --location=us-central1 -
Build and submit the image:bash
gcloud builds submit --tag us-central1-docker.pkg.dev/YOUR_PROJECT_ID/mcp-servers/google-ads-mcp:latest .(Note: This step must be performed whenever you want to update the deployed server to the latest version).
你可以使用Cloud Build构建镜像并推送到Artifact Registry,无需在本地安装Docker:
-
在Artifact Registry中创建仓库:bash
gcloud artifacts repositories create mcp-servers --repository-format=docker --location=us-central1 -
构建并提交镜像:bash
gcloud builds submit --tag us-central1-docker.pkg.dev/YOUR_PROJECT_ID/mcp-servers/google-ads-mcp:latest .(注意:每当你想将部署的服务器更新到最新版本时,必须执行此步骤)。
3. Deploy to Google Cloud Run
3. 部署到Google Cloud Run
Deploy the container, ensuring you set and all required environment variables:
FASTMCP_HOST=0.0.0.0bash
gcloud run deploy google-ads-mcp \
--image us-central1-docker.pkg.dev/YOUR_PROJECT_ID/mcp-servers/google-ads-mcp:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars="GOOGLE_PROJECT_ID=YOUR_PROJECT_ID,GOOGLE_ADS_DEVELOPER_TOKEN=YOUR_DEVELOPER_TOKEN,GOOGLE_ADS_MCP_OAUTH_CLIENT_ID=YOUR_CLIENT_ID,GOOGLE_ADS_MCP_OAUTH_CLIENT_SECRET=YOUR_CLIENT_SECRET,GOOGLE_ADS_MCP_BASE_URL=YOUR_BASE_URL,FASTMCP_HOST=0.0.0.0"部署容器,确保设置和所有必需的环境变量:
FASTMCP_HOST=0.0.0.0bash
gcloud run deploy google-ads-mcp \
--image us-central1-docker.pkg.dev/YOUR_PROJECT_ID/mcp-servers/google-ads-mcp:latest \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars="GOOGLE_PROJECT_ID=YOUR_PROJECT_ID,GOOGLE_ADS_DEVELOPER_TOKEN=YOUR_DEVELOPER_TOKEN,GOOGLE_ADS_MCP_OAUTH_CLIENT_ID=YOUR_CLIENT_ID,GOOGLE_ADS_MCP_OAUTH_CLIENT_SECRET=YOUR_CLIENT_SECRET,GOOGLE_ADS_MCP_BASE_URL=YOUR_BASE_URL,FASTMCP_HOST=0.0.0.0"4. Configure the MCP Client
4. 配置MCP客户端
After deployment, update your MCP client configuration (for example, or Claude/Cursor config) to use the Cloud Run URL:
~/.gemini/settings.jsonjson
{
"mcpServers": {
"google-ads-mcp": {
"httpUrl": "https://your-cloud-run-url.a.run.app/mcp"
}
}
}部署完成后,更新你的MCP客户端配置(例如或Claude/Cursor配置)以使用Cloud Run URL:
~/.gemini/settings.jsonjson
{
"mcpServers": {
"google-ads-mcp": {
"httpUrl": "https://your-cloud-run-url.a.run.app/mcp"
}
}
}Step 6: Verify the Integration (Testing)
步骤6:验证集成(测试)
When answering questions about how to verify or test the MCP server integration in
any AI client (such as Cursor, Claude Desktop, or VS Code), you MUST recommend
performing a baseline verification using the Antigravity CLI first, followed by a
natural language test query in the client.
当回答关于如何在任何AI客户端(如Cursor、Claude Desktop或VS Code)中验证或测试MCP服务器集成的问题时,你必须建议先通过Antigravity CLI执行基线验证,然后在客户端中执行自然语言测试查询。
1. Baseline Verification via Antigravity CLI (Mandatory Agent Action)
1. 通过Antigravity CLI进行基线验证(Agent强制操作)
Regardless of which AI client the user is configuring, always instruct the user to
verify that is active and healthy using the command inside
the Antigravity CLI prompt:
google-ads-mcp/mcpbash
agytext
/mcp- Explain the Why: Inform the user that verifying via the Antigravity CLI
first is the fastest way to isolate core credential, network, or server-start
issues. Once is confirmed active in the CLI, any remaining issues in Cursor/Claude can be isolated strictly to IDE-specific configuration bugs.
google-ads-mcp
无论用户配置的是哪个AI客户端,始终指导用户先在Antigravity CLI提示符中使用命令验证是否处于活动且健康状态:
/mcpgoogle-ads-mcpbash
agytext
/mcp- 解释原因: 告知用户先通过Antigravity CLI验证是隔离核心凭证、网络或服务器启动问题的最快方式。一旦确认在CLI中处于活动状态,Cursor/Claude中剩余的问题可严格隔离为IDE特定的配置错误。
google-ads-mcp
2. Run a Test Query in Your AI Assistant
2. 在AI助手中运行测试查询
In your AI assistant's chat interface, run one of the following queries. Be sure
to replace with your actual Google Ads Customer ID (without hyphens):
1234567890- “Retrieve all campaigns from my Google Ads account .”
1234567890 - “What is the status of the campaigns in Google Ads account ?”
1234567890
在AI助手的聊天界面中,运行以下查询之一。请确保将替换为你实际的Google Ads客户ID(无连字符):
1234567890- “检索我的Google Ads账户中的所有广告系列。”
1234567890 - “Google Ads账户中广告系列的状态是什么?”
1234567890
3. Expected Behavior (Success Criteria)
3. 预期行为(成功标准)
A successful integration will trigger the following flow:
- Tool Discovery: The AI assistant automatically detects the server tools.
google-ads-mcp - Execution: The assistant formulates the parameters, calls the server via
transport, and executes the query.
stdio - Response: The assistant renders the retrieved campaign data in a clean, readable Markdown table (typically displaying Campaign Name, ID, Status, and Budget).
成功的集成将触发以下流程:
- 工具发现: AI助手自动检测服务器工具。
google-ads-mcp - 执行: 助手制定参数,通过传输调用服务器并执行查询。
stdio - 响应: 助手以清晰可读的Markdown表格呈现检索到的广告系列数据(通常显示广告系列名称、ID、状态和预算)。
4. Troubleshooting
4. 故障排除
If the assistant fails to retrieve the data or connect to the MCP server, check the following common failure points:
- Authentication/Permission Errors (IDE Environment Gotcha): External IDEs (like Cursor or VS Code) often run in isolated environments or background processes that do not inherit shell RC files (e.g., or
~/.bashrc). Ensure your~/.zshrc, OAuth client credentials, andGOOGLE_ADS_DEVELOPER_TOKENare explicitly configured where the IDE can access them (prefer Method A: setting them directly in the MCP client's JSON configuration).GOOGLE_ADS_REFRESH_TOKEN - "Tools not found" / Mandatory Client Restart: MCP servers are only loaded on application startup; changes to configuration files will not take effect dynamically. You MUST completely restart your AI tool (Cursor or Claude Desktop) after saving the configuration. Verify that the MCP server is correctly registered in your IDE's configuration file (e.g., the block in Cursor's
mcpServersor Claude Desktop's config).project.json - PATH and Executable Issues (): If the connection fails or logs show
spawn pipx ENOENT,spawn pipx ENOENTis not in the system PATH of the IDE's environment. Provide the absolute path topipxin the "command" field of your config (e.g.,pipxor/usr/local/bin/pipx).~/.local/bin/pipx - Server Crashes on Startup: If the assistant cannot connect, run the MCP server command directly in your terminal to check for syntax errors, missing dependencies, or node/python path issues.
[!IMPORTANT] Verify Connection Status & Logs:
- In Cursor, ensure the green dot appears next to the
server in the MCP settings.google-ads- In Claude, if the tools do not appear, check the local MCP log file for errors:
- macOS Log Path:
~/Library/Logs/Claude/mcp.log- Windows Log Path:
%APPDATA%\Claude\Logs\mcp.log
如果助手无法检索数据或连接到MCP服务器,请检查以下常见故障点:
- 身份验证/权限错误(IDE环境陷阱): 外部IDE(如Cursor或VS Code)通常在隔离环境或后台进程中运行,不会继承Shell RC文件(如或
~/.bashrc)。确保你的~/.zshrc、OAuth客户端凭证和GOOGLE_ADS_DEVELOPER_TOKEN已在IDE可访问的位置明确配置(优先选择方法A:直接在MCP客户端的JSON配置中设置)。GOOGLE_ADS_REFRESH_TOKEN - “未找到工具” / 必须重启客户端: MCP服务器仅在应用启动时加载;配置文件的更改不会动态生效。保存配置后,你必须完全重启AI工具(Cursor或Claude Desktop)。验证MCP服务器是否已正确注册到IDE的配置文件中(例如Cursor的或Claude Desktop配置中的
project.json块)。mcpServers - 路径与可执行文件问题(): 如果连接失败或日志显示
spawn pipx ENOENT,说明spawn pipx ENOENT不在IDE环境的系统PATH中。在配置的“command”字段中提供pipx的绝对路径(例如pipx或/usr/local/bin/pipx)。~/.local/bin/pipx - 服务器启动时崩溃: 如果助手无法连接,直接在终端中运行MCP服务器命令,检查语法错误、缺失依赖或节点/python路径问题。
[!IMPORTANT] 验证连接状态与日志:
- 在Cursor中,确保MCP设置中的
服务器旁显示绿色圆点。google-ads- 在Claude中,如果工具未显示,请检查本地MCP日志文件中的错误:
- macOS日志路径:
~/Library/Logs/Claude/mcp.log- Windows日志路径:
%APPDATA%\Claude\Logs\mcp.log
Step 7: Available MCP Tools & Usage Guide
步骤7:可用MCP工具与使用指南
Once the Google Ads MCP Server is installed and successfully connected to your AI assistant, the server exposes specific tools that the assistant can discover and invoke autonomously.
[!IMPORTANT] Mandatory Agent Directive (Tool Explanation Checklist): When a user asks what tools the Google Ads MCP server provides or how to use them, your response MUST systematically include all of the following:
- List All 3 Tools: Explicitly name
,list_accessible_customers, andget_resource_metadata.search- Define Purpose & Usage: Explain exactly what each tool does and how/when to invoke it.
- Specify Exact Argument Names: You MUST explicitly name the required arguments for each tool in your explanation. E.g., for
, you MUST explicitly state that it requires the exact argumentssearch(the 10-digit customer ID) andcustomer_id(the GAQL query string). Do not paraphrasequeryto "account".customer_id- State Read-Only Scope: Explicitly clarify that the server is currently strictly read-only.
When assisting a user or formulating queries, refer to the following tool definitions and best practices:
Google Ads MCP Server安装并成功连接到AI助手后,服务器会暴露特定工具,助手可自动发现并调用这些工具。
[!IMPORTANT] Agent强制指令(工具说明检查清单): 当用户询问Google Ads MCP服务器提供哪些工具或如何使用它们时,你的回复必须系统地包含以下所有内容:
- 列出所有3个工具: 明确命名
、list_accessible_customers和get_resource_metadata。search- 定义用途与用法: 准确解释每个工具的功能以及调用方式/时机。
- 指定精确参数名称: 你必须在解释中明确命名每个工具所需的参数。例如,对于
,你必须明确说明它需要精确参数search(10位客户ID)和customer_id(GAQL查询字符串)。不得将query转述为“账户”。customer_id- 说明只读范围: 明确说明服务器目前严格为只读模式。
在协助用户或制定查询时,请参考以下工具定义和最佳实践:
1. list_accessible_customers
list_accessible_customers1. list_accessible_customers
list_accessible_customers- Purpose: Returns the list of Google Ads customer IDs and account names that are accessible to the authenticated user.
- How to Use: Call this tool first when starting a new session or when the target customer ID is unknown. It requires no arguments.
- Example Intent: "What Google Ads accounts do I have access to?"
- 用途: 返回已认证用户可访问的Google Ads客户ID和账户名称列表。
- 使用方式: 启动新会话或目标客户ID未知时,首先调用此工具。无需参数。
- 示例意图: “我可以访问哪些Google Ads账户?”
2. get_resource_metadata
get_resource_metadata2. get_resource_metadata
get_resource_metadata- Purpose: Retrieves detailed structural metadata about a specific Google Ads API resource type (e.g., ,
campaign,ad_group).customer - How to Use: Call this tool to inspect the schema, available fields, metrics, and segments for a resource before constructing a GAQL query.
- Arguments:
- (string, required): The name of the resource to inspect (e.g.,
resource).campaign
- Example Intent: "What fields and metrics can I query for an ad group?"
- 用途: 检索特定Google Ads API资源类型(如、
campaign、ad_group)的详细结构元数据。customer - 使用方式: 在构建GAQL查询之前,调用此工具检查资源的架构、可用字段、指标和细分维度。
- 参数:
- (字符串,必填):要检查的资源名称(例如
resource)。campaign
- 示例意图: “我可以查询广告组的哪些字段和指标?”
3. search
search3. search
search- Purpose: Executes a Google Ads Query Language (GAQL) query to fetch resource metrics, attributes, segments, and status.
- How to Use: Construct a valid GAQL query string based on the resource metadata and execute the search against a specific customer account.
- Arguments:
- (string, required): The 10-digit target Google Ads customer ID (digits only, no hyphens).
customer_id - (string, required): A valid GAQL query string (e.g.,
query).SELECT campaign.id, campaign.name, campaign.status, metrics.impressions FROM campaign WHERE campaign.status = 'ENABLED'
- Example Intent: "Get the impressions and status of all enabled campaigns for account 1234567890."
[!NOTE] Read-Only Scope: The Google Ads MCP Server is currently strictly read-only. It cannot modify bids, pause campaigns, or create new advertising assets.
- 用途: 执行Google Ads查询语言(GAQL)查询,以获取资源指标、属性、细分维度和状态。
- 使用方式: 根据资源元数据构建有效的GAQL查询字符串,并针对特定客户账户执行搜索。
- 参数:
- (字符串,必填):10位目标Google Ads客户ID(仅含数字,无连字符)。
customer_id - (字符串,必填):有效的GAQL查询字符串(例如
query)。SELECT campaign.id, campaign.name, campaign.status, metrics.impressions FROM campaign WHERE campaign.status = 'ENABLED'
- 示例意图: “获取账户1234567890中所有启用广告系列的展示次数和状态。”
[!NOTE] 只读范围: Google Ads MCP Server目前严格为只读模式。它无法修改出价、暂停广告系列或创建新的广告资产。