AdSense-MCP-Server

AdSense-MCP-Server

Connects Google AdSense to MCP clients like Claude and Cursor, enabling earnings summaries, detailed reports, site status checks, and more via natural language.

Category
访问服务器

README

AdSense-MCP-Server

Google AdSense MCP Server — Connect Google AdSense to Claude, Cursor, and other MCP clients.

npm version npm downloads License: MIT CI

Features

  • 📊 Earnings Summary — Quick overview of today, yesterday, last 7 days, and monthly earnings
  • 📈 Detailed Reports — Generate reports with dimensions (date, site, country, ad unit) and metrics
  • 🔄 Period Comparison — Compare performance between time periods
  • 🌐 Site Status — Check approval status for all your sites
  • ⚠️ Alerts & Policy Issues — Monitor account health and catch violations early
  • 💰 Payment History — View payment history and pending earnings
  • 📦 Ad Units — List ad units and get embed codes
  • 📤 CSV Export — Export reports for further analysis
  • 💾 Caching — SQLite cache for faster repeated queries
  • 🔐 Secure — OAuth tokens stored in OS keychain, read-only scope

Quick Start

# Install globally
npm install -g @appsyogi/adsense-mcp-server

# Set up OAuth credentials
adsense-mcp init

# Verify setup
adsense-mcp doctor

# Start the server (for MCP clients)
adsense-mcp run

Prerequisites

1. Create Google Cloud OAuth Credentials

You need to create your own OAuth credentials in Google Cloud Console:

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the AdSense Management API:
    • Go to "APIs & Services" → "Library"
    • Search for "AdSense Management API"
    • Click "Enable"
  4. Create OAuth credentials:
    • Go to "APIs & Services" → "Credentials"
    • Click "Create Credentials" → "OAuth client ID"
    • Choose "Desktop application"
    • Name it (e.g., "AdSense-MCP")
    • Click "Create"
  5. Copy the Client ID and Client Secret
  6. Add test users (required while app is in testing mode):
    • Go to "APIs & Services" → "OAuth consent screen"
    • Scroll to "Test users" section
    • Click "Add users"
    • Add the Google account email(s) you'll use to authenticate
    • Click "Save"

Note: While your app's publishing status is "Testing", only test users can authenticate. You can add up to 100 test users.

2. Configure AdSense-MCP

Run the init command and enter your credentials:

adsense-mcp init

This will:

  • Prompt for your Client ID and Client Secret
  • Open a browser for Google authentication
  • Store your refresh token securely in the OS keychain

Installation

npx @appsyogi/adsense-mcp-server init

Quick Start

1. Initialize (OAuth Setup)

npx adsense-mcp init

This will:

  • Open your browser for Google sign-in
  • Request read-only access to your AdSense data
  • Let you select your default account (if you have multiple)
  • Store credentials securely

2. Verify Setup

npx adsense-mcp doctor

3. Add to Your MCP Client

VS Code Copilot (~/.vscode/mcp.json)

{
    "servers": {
        "adsense": {
            "command": "npx",
            "args": ["@appsyogi/adsense-mcp-server", "run"],
            "type": "stdio"
        }
    }
}

Claude Desktop (~/Library/Application Support/Claude/claude_desktop_config.json)

{
    "mcpServers": {
        "adsense": {
            "command": "npx",
            "args": ["@appsyogi/adsense-mcp-server", "run"]
        }
    }
}

Available Tools

Tool Description
adsense_list_accounts List all AdSense accounts you have access to
adsense_earnings_summary Quick earnings overview (today, yesterday, last 7 days, this month)
adsense_generate_report Generate detailed reports with custom dimensions and metrics
adsense_compare_periods Compare performance between two time periods
adsense_list_sites List all sites with their approval status
adsense_list_alerts Get account alerts and warnings
adsense_list_policy_issues Check for policy violations
adsense_list_payments View payment history and pending earnings
adsense_list_ad_units List all ad units
adsense_get_ad_code Get HTML embed code for an ad unit
adsense_export_csv Export report data as CSV

Example Conversations

Check Earnings

You: How's my AdSense doing today?

Claude: 📊 **AdSense Earnings Summary**

| Period | Earnings | Impressions | Clicks | CTR |
|--------|----------|-------------|--------|-----|
| Today | $8.45 | 3,200 | 28 | 0.88% |
| Yesterday | $15.67 | 6,200 | 52 | 0.84% |
| Last 7 Days | $98.45 | 42,000 | 380 | 0.90% |
| This Month | $345.67 | 150,000 | 1,350 | 0.90% |

You're tracking 16% ahead of last month at this point! 🎉

Check Site Status

You: Is my new site approved yet?

Claude: 📋 **Site Status**

| Site | Status | Notes |
|------|--------|-------|
| example.com | ✅ READY | Ads serving |
| blog.example.com | ⏳ GETTING_READY | Under review |
| newsite.com | ⚠️ NEEDS_ATTENTION | Insufficient content |

Generate Report

You: Show me earnings by country for last week

Claude: [Generates report with COUNTRY_NAME dimension]

CLI Commands

adsense-mcp init

Set up OAuth authentication and select default account.

# Interactive setup
npx adsense-mcp init

# Set specific default account
npx adsense-mcp init --account pub-1234567890123456

# Use service account (advanced)
npx adsense-mcp init --service-account /path/to/key.json

adsense-mcp doctor

Verify your setup and check account health.

npx adsense-mcp doctor

adsense-mcp run

Start the MCP server (typically called by your MCP client).

# Use default account
npx adsense-mcp run

# Use specific account
npx adsense-mcp run --account pub-9876543210987654

# Verbose logging
npx adsense-mcp run --verbose

Multi-Account Support

If you have multiple AdSense accounts, you can:

  1. Select default during init
  2. Override with --account flag
  3. Use adsense_list_accounts tool to see all accounts
  4. Pass accountId parameter to any tool

Data Storage

All data is stored locally in ~/.config/adsense-mcp/:

  • config.json - Default account and settings
  • tokens.json - OAuth refresh token (encrypted)
  • cache.sqlite - Report cache for faster responses

Security

  • Read-only access - This server only requests adsense.readonly scope
  • Secure token storage - Tokens are encrypted using OS keychain (via keytar)
  • Local only - All data stays on your machine
  • No telemetry - We don't collect any usage data

Rate Limits

The AdSense API has strict rate limits (100 requests/minute). This server:

  • Caches responses intelligently (5min-24hr based on data type)
  • Implements exponential backoff for retries
  • Tracks request rates to avoid hitting limits

Troubleshooting

"No tokens found" error

Run npx adsense-mcp init to set up authentication.

"Rate limit exceeded" error

Wait a minute and try again. The server will automatically retry with backoff.

"Account not found" error

Make sure you've selected a valid account during setup. Run npx adsense-mcp doctor to see available accounts.

Development

# Clone the repo
git clone https://github.com/AppsYogi-com/adsense-mcp-server.git
cd adsense-mcp-server

# Install dependencies
npm install

# Build
npm run build

# Run in dev mode
npm run dev

# Test locally
node dist/cli/index.js doctor

License

MIT

Contributing

Contributions are welcome! Please open an issue or PR.

Credits

Built with:

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选