adsense-mcp
Provides tools for managing Google AdSense accounts, including creating and managing ad units, generating ad code for various frameworks, querying earnings reports, checking policy alerts, managing payments, and automating ads.txt verification.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@adsense-mcp Create a display ad unit called 'Homepage Banner'"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
adsense-mcp
MCP (Model Context Protocol) server for Google AdSense management. Create ad units, generate framework-specific ad code, manage earnings reports, and automate ads.txt — all from your AI assistant.
Built for solo developers who build websites with AI agents and want to monetize them without leaving the terminal.
Features
Ad Unit CRUD — Create and manage ad units via AdSense Management API v2
Ad Code Retrieval — Get ready-to-paste HTML/JS embed code for any ad unit
Framework Snippets — Generate ad integration code for React, Next.js, Vue, Nuxt, Astro, Svelte
ads.txt Automation — Generate and remotely verify ads.txt for your domains
Earnings Reports — Query revenue, page views, clicks with flexible date ranges and dimensions
Alerts & Payments — Monitor policy issues and payment history
Auto-detection — Automatically resolves your account and ad client, so most parameters are optional
Lightweight — Uses direct REST calls instead of the heavy
googleapispackage
Related MCP server: flour-ads
Prerequisites
Active Google AdSense account (already approved)
Node.js 18+
Google Cloud OAuth credentials (see Setup below)
Setup
1. Create Google Cloud OAuth Credentials
Go to Google Cloud Console
Create a new project (or select an existing one)
Enable the AdSense Management API:
Navigate to APIs & Services > Library
Search for "AdSense Management API"
Click Enable
Create OAuth credentials:
Go to APIs & Services > Credentials
Click Create Credentials > OAuth client ID
Choose Desktop app as the application type
Download the JSON file
Configure the OAuth consent screen:
Go to APIs & Services > OAuth consent screen
Keep the publishing status as Testing
Add your Google account as a Test user
Note: While in "Testing" mode, only test users you add can authenticate. This is fine for personal use — no Google review required.
2. Install
npm install -g adsense-mcp3. Authenticate
adsense-mcp auth /path/to/downloaded-credentials.jsonThis will:
Save your OAuth credentials to
~/.adsense-mcp/credentials.jsonOpen your browser for Google OAuth consent
Save access/refresh tokens to
~/.adsense-mcp/tokens.json
You only need to do this once. Tokens auto-refresh on subsequent use.
4. Configure Your AI Tool
Claude Code
Add to your project's .mcp.json:
{
"mcpServers": {
"adsense": {
"command": "npx",
"args": ["-y", "adsense-mcp"]
}
}
}Or add globally in ~/.claude/settings.json:
{
"mcpServers": {
"adsense": {
"command": "npx",
"args": ["-y", "adsense-mcp"]
}
}
}Cursor
Add to .cursor/mcp.json in your project root:
{
"mcpServers": {
"adsense": {
"command": "npx",
"args": ["-y", "adsense-mcp"]
}
}
}Windsurf
Add to ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"adsense": {
"command": "npx",
"args": ["-y", "adsense-mcp"]
}
}
}Tools Reference
Account & Configuration
list_accounts
List all AdSense accounts linked to your Google account.
Parameters: (none)Example prompt: "Show me my AdSense accounts"
list_ad_clients
List ad clients (publisher IDs like ca-pub-XXXX) for an account.
Parameters:
account (optional) Account name. Auto-detected if omitted.Example prompt: "What's my AdSense publisher ID?"
list_sites
List all sites with their approval status and auto-ads setting.
Parameters:
account (optional) Account name. Auto-detected if omitted.Example prompt: "Which sites are approved in my AdSense?"
Ad Unit Management
create_ad_unit
Create a new ad unit. Returns the unit name, slot ID, and state.
Parameters:
displayName (required) Human-readable name (e.g., "Homepage Banner")
type (optional) DISPLAY | IN_FEED | IN_ARTICLE | MATCHED_CONTENT (default: DISPLAY)
adClient (optional) Ad client name. Auto-detected if omitted.Example prompt: "Create a display ad unit called 'Sidebar Ad' for my blog"
list_ad_units
List all ad units with their name, display name, state, type, and size.
Parameters:
adClient (optional) Ad client name. Auto-detected if omitted.Example prompt: "List all my ad units"
get_ad_code
Get the raw HTML/JS ad code for a specific ad unit, as provided by Google.
Parameters:
adUnit (required) Full ad unit name (e.g., accounts/pub-XXX/adclients/ca-pub-XXX/adunits/123)Example prompt: "Get the embed code for my sidebar ad unit"
get_ad_snippet
Generate framework-specific ad component code, ready to drop into your project.
Parameters:
framework (required) html | react | nextjs | vue | nuxt | astro | svelte
publisherId (required) Publisher ID (e.g., ca-pub-1234567890123456)
slotId (required) Ad unit slot ID (e.g., 1234567890)
style (optional) responsive | in-article | in-feed | fixed (default: responsive)
width (optional) Width in px (only for "fixed" style)
height (optional) Height in px (only for "fixed" style)Example prompt: "Generate a Next.js component for my ad unit slot 9876543210"
Supported frameworks and what gets generated:
Framework | Output |
| Standard |
|
|
| Layout with |
| SFC with |
|
|
|
|
| Component with |
ads.txt
generate_ads_txt
Generate the correct ads.txt content for your AdSense account.
Parameters:
account (optional) Account name. Auto-detected if omitted.Example prompt: "Generate ads.txt for my site"
Returns the entry line and instructions for where to place the file in various project types.
verify_ads_txt
Fetch a domain's /ads.txt and check if it contains your publisher entry.
Parameters:
domain (required) Domain to check (e.g., example.com)
account (optional) Account name. Auto-detected if omitted.Example prompt: "Check if ads.txt is set up correctly on myblog.com"
Analytics
generate_report
Generate an earnings report with customizable date range, metrics, and dimensions.
Parameters:
dateRange (optional) TODAY | YESTERDAY | LAST_7_DAYS | LAST_30_DAYS |
MONTH_TO_DATE | YEAR_TO_DATE | LAST_3_MONTHS | LAST_12_MONTHS
(default: LAST_7_DAYS)
metrics (optional) Array of metrics (default: [ESTIMATED_EARNINGS, PAGE_VIEWS, CLICKS, PAGE_VIEWS_CTR])
dimensions (optional) Array of dimensions (default: [DATE])
account (optional) Account name. Auto-detected if omitted.Available metrics: ESTIMATED_EARNINGS, PAGE_VIEWS, IMPRESSIONS, CLICKS, PAGE_VIEWS_CTR, COST_PER_CLICK, PAGE_VIEWS_RPM, AD_REQUESTS, AD_REQUESTS_CTR
Available dimensions: DATE, WEEK, MONTH, SITE_DOMAIN, AD_UNIT_NAME, COUNTRY_NAME, PLATFORM_TYPE
Example prompt: "Show my earnings for the last 30 days broken down by site"
list_alerts
List policy alerts and issues that need attention.
Parameters:
account (optional) Account name. Auto-detected if omitted.Example prompt: "Are there any AdSense policy issues I should know about?"
list_payments
List payment history.
Parameters:
account (optional) Account name. Auto-detected if omitted.Example prompt: "Show my AdSense payment history"
Usage Examples
Full workflow: Add ads to a new Next.js site
You: "I just deployed myblog.com with Next.js. Set up AdSense ads for it."
AI: 1. Calls list_accounts → gets your account
2. Calls list_sites → confirms myblog.com is approved
3. Calls create_ad_unit → creates "myblog-header" (DISPLAY)
4. Calls create_ad_unit → creates "myblog-article" (IN_ARTICLE)
5. Calls get_ad_snippet (nextjs) → generates Next.js components
6. Calls generate_ads_txt → generates ads.txt content
7. Inserts ad components into your layout and article pages
8. Creates public/ads.txt
9. Calls verify_ads_txt → confirms setup after deployQuick report
You: "How are my ads performing this month?"
AI: Calls generate_report with dateRange=MONTH_TO_DATE,
dimensions=[DATE, SITE_DOMAIN]
→ Shows earnings trend by siteAd placement for existing units
You: "Add my existing ad units to this Astro blog"
AI: 1. Calls list_ad_units → gets your units and slot IDs
2. Calls get_ad_snippet (astro) for each unit
3. Inserts components into your Astro layoutsTroubleshooting
"Not authenticated" error
Re-run the auth flow:
adsense-mcp authIf tokens exist but are invalid, delete them and re-authenticate:
rm ~/.adsense-mcp/tokens.json
adsense-mcp auth"AdSense Management API has not been used" error
Enable the API in Google Cloud Console:
Go to APIs & Services > Library
Search "AdSense Management API"
Click Enable
"Access Not Configured" or 403 errors
Make sure:
Your Google account is added as a test user in the OAuth consent screen
The AdSense Management API is enabled in your GCP project
Your AdSense account is active and approved
Token refresh failures
Delete the saved tokens and re-authenticate:
rm ~/.adsense-mcp/tokens.json
adsense-mcp authSecurity
OAuth tokens are stored in
~/.adsense-mcp/tokens.json(file permission: user-only recommended)Credentials are stored in
~/.adsense-mcp/credentials.jsonThe server uses
https://www.googleapis.com/auth/adsensescope (full read/write)No data is sent to any third party — all API calls go directly to Google
Auth callback runs on
127.0.0.1with a randomly assigned port
To restrict to read-only access, modify the SCOPES array in src/auth.ts to:
const SCOPES = ['https://www.googleapis.com/auth/adsense.readonly'];License
MIT
Available Tools
12 toolscreate_ad_unitA
Create a new ad unit. Returns the created unit with its name and slot ID.
Inputs: displayName (required), type, adClient.
generate_ads_txtA
Generate ads.txt content for your site. Place this file at your domain root (e.g., example.com/ads.txt).
Inputs: account.
generate_reportA
Generate an AdSense earnings report with customizable date range, metrics, and dimensions
Inputs: account, metrics, dateRange, dimensions.
get_ad_codeB
Get the HTML/JS ad code snippet for an ad unit, ready to paste into your website
Inputs: adUnit (required).
get_ad_snippetB
Generate framework-specific ad integration code (React, Next.js, Vue, Astro, Svelte, etc.)
Inputs: slotId (required), framework (required), publisherId (required), style, +2 more.
list_accountsA
List all AdSense accounts associated with your Google account
Inputs: no named parameters.
list_ad_clientsA
List ad clients (publisher IDs) for an account
Inputs: account.
list_ad_unitsA
List all ad units. Returns name, displayName, state, type, and size for each unit.
Inputs: adClient.
list_alertsA
List AdSense alerts and policy issues that need attention
Inputs: account.
list_paymentsA
List payment history for your AdSense account
Inputs: account.
list_sitesA
List all sites in your AdSense account with their approval status and auto-ads setting
Inputs: account.
verify_ads_txtB
Check if ads.txt is correctly set up on a domain by fetching and verifying its contents
Inputs: domain (required), account.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 12 tools
Most tools target clearly distinct resources and actions, such as listing accounts, creating ad units, and verifying ads.txt. The only potential confusion is between get_ad_code and get_ad_snippet, but their descriptions distinguish raw HTML/JS from framework-specific integration code.
Tool names consistently follow a verb_noun pattern in snake_case: list_*, create_ad_unit, get_ad_code, generate_report, verify_ads_txt. The naming is predictable and easy for an agent to navigate.
Twelve tools is well within the typical 3-15 range for a focused server. Each tool covers a meaningful AdSense workflow without obvious padding or duplication.
The server covers listing, creation, reporting, payments, alerts, and ads.txt verification, but has notable gaps: there is no update or delete operation for ad units, and site management is limited to listing. Agents can complete core workflows but cannot modify existing resources.
Maintenance
Related MCP Connectors
Google Ads MCP server: run Search, Display, Demand Gen and PMax campaigns from AI.
Website monetization for AI agents: apply, integrate ads, reporting, and payouts — all over MCP.
MCP-native ad server. Monetize AI chatbots and agents with conversational ads.
Hosted MCP server for marketing agencies: connect Google Ads, GA4, Search Console, Meta, LinkedIn and more to Claude or ChatGPT. Pull reports and make changes via OAuth login, no setup.
Related MCP Servers
- AlicenseAqualityBmaintenanceAn MCP server that lets AI assistants look up any advertiser's Google ads. Search by domain or company name, retrieve ad creatives, and decode text ad content from Google's Ads Transparency Center.8578 PyPI14MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for managing ad campaigns across Google Ads, Meta, and more. Enables deploying campaigns, checking performance, and managing budgets from terminal or AI assistants.MIT
- AlicenseAqualityBmaintenanceConnects Google AdSense to MCP clients like Claude and Cursor, enabling earnings summaries, detailed reports, site status checks, and more via natural language.11575 npm5MIT
- AlicenseAqualityDmaintenanceA Model Context Protocol (MCP) server that gives Claude Desktop direct access to your Google AdSense account. Ask plain English questions about your revenue — no dashboard required.1019 npmMIT