Back to MCP directory
publicPublicdnsLocal runtime

mcp-google-ads

Google Ads MCP是一个连接Google Ads与Claude AI的工具,通过自然语言对话分析广告数据,提供账户管理、活动分析、关键词优化和预算管理功能。

article

README

🚀 如何为Claude和Cursor构建Google Ads MCP(管理客户平台)

本项目是一个用于与Google Ads API交互的管理客户平台(MCP)的实现,允许您通过Claude Desktop和Cursor进行配置和控制,具备广告系列管理、广告组管理等多种核心功能。

🚀 快速开始

  1. 克隆仓库
    git clone https://github.com/your-username/google-ads-mcp.git
    cd google-ads-mcp
    
  2. 安装依赖
    pip install -r requirements.txt
    
  3. 配置环境变量: 创建并编辑.env文件:
    GOOGLE_ADS_CREDENTIALS_PATH=/path/to/your/google-ads.json
    CLAUDE_API_KEY=your_api_key_here
    
  4. 启动服务
    python -m google_ads_mcp.mcp --config config.json
    

✨ 主要特性

  • 广告系列管理:创建、读取、更新和删除广告系列。
  • 广告组管理:操作广告组,包括添加、更新和删除。
  • 关键词管理:管理和优化广告词。
  • 报告生成:自动生成Google Ads性能报告。
  • 批量操作:支持大规模数据的批量处理。

📦 安装指南

克隆项目

git clone https://github.com/your-username/google-ads-mcp.git
cd google-ads-mcp

安装依赖

pip install -r requirements.txt

配置环境

创建并编辑.env文件:

GOOGLE_ADS_CREDENTIALS_PATH=/path/to/your/google-ads.json
CLAUDE_API_KEY=your_api_key_here

💻 使用示例

使用Claude Desktop

基础用法

google_ads_mcp/mcp.py中添加Claude API调用:

from claude_api import ClaudeAPI

class GoogleAdsMCP:
    def __init__(self):
        self.claude = ClaudeAPI(your_api_key)

    # 其他方法...

高级用法

在Caulde Desktop中注册您的服务: 创建新的Python文件claude_plugin.py

from google_ads_mcp.mcp import GoogleAdsMCP

class GoogleAdsPlugin:
    def __init__(self, api_key):
        self.mcp = GoogleAdsMCP()

    def get_advertising_campaigns(self):
        return self.mcp.list_campaigns()

使用Cursor

基础用法

在Cursor中使用MCP,创建google_ads_mcp/cursor_extension.py

from .mcp import GoogleAdsMCP

class GoogleAdsExtension:
    def __init__(self):
        self.mcp = GoogleAdsMCP()

    def get_campaigns(self):
        return self.mcp.list_campaigns()

高级用法

在项目根目录创建setup.py

from setuptools import setup, find_packages

setup(
    name="google-ads-mcp",
    version="1.0.0",
    packages=find_packages(),
    install_requires=[
        "google-ads",
        "claude_api"
    ]
)

📚 详细文档

项目结构

google-ads-mcp/
├── google_ads_mcp/
│   ├── __init__.py
│   ├── mcp.py                 # 核心MCP实现
│   ├── services/             # 所有服务的定义
│   │   └── ads_service.py    # Google Ads API服务
│   └── tests/               # 测试文件
│       ├── test_google_ads_mcp.py  # 主要测试文件
│       └── test_token_refresh.py   # 认证和令牌刷新测试
├── .env                       # 环境变量文件
├── config.json                # MCP配置文件
├── requirements.txt           # 项目依赖项
└── README.md                  # 项目说明文档

测试

环境变量配置

编辑tests/test_google_ads_mcp.py

import os
from unittest.mock import patch
from google_ads_mcp.mcp import GoogleAdsMCP

def test_init():
    with patch.dict('os.environ', {
        'GOOGLE_ADS_CREDENTIALS_PATH': '/path/to/google-ads.json',
        'CLAUDE_API_KEY': 'test_key'
    }):
        mcp = GoogleAdsMCP()
        assert mcp.credentials_path == '/path/to/google-ads.json'
        assert mcp.claude_api_key == 'test_key'

运行测试

运行以下命令:

python -m pytest tests/

常见问题解决

环境变量配置错误

  1. 检查.env文件路径是否正确。
  2. 确保所有环境变量都已设置。

认证失败

  1. 验证Google Ads API凭据文件是否存在且内容正确。
  2. 确保Claude API密钥有效。

附录

示例配置文件config.json

{
    "google_ads": {
        "client_id": "your_client_id",
        "client_secret": "your_client_secret"
    },
    "claude": {
        "api_key": "your_api_key_here"
    }
}

更多资源

📄 许可证

项目使用MIT许可证。请查看LICENSE文件获取详细信息。

📞 联系方式

如需反馈,请联系:

ernesto@ixigo.com
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client