adsense-mcp
AdSense MCP
一个从 AdSense Management API v2 提取临时数据的 MCP 服务器。它提供了一个不受限制的报告接口:任何受支持的 AdSense 维度、指标、筛选条件、时间段、排序方式、时区、语言、货币和限制都可以传递给 accounts.reports.generate。
该服务器使用只读的 https://www.googleapis.com/auth/adsense.readonly OAuth 范围。它不会向 AdSense 账户写入任何内容。
安装
发布后,使用 npx -y @sirmacke/adsense-mcp 从 MCP 客户端运行它。配置 ADSENSE_ACCESS_TOKEN,或同时配置 ADSENSE_CLIENT_ID、ADSENSE_CLIENT_SECRET 和 ADSENSE_REFRESH_TOKEN 这三个变量。
Related MCP server: google-ads-mcp
安全性
OAuth 访问令牌、刷新令牌和客户端密钥都是凭据。请勿将它们放入此仓库、问题跟踪器、shell 历史记录以及与其他人共享的 MCP 配置中。如果其中任何一个泄露,请立即在 Google Cloud 中撤销它;请参阅 SECURITY.md。
设置
在 Google Cloud 中,启用 AdSense Management API 并创建 OAuth 桌面客户端。
获取授予
https://www.googleapis.com/auth/adsense.readonly范围的刷新令牌。请保密。将
.env.example复制到您的安全环境配置中,并填写ADSENSE_ACCESS_TOKEN或 OAuth 客户端 ID、密钥和刷新令牌。安装并构建:
npm install
npm run build一次性 OAuth 授权(不使用 gcloud)
从 Google Cloud 下载 OAuth 桌面客户端 JSON,然后运行:
$env:ADSENSE_OAUTH_CLIENT_FILE = "C:\secure\adsense-client.json"
$env:ADSENSE_TOKEN_FILE = "C:\secure\adsense-oauth.json"
npm run authorize该命令会在 localhost 回调中打开 Google 同意屏幕,并仅将客户端 ID、客户端密钥和刷新令牌保存在私有令牌文件中。将这些值复制到 MCP 配置的 ADSENSE_CLIENT_ID、ADSENSE_CLIENT_SECRET 和 ADSENSE_REFRESH_TOKEN 字段中。不要将外部同意屏幕保留在“测试”状态:其刷新令牌会在七天后过期。
Claude Desktop
当前的 Claude Desktop 版本使用扩展。运行 npm run package,然后从“设置”→“扩展”→“高级设置”→“安装扩展”安装 build/adsense-mcp.mcpb。它会安全地提示输入 OAuth 值。在支持经典配置的安装中,请改为添加以下内容:
{
"mcpServers": {
"adsense": {
"command": "node",
"args": ["/absolute/path/to/adsense-mcp/dist/index.js"],
"env": {
"ADSENSE_CLIENT_ID": "...",
"ADSENSE_CLIENT_SECRET": "...",
"ADSENSE_REFRESH_TOKEN": "..."
}
}
}
}Codex
将等效的服务器定义添加到您的 Codex MCP 配置中,使用相同的命令、参数和环境变量。该服务器使用标准的 MCP stdio 传输,可在两个客户端中工作。
工具
adsense_list_accountsadsense_get_accountadsense_generate_report
示例报告请求:metrics: ["ESTIMATED_EARNINGS", "PAGE_VIEWS", "CLICKS"]、dimensions: ["DATE", "COUNTRY_NAME"]、dateRange: "LAST_7_DAYS"、orderBy: ["-ESTIMATED_EARNINGS"]。
验证
npm test
npm run build实时验证还需要上述 OAuth 值和一个 AdSense 账户。该 API 的报告端点为 GET /v2/{account}/reports:generate;它需要 AdSense 或 AdSense 只读 OAuth 范围。
许可证
Available Tools
3 toolsadsense_generate_reportA
Extract any ad-hoc AdSense report. Supply API v2 dimensions, metrics, filters, dates, sorting, and other report parameters. Account is discovered automatically when omitted.
Inputs: metrics (required), limit, account, endDate, +8 more.
adsense_get_accountA
Get one AdSense account by resource name, e.g. accounts/pub-123.
Inputs: account (required).
adsense_list_accountsA
List AdSense accounts available to the authenticated user.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Each tool targets a distinct operation: listing accounts, retrieving a specific account, and generating reports. There is no overlap between these actions, and the report tool even auto-discovers the account, reducing ambiguity.
All tool names follow a consistent verb_noun pattern with the 'adsense_' prefix (list_accounts, get_account, generate_report). This makes the naming predictable and easy to navigate.
With 3 tools, the server is on the lower end of the ideal range, but it covers the core AdSense operations: account listing, account retrieval, and report generation. The count feels minimal yet sufficient for a focused server, though slightly thin.
The surface covers essential account and reporting operations, but lacks other common AdSense resources like ad units, sites, or alerts. This might be a notable gap for agents needing broader management capabilities, though it may be acceptable for a report-focused server.
Maintenance
Related MCP Connectors
MCP server for querying and analyzing data from ad platforms, analytics tools, and spreadsheets
Hosted MCP server for GA4, Google Ads and Search Console. Google OAuth, nothing to install.
Google Ads MCP server — manage campaigns, keywords, and metrics.
Query selected Google and Bing analytics, search, and advertising reports through MCP.
Related MCP Servers
- AlicenseAqualityDmaintenanceMCP 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.12MIT
- FlicenseNot gradedqualityDmaintenanceMCP server for Google Ads campaign reporting and management via Claude, enabling GAQL queries, performance metrics, and campaign modifications.-
- AlicenseNot gradedqualityDmaintenanceMCP server for querying Google Analytics accounts, properties, reports, and realtime data using the Data API and Admin API.1Apache 2.0
- AlicenseNot gradedqualityFmaintenanceMCP server that provides tools to interact with Google Analytics APIs, enabling account and property retrieval, report running, and custom dimension/metrics access.Apache 2.0