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 "Install 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-mcpCreate 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: google-ads-transparency-mcp
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
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/mkroo/adsense-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server