Google AdSense

السجل الرسمي المالية والمدفوعات

Read AdSense Management API v2 accounts, inventory, payments, policy, and reports through MCP.

التثبيت

أضف هذا إلى إعدادات MCP في عميلك (Claude Desktop: claude_desktop_config.json، وCursor: ‏.cursor/mcp.json، ويستخدم VS Code وغيره الصيغة نفسها «mcpServers»).

NPM package @sirmacke/adsense-mcp
Claude Code
claude mcp add google-adsense -e 'ADSENSE_ACCESS_TOKEN=<your adsense_access_token>' -e 'ADSENSE_CLIENT_ID=<ADSENSE_CLIENT_ID>' -e 'ADSENSE_CLIENT_SECRET=<your adsense_client_secret>' -e 'ADSENSE_REFRESH_TOKEN=<your adsense_refresh_token>' -e 'ADSENSE_ACCOUNT=<ADSENSE_ACCOUNT>' -- npx -y @sirmacke/adsense-mcp@0.2.0
إعداد JSON (Claude Desktop وCursor وVS Code)
{
    "mcpServers": {
        "google-adsense": {
            "command": "npx",
            "args": [
                "-y",
                "@sirmacke/adsense-mcp@0.2.0"
            ],
            "env": {
                "ADSENSE_ACCESS_TOKEN": "<your adsense_access_token>",
                "ADSENSE_CLIENT_ID": "<ADSENSE_CLIENT_ID>",
                "ADSENSE_CLIENT_SECRET": "<your adsense_client_secret>",
                "ADSENSE_REFRESH_TOKEN": "<your adsense_refresh_token>",
                "ADSENSE_ACCOUNT": "<ADSENSE_ACCOUNT>"
            }
        }
    }
}

متغيرات البيئة

  • ADSENSE_ACCESS_TOKEN سري Optional short-lived OAuth access token.
  • ADSENSE_CLIENT_ID OAuth desktop client ID. Required when not using an access token.
  • ADSENSE_CLIENT_SECRET سري OAuth desktop client secret. Required when not using an access token.
  • ADSENSE_REFRESH_TOKEN سري OAuth refresh token. Required when not using an access token.
  • ADSENSE_ACCOUNT Optional AdSense account resource name. The first accessible account is used when omitted.

التوثيق

مأخوذ من ملف README للمشروع على GitHub ويُحدَّث أسبوعيًا. تفتح الروابط على GitHub.

المحتويات
  1. AdSense MCP
  2. Install
  3. Security
  4. Setup
  5. Claude Desktop
  6. Codex
  7. Tools
  8. Verify
  9. Releasing
  10. License

AdSense MCP

An MCP server providing read-only access to the AdSense Management API v2: accounts, payments, alerts, policy issues, sites, inventory, ad code, and saved or ad-hoc reports.

The server uses the read-only https://www.googleapis.com/auth/adsense.readonly OAuth scope. It does not write to an AdSense account.

Install

Once published, run it from an MCP client with npx -y @sirmacke/adsense-mcp. Configure either ADSENSE_ACCESS_TOKEN, or all three of ADSENSE_CLIENT_ID, ADSENSE_CLIENT_SECRET, and ADSENSE_REFRESH_TOKEN.

Security

OAuth access tokens, refresh tokens, and client secrets are credentials. Keep them out of this repository, issue trackers, shell history, and MCP configuration that is shared with others. If one is exposed, revoke it in Google Cloud immediately; see SECURITY.md.

Setup

  1. In Google Cloud, enable AdSense Management API and create an OAuth Desktop client.
  2. Obtain a refresh token granted the https://www.googleapis.com/auth/adsense.readonly scope. Keep it secret.
  3. Copy .env.example to your secure environment configuration and populate either ADSENSE_ACCESS_TOKEN or the OAuth client ID, secret, and refresh token.
  4. Install and build:
npm install
npm run build
One-time OAuth authorization (without gcloud)

Download the OAuth Desktop client JSON from Google Cloud, then run:

$env:ADSENSE_OAUTH_CLIENT_FILE = "C:\secure\adsense-client.json"
$env:ADSENSE_TOKEN_FILE = "C:\secure\adsense-oauth.json"
npm run authorize

The command opens the Google consent screen on a localhost callback and saves the client ID, client secret, and refresh token only in the private token file. Copy those values to the ADSENSE_CLIENT_ID, ADSENSE_CLIENT_SECRET, and ADSENSE_REFRESH_TOKEN fields of the MCP configuration. Do not leave an External consent screen in Testing: its refresh tokens expire after seven days.

Claude Desktop

Current Claude Desktop builds use extensions. Run npm run package, then install build/adsense-mcp.mcpb from Settings → Extensions → Advanced settings → Install extension. It securely prompts for the OAuth values. On installations that support classic configuration, add this instead:

{
  "mcpServers": {
    "adsense": {
      "command": "node",
      "args": ["/absolute/path/to/adsense-mcp/dist/index.js"],
      "env": {
        "ADSENSE_CLIENT_ID": "...",
        "ADSENSE_CLIENT_SECRET": "...",
        "ADSENSE_REFRESH_TOKEN": "..."
      }
    }
  }
}

Codex

Add the equivalent server definition to your Codex MCP configuration, using the same command, arguments, and environment variables. The server uses the standard MCP stdio transport and works in both clients.

Tools

Accounts and account status
  • adsense_list_accounts
  • adsense_get_account
  • adsense_list_child_accounts
  • adsense_list_payments
  • adsense_list_alerts
  • adsense_get_ad_blocking_recovery_tag
  • adsense_list_policy_issues
  • adsense_get_policy_issue
  • adsense_list_sites
  • adsense_get_site
Inventory
  • adsense_list_ad_clients
  • adsense_get_ad_client
  • adsense_get_ad_client_ad_code
  • adsense_list_ad_units
  • adsense_get_ad_unit
  • adsense_get_ad_unit_ad_code
  • adsense_list_linked_custom_channels
  • adsense_list_url_channels
  • adsense_get_url_channel
  • adsense_list_custom_channels
  • adsense_get_custom_channel
  • adsense_list_linked_ad_units
Reports
  • adsense_list_saved_reports
  • adsense_get_saved_report
  • adsense_generate_saved_report
  • adsense_generate_report

Account-level tools discover the configured or first accessible account when account is omitted. Paginated list tools accept pageSize and pageToken; pass a returned nextPageToken to continue. Resource-specific tools accept the canonical names returned by their corresponding list tools.

adsense_list_payments returns paid and unpaid earnings, including the formatted amount and, for paid earnings, the credited date. The AdSense API does not expose bank or payment-method details.

Example report request: metrics: ["ESTIMATED_EARNINGS", "PAGE_VIEWS", "CLICKS"], dimensions: ["DATE", "COUNTRY_NAME"], dateRange: "LAST_7_DAYS", orderBy: ["-ESTIMATED_EARNINGS"].

The server returns structured JSON. The API's duplicate CSV report methods are intentionally omitted because agents can transform the structured response when CSV is needed.

Verify

npm test
npm run build

Live verification also requires the OAuth values above and an AdSense account. Every exposed endpoint accepts the AdSense read-only OAuth scope.

Releasing

Releases are published to both npm and the official MCP Registry. The registry stores discovery metadata from server.json; the installable server itself is distributed through npm.

  1. Update the version consistently in package.json, package-lock.json, server.json (including its npm package entry), mcpb/manifest.json, and the MCP server version in src/index.ts.
  2. Run npm test and npm pack --dry-run to verify the build and published package contents.
  3. Commit and push the release to GitHub.
  4. Publish the public scoped package with npm publish --access public.
  5. Authenticate when necessary with mcp-publisher login github, then run mcp-publisher publish to publish the matching server.json version.

Publish npm before the MCP Registry because registry validation requires the referenced public package version to exist. Published versions are immutable, so corrections require a new version.

License

MIT

الأسئلة الشائعة

ما هو Google AdSense؟

Read AdSense Management API v2 accounts, inventory, payments, policy, and reports through MCP.

كيف أثبّت Google AdSense؟

يعمل على جهازك. في Claude Code: claude mcp add google-adsense -e 'ADSENSE_ACCESS_TOKEN=<your adsense_access_token>' -e 'ADSENSE_CLIENT_ID=<ADSENSE_CLIENT_ID>' -e 'ADSENSE_CLIENT_SECRET=<your adsense_client_secret>' -e 'ADSENSE_REFRESH_TOKEN=<your adsense_refresh_token>' -e 'ADSENSE_ACCOUNT=<ADSENSE_ACCOUNT>' -- npx -y @sirmacke/adsense-mcp@0.2.0. وفي العملاء الآخرين، الصق إعداد JSON من هذه الصفحة في إعدادات MCP الخاصة بهم.

هل يحتاج Google AdSense إلى مفتاح API؟

نعم. يتطلب ADSENSE_ACCESS_TOKEN, ADSENSE_CLIENT_SECRET, ADSENSE_REFRESH_TOKEN، وتضبطها في إعداداته.

هل Google AdSense مفتوح المصدر؟

نعم. شيفرته متاحة على GitHub بترخيص MIT.

من يصون Google AdSense؟

ينشره SirMacke. يدرجه AI.tn لكنه لا يصونه ولا يوصي به.

من سجل MCP الرسمي. الإدراج ليس توصية: راجع شيفرة الخادم وصلاحياته قبل منحه الوصول إلى بياناتك.