Admob Mcp

Created By
Abhishek Dhobe20 days ago
A powerful Model Context Protocol (MCP) server that exposes Google AdMob management, mediation waterfall operations, advanced revenue analysis, and A/B experiments directly to MCP-compatible AI clients (such as Claude Code CLI, Claude Desktop, Cursor, Windsurf, and Cline). Features a local Rules Engine and Safety Layer ensuring that mutating operations are audited, verified, and run via dry-runs before touching your live AdMob account.
Overview

๐Ÿš€ AdMob Model Context Protocol (MCP) Server

A powerful Model Context Protocol (MCP) server that exposes Google AdMob management, mediation waterfall operations, advanced revenue analysis, and A/B experiments directly to MCP-compatible AI clients (such as Claude Code CLI, Claude Desktop, Cursor, Windsurf, and Cline).

Features a local Rules Engine and Safety Layer ensuring that mutating operations are audited, verified, and run via dry-runs before touching your live AdMob account.


๐Ÿ“‚ Architecture Overview

MCP-admob/
โ”œโ”€โ”€ admob_mcp/              โ† MCP Server Layer (FastMCP)
โ”‚   โ”œโ”€โ”€ server.py           โ† Server entry point, async context & lifespans
โ”‚   โ”œโ”€โ”€ resources.py        โ† Exposed resources (ad-sources, format-support)
โ”‚   โ”œโ”€โ”€ prompts.py          โ† Integrated workflow prompt templates
โ”‚   โ””โ”€โ”€ tools/              โ† MCP Tool modules
โ”‚       โ”œโ”€โ”€ reporting.py    โ† Read-only reports & network data
โ”‚       โ”œโ”€โ”€ management.py   โ† Mediation Group CRUD
โ”‚       โ”œโ”€โ”€ experiments.py  โ† A/B experiment lifecycles
โ”‚       โ””โ”€โ”€ diagnostics.py  โ† Expert metrics analysis & geo recommendations
โ”œโ”€โ”€ admob_core/             โ† Business Logic & Library Layer
โ”‚   โ”œโ”€โ”€ client.py           โ† Async Google AdMob REST API v1beta wrapper
โ”‚   โ”œโ”€โ”€ auth.py             โ† OAuth 2.0 credential loading & browser flow
โ”‚   โ”œโ”€โ”€ db.py               โ† Local SQLite metrics database (admob_metrics.db)
โ”‚   โ”œโ”€โ”€ analyzer.py         โ† AdMonExpert core diagnostics & sync logic
โ”‚   โ”œโ”€โ”€ rules.py            โ† Mediation policy validator (Rules Engine)
โ”‚   โ”œโ”€โ”€ safety.py           โ† Write safeguard & audit logger
โ”‚   โ””โ”€โ”€ registry.py         โ† 13+ Ad Source capabilities knowledge base
โ”œโ”€โ”€ config.yaml             โ† App categories & rule configuration thresholds
โ”œโ”€โ”€ requirements.txt        โ† Python package dependencies
โ”œโ”€โ”€ .env.example            โ† Template for required environment variables
โ”œโ”€โ”€ .env                    โ† Your secrets (not committed โ€” copy from .env.example)
โ”œโ”€โ”€ credentials.json        โ† OAuth 2.0 Client credentials (not committed โ€” you provide)
โ””โ”€โ”€ token.json              โ† Authorized OAuth user token (not committed โ€” auto-generated)

๐Ÿ› ๏ธ Prerequisites & Setup

1. Enable the Google AdMob API

  1. Open the Google Cloud Console.
  2. Select or create your project.
  3. Search for AdMob API in the API Library and click Enable.

2. Download OAuth 2.0 Desktop Credentials

  1. Navigate to APIs & Services โ†’ Credentials.
  2. Click Create Credentials โ†’ OAuth client ID.
  3. Select Desktop app as the Application Type.
  4. Download the generated client JSON and save it in the root of this repo as credentials.json.

3. Create Virtual Environment & Install Dependencies

python3 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt

Python 3.10+ required. fastmcp does not support Python 3.9 or older.

4. Configure Environment (.env)

cp .env.example .env

Then edit .env:

PUBLISHER_ID=pub-XXXXXXXXXXXXXXXX      # Your AdMob Publisher ID (AdMob UI โ†’ Account)
CREDENTIALS_PATH=credentials.json       # Path to your OAuth credentials file
TOKEN_PATH=token.json                   # Where to cache the authorized token
AUDIT_LOG_PATH=audit.log               # Log file for mutating operations
SLACK_WEBHOOK_URL=                      # (Optional) Slack alert webhook

5. Run the One-time Authorization Flow

python admob_core/auth.py

A browser tab will open โ€” authenticate with your Google AdMob account and grant permissions. This writes token.json which is cached and auto-refreshed on all subsequent runs.


๐Ÿ’ป Integrating with AI Clients

Replace /path/to/MCP-admob with the absolute path to wherever you cloned this repo.

๐Ÿค– Claude Code (CLI)

claude mcp add admob-mediation \
  --env PYTHONPATH="/path/to/MCP-admob" \
  --env PUBLISHER_ID="pub-XXXXXXXXXXXXXXXX" \
  --env CREDENTIALS_PATH="/path/to/MCP-admob/credentials.json" \
  --env TOKEN_PATH="/path/to/MCP-admob/token.json" \
  --env AUDIT_LOG_PATH="/path/to/MCP-admob/audit.log" \
  -- "/path/to/MCP-admob/.venv/bin/python" -m admob_mcp

Or via JSON:

claude mcp add-json admob-mediation '{
  "command": "/path/to/MCP-admob/.venv/bin/python",
  "args": ["-m", "admob_mcp"],
  "env": {
    "PYTHONPATH": "/path/to/MCP-admob",
    "PUBLISHER_ID": "pub-XXXXXXXXXXXXXXXX",
    "CREDENTIALS_PATH": "/path/to/MCP-admob/credentials.json",
    "TOKEN_PATH": "/path/to/MCP-admob/token.json",
    "AUDIT_LOG_PATH": "/path/to/MCP-admob/audit.log"
  }
}'

Verify with claude mcp list.


๐Ÿ–ฅ๏ธ Claude Desktop App

Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "admob-mediation": {
      "command": "/path/to/MCP-admob/.venv/bin/python",
      "args": ["-m", "admob_mcp"],
      "cwd": "/path/to/MCP-admob",
      "env": {
        "PYTHONPATH": "/path/to/MCP-admob",
        "PUBLISHER_ID": "pub-XXXXXXXXXXXXXXXX",
        "CREDENTIALS_PATH": "/path/to/MCP-admob/credentials.json",
        "TOKEN_PATH": "/path/to/MCP-admob/token.json",
        "AUDIT_LOG_PATH": "/path/to/MCP-admob/audit.log"
      }
    }
  }
}

Restart Claude Desktop to reload.


๐Ÿ” Cursor IDE

  1. Settings โ†’ Features โ†’ MCP โ†’ + Add New MCP Server
  2. Name: admob-mediation | Type: command
  3. Command: /path/to/MCP-admob/.venv/bin/python -m admob_mcp
  4. Ensure your .env is populated in the project root.

๐ŸŒŠ Windsurf / Cline / Roo Code

"admob-mediation": {
  "command": "/path/to/MCP-admob/.venv/bin/python",
  "args": ["-m", "admob_mcp"],
  "env": {
    "PYTHONPATH": "/path/to/MCP-admob",
    "PUBLISHER_ID": "pub-XXXXXXXXXXXXXXXX",
    "CREDENTIALS_PATH": "/path/to/MCP-admob/credentials.json",
    "TOKEN_PATH": "/path/to/MCP-admob/token.json",
    "AUDIT_LOG_PATH": "/path/to/MCP-admob/audit.log"
  }
}

๐Ÿงฉ MCP Primitives Reference

๐Ÿ› ๏ธ Tools (14 total)

Reporting โ€” Read-Only

ToolDescription
admob_list_appsLists all active apps in the publisher account
admob_list_ad_unitsLists ad units, optionally filtered by app_id
admob_network_reportNetwork revenue report across dates, apps, formats, countries
admob_mediation_reportMediation revenue report broken down by network, bidding vs waterfall

Mediation Management โ€” Write Operations

ToolDescription
admob_list_mediation_groupsLists all mediation groups with targeting and line items
admob_list_ad_sourcesLists available ad network sources supported by AdMob
admob_create_mediation_groupCreates a mediation group (runs Rules Engine validation first)
admob_update_mediation_groupUpdates targeting, status, or line items of a mediation group

Experiments โ€” A/B Testing

ToolDescription
admob_create_ab_experimentCreates a mediation A/B experiment
admob_stop_ab_experimentStops an A/B experiment and selects the winner variant

Diagnostics & Optimization

ToolDescription
admob_expert_syncSyncs 14 days of mediation metrics into the local SQLite DB
admob_expert_analyzeRoot-cause analysis: fill rate anomalies, match rate drops, revenue alerts
admob_recommend_networks_geoTier-1/Tier-2 network recommendations for a country + ad format
admob_request_placement_mapReturns a placement mapping template for UX/monetization planning

๐Ÿ“ฆ Resources (3)

URIDescription
admob://ad-sourcesFull ad network registry with bidding/waterfall support and source IDs
admob://app-categoriesApp category definitions and child-directed settings from config.yaml
admob://format-supportFormat support matrix per ad source (banner, interstitial, rewarded, etc.)

๐Ÿ’ก Prompts (2)

PromptDescription
optimize_app(app_id)Step-by-step audit: sync data โ†’ analyze โ†’ inspect groups โ†’ recommend changes
portfolio_healthPortfolio-wide audit: flags stale A/B tests, revenue drops, missing partners

๐Ÿ”’ Safety, Auditing & Rules Engine

All write operations go through a two-stage safety pipeline before touching the live API:

Stage 1 โ€” Rules Engine (rules.py)

RuleSeverityDescription
format_check๐Ÿ”ด BLOCKPrevents adding a network that doesn't support the group's ad format
child_directed๐Ÿ”ด BLOCKBlocks bidding networks on COPPA-tagged apps
min_bidding๐ŸŸก WARNAlerts when fewer than 3 bidding partners are configured
admob_network_required๐ŸŸก WARNWarns if AdMob Network is absent from the waterfall
pangle_region๐ŸŸก WARNWarns if Pangle is added outside its strong geos (APAC, US, BR, MX)

Stage 2 โ€” Snapshot + Audit Log (safety.py)

  • dry_run=True on any write tool previews the change without hitting the API
  • Every real mutation captures a pre-change snapshot and appends a structured JSON entry to audit.log

โš™๏ธ Configuration (config.yaml)

Customize app categories and rule thresholds:

app_categories:
  gaming:
    app_ids: ["ca-app-pub-XXXX~YYYY"]   # AdMob app IDs to tag
    child_directed: false
    primary_formats: ["REWARDED_VIDEO", "INTERSTITIAL", "BANNER"]

rules:
  min_bidding_partners: 3
  stale_ecpm_threshold_days: 30
  stale_experiment_days: 14

โŒ Troubleshooting

ErrorFix
ValueError: PUBLISHER_ID must be providedCheck .env contains PUBLISHER_ID=pub-... and that the server's cwd points to the repo root
FileNotFoundError: credentials.json not foundPlace credentials.json in the repo root or set CREDENTIALS_PATH to its absolute path
403 Forbidden / AdMob API not enabledEnable the AdMob API in Google Cloud Console for your project
401 Unauthorized / Token ExpiredDelete token.json and re-run python admob_core/auth.py
fastmcp not found / install errorsEnsure you're using Python 3.10+ (python --version)

๐Ÿ“‹ Requirements

  • Python 3.10+
  • Google Cloud project with AdMob API enabled
  • OAuth 2.0 Desktop App credentials (credentials.json)
  • An active AdMob publisher account

๐Ÿ“„ License

MIT โ€” see LICENSE.

Server Config

{
  "mcpServers": {
    "admob-mediation": {
      "command": "/path/to/MCP-admob/.venv/bin/python",
      "args": [
        "-m",
        "admob_mcp"
      ],
      "cwd": "/path/to/MCP-admob",
      "env": {
        "PYTHONPATH": "/path/to/MCP-admob",
        "PUBLISHER_ID": "pub-XXXXXXXXXXXXXXXX",
        "CREDENTIALS_PATH": "/path/to/MCP-admob/credentials.json",
        "TOKEN_PATH": "/path/to/MCP-admob/token.json",
        "AUDIT_LOG_PATH": "/path/to/MCP-admob/audit.log"
      }
    }
  }
}
Project Info
Created At
20 days ago
Updated At
20 days ago
Author Name
Abhishek Dhobe
Star
-
Language
-
License
-
Category
Tags

Recommend Servers

View All
Teardrop

10 days ago