admob-mcp
# admob-mcp
A **read-only** [Model Context Protocol](https://modelcontextprotocol.io) server for **Google AdMob**. It lets Claude Code, Claude Desktop, Cursor, VS Code or any MCP client pull your AdMob data and analyze it with you:
- revenue, eCPM, fill and CTR, broken down by app, ad unit, country, format, platform or version;
- mediation performance per ad network;
- period-over-period drivers;
- anomaly detection.
> "Why did revenue drop yesterday?" → `compare_periods` and `detect_anomalies` show that *Puzzle Quest* lost 48% of earnings, almost all of it volume (impressions −47%), not price (eCPM flat).
## Why this server
- **Read-only by design.** It requests only the `admob.readonly` and `admob.report` scopes, and every tool is annotated `readOnlyHint`.
- **Your credentials, your machine.** It uses your own OAuth client. The token is stored locally with `0600` permissions. There is no telemetry, and the only network calls go to Google.
- **Small and auditable.** Runtime dependencies are the official MCP SDK, `zod` and Google's `google-auth-library`. AdMob REST calls are a ~150-line `fetch` client.
- **Built for agents:**
- human units (no micros);
- date presets in the account time zone;
- request validation with precise errors before calling the API;
- correct totals for ratio metrics;
- compact tables plus typed `structuredContent`;
- CSV export for big reports.
- **Analytics, not just endpoints:** one-call earnings summary, period comparison ranked by contribution, and transparent anomaly detection.
## Quick start
### Set up with an AI agent
Copy this prompt and paste it into any AI coding agent (Claude Code, Cursor, Antigravity, VS Code Copilot, Codex, etc.) to have it guide you through installation, Google Cloud OAuth setup, verification, and client configuration:
```text
Help me set up and connect the `admob-mcp` read-only Google AdMob MCP server on my machine.
Repo: https://github.com/oleksandrtry/admob-mcp
Docs: docs/setup-google-cloud.md and docs/troubleshooting.md
Follow these steps and check my environment before asking me to do anything manual:
1. Check Node.js (`node -v`, requires >= 20). Install `admob-mcp` from GitHub if not already installed:
- If we are inside a local clone of `admob-mcp`, run `npm install && npm run build` (optionally `npm link`) and use `node <ABS_PATH>/dist/index.js`.
- Otherwise, install globally from GitHub (`npm install -g github:oleksandrtry/admob-mcp`) so `admob-mcp` is available on PATH, or clone the repo into a folder and build it.
2. Run `<cmd> doctor` first to see if valid AdMob credentials already exist.
3. If not authenticated yet, never ask me to paste secrets or JSON files into chat. Instead:
- On macOS/Linux/WSL with a local clone, offer to run `./scripts/setup-google-cloud.sh`, OR walk me step-by-step through `docs/setup-google-cloud.md`:
a) Create/select a Google Cloud project and enable `admob.googleapis.com`.
b) Configure OAuth consent screen (External), add read-only scopes `https://www.googleapis.com/auth/admob.readonly` and `https://www.googleapis.com/auth/admob.report`, and click **Publish app** ("In production") so the refresh token does not expire after 7 days.
c) Create a **Desktop app** OAuth client and download the JSON (for example to `~/.config/admob-mcp/client_secret.json`).
- Then run `<cmd> auth --client-secret <path-to-client_secret.json>` and tell me when to complete sign-in in the browser (note: for an unverified personal app, click Advanced -> Go to app (unsafe) and tick both AdMob scopes).
4. Run `<cmd> doctor` to confirm credentials, access token, and AdMob account ID(s).
5. Configure the MCP server in the MCP client I am currently using (or ask which client I want if unclear), using `admob-mcp` (if installed globally) or `node <ABS_PATH>/dist/index.js` (if built from a clone), and setting `ADMOB_ACCOUNT_ID` if `doctor` lists multiple accounts.
6. Tell me when to reload/restart the client and offer to test the connection with `list_accounts` or `get_earnings_summary`.
```
### Manual setup
**1. Install from GitHub.** Needs Node.js ≥ 20.
Either install globally from GitHub:
```bash
npm install -g github:oleksandrtry/admob-mcp
```
Or clone the repo and build locally (this also gives you the interactive setup wizard):
```bash
git clone https://github.com/oleksandrtry/admob-mcp.git
cd admob-mcp
npm install && npm run build
# Optional: make `admob-mcp` available globally
npm link
```
**2. Create a Google OAuth client and sign in (once, ~10 min).**
- **Guided script (macOS / Linux / WSL):** run `./scripts/setup-google-cloud.sh` from a cloned repo — it walks you through Google Cloud, runs `auth` and `doctor`, and can register the server in Claude Code.
- **Or manually:** follow **[docs/setup-google-cloud.md](docs/setup-google-cloud.md)** (create a project, enable the AdMob API, publish the consent screen, download a *Desktop app* OAuth JSON), then run:
```bash
admob-mcp auth --client-secret ./client_secret.json
admob-mcp doctor
```
*(Without global install/`npm link`, use `node dist/index.js` instead of `admob-mcp`.)*
**3. Connect your client.**
> The examples below assume `admob-mcp` is installed globally (`npm install -g github:oleksandrtry/admob-mcp` or `npm link`). If you built from a clone without linking, use `"command": "node", "args": ["/absolute/path/to/admob-mcp/dist/index.js"]` (or `node /absolute/path/to/admob-mcp/dist/index.js` in `claude mcp add`). With `nvm`, prefer the absolute path to `admob-mcp` or `node`.
<details open>
<summary><b>Claude Code</b></summary>
```bash
claude mcp add admob --scope user -- admob-mcp
```
With several AdMob accounts, set a default:
```bash
claude mcp add admob --scope user --env ADMOB_ACCOUNT_ID=pub-1234567890123456 -- admob-mcp
```
</details>
<details>
<summary><b>Claude Desktop</b></summary>
Add this to `claude_desktop_config.json` (Settings → Developer → Edit Config):
```json
{
"mcpServers": {
"admob": {
"command": "admob-mcp"
}
}
}
```
</details>
<details>
<summary><b>Cursor</b></summary>
Add this to `~/.cursor/mcp.json`:
```json
{
"mcpServers": {
"admob": { "command": "admob-mcp" }
}
}
```
</details>
<details>
<summary><b>VS Code (GitHub Copilot)</b></summary>
Add this to `.vscode/mcp.json`, or run *MCP: Add Server*:
```json
{
"servers": {
"admob": { "type": "stdio", "command": "admob-mcp" }
}
}
```
</details>
<details>
<summary><b>Other clients</b></summary>
Any stdio MCP client works. Run `admob-mcp` (or `node /absolute/path/to/admob-mcp/dist/index.js`), with optional environment variables from the [configuration](#configuration) table.
</details>
Then ask things like:
- *"How did my apps do last week?"*
- *"Compare this month with the same period last year by country."*
- *"Did anything break in the last 3 days?"*
- *"Which mediation network has the best eCPM for interstitials?"*
- *"Export daily earnings per ad unit for September to september.csv."*
## Tools
| Tool | Purpose |
|---|---|
| `list_accounts` | Publisher accounts, currency, time zone |
| `list_apps` | Apps with IDs, platform, store ID, approval state |
| `list_ad_units` | Ad units with IDs, app, format |
| `list_ad_sources` | Mediation ad sources (networks) |
| `run_network_report` | Flexible AdMob Network report: any dimensions, metrics, filters, sort, CSV export |
| `run_mediation_report` | Mediation report by ad source, instance, mediation group… |
| `run_campaign_report` | House-ad / cross-promo campaign report (≤ 30 days) |
| `get_earnings_summary` | KPIs, daily trend and top contributors in one call |
| `compare_periods` | Period vs baseline, groups ranked by contribution to the change, volume vs price |
| `detect_anomalies` | Recent days vs baseline median, flags drops and spikes per app, country… |
**Prompts** (slash commands in Claude Code: `/mcp__admob__…`): `weekly_revenue_review`, `investigate_revenue_drop`, `mediation_performance_audit`, `country_breakdown`.
See **[docs/tools.md](docs/tools.md)** for parameters, units and the exact anomaly method.
## Configuration
| Variable | Purpose |
|---|---|
| `ADMOB_ACCOUNT_ID` | Default publisher ID (`pub-…`) when the Google user has several accounts |
| `ADMOB_CURRENCY` | Default report currency (ISO 4217), e.g. `USD`. Defaults to the account currency |
| `ADMOB_CLIENT_ID`, `ADMOB_CLIENT_SECRET`, `ADMOB_REFRESH_TOKEN` | Use these instead of the saved credentials file (CI, containers) |
| `ADMOB_CONFIG_DIR` | Directory holding `credentials.json` (default `~/.config/admob-mcp`, `%APPDATA%\admob-mcp` on Windows) |
Credentials are looked up in this order:
1. The environment variables above.
2. `credentials.json`.
3. Google Application Default Credentials.
### CLI
```text
admob-mcp Start the MCP server on stdio
admob-mcp auth Sign in with Google (--client-secret <file>, --no-browser)
admob-mcp doctor Check credentials and API access
admob-mcp logout Delete saved credentials
```
## Security and privacy
- **Scopes:** `admob.readonly` and `admob.report` only. The server cannot change apps, ad units or mediation, and it never touches payments.
- **Local token storage:** the refresh token lives in `credentials.json` (mode `0600`, directory `0700`) in Google's `authorized_user` format.
- **No telemetry:** the server makes no network calls other than `oauth2.googleapis.com` and `admob.googleapis.com`.
- **File writes:** the server writes files only when you ask a report tool for `save_csv_path`.
- **Revoking access:** run `admob-mcp logout`, then remove the app at <https://myaccount.google.com/permissions>.
## Troubleshooting
See **[docs/troubleshooting.md](docs/troubleshooting.md)**. Most issues are an expired Testing-mode token (publish the consent screen) or the AdMob API not being enabled in the client's project.
## Development
The project needs Node.js ≥ 20.
```bash
npm install
npm run build # compile to dist/
npm test # unit tests (vitest)
npm run typecheck
npm run lint
```
Run your local build in Claude Code:
```bash
claude mcp add admob-dev --scope user -- node /absolute/path/to/admob-mcp/dist/index.js
```
You can also inspect it with the MCP Inspector:
```bash
npx @modelcontextprotocol/inspector node dist/index.js
```
## License
[MIT](LICENSE)
*Not affiliated with Google. AdMob is a trademark of Google LLC.*
TDQS
Scored across 10 tools
The four list_* tools target clearly separate resources, and the three run_*_report tools map to distinct report types (network, mediation, campaign). The only real overlap is get_earnings_summary versus run_network_report, which both cover AdMob Network performance, though the descriptions differentiate them as a quick overview versus a customizable breakdown.
All ten tools follow a consistent snake_case verb_noun pattern (list_accounts, run_network_report, get_earnings_summary, compare_periods, detect_anomalies). The verbs are meaningful and predictably paired with the resource or operation they act on.
Ten tools is well within the ideal range and each one earns its place: four discovery/list tools, three report runners, and three analysis helpers. Nothing appears redundant or padding.
The reporting surface is thorough, covering network, mediation, and campaign reports plus summary, comparison, and anomaly detection. Minor gaps exist: there is no listing of mediation groups or ad source instances, and no per-app or per-ad-unit detail lookup beyond the bulk list tools.