Skip to content

About

Google Analytics 4 and Search Console for agents: read-only, token-efficient TOON output

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

search-console-axi

CI Platform: Linux and macOS npm weekly downloads

Google Search Console reporting, URL inspection, and preview-gated Indexing API notifications for agents. search-console-axi is an AXI CLI. Output uses compact TOON format. Requires Node.js 22.12 or newer.

npx skills add Dematom1/search-console-axi --skill search-console-axi -g

No install needed: tell your agent "Execute npx -y search-console-axi to read Google Search Console clicks, impressions, top queries and URL indexing status."

Either way, Google credentials are required first: see Authentication.

Optional

Install the CLI globally:

npm i -g search-console-axi
search-console-axi --help

Authentication

The CLI validates credential JSON locally and authenticates through google-auth-library. It never stores or prints OAuth tokens or service-account keys. For personal access, create your own Desktop OAuth client and configure ADC with gcloud auth application-default login --client-id-file=client.json --scopes=https://www.googleapis.com/auth/webmasters.readonly,https://www.googleapis.com/auth/cloud-platform. Google's built-in gcloud OAuth client cannot grant the Search Console scope.

Service account

  1. Create or reuse a Google Cloud project and enable the Google Search Console API.
  2. Create a service account; it needs no project-level IAM roles.
  3. Load its JSON key from your secret manager into SEARCH_CONSOLE_AXI_SA_KEY. Never commit the key.
  4. In Search Console, add the service-account email under Settings > Users and permissions with Restricted access.

For local key files, set GOOGLE_APPLICATION_CREDENTIALS or run search-console-axi setup service-account <key.json>. Credential precedence is SEARCH_CONSOLE_AXI_SA_KEY, GOOGLE_APPLICATION_CREDENTIALS (with google_application_credentials as a fallback alias), the saved path configured by search-console-axi setup service-account, then user ADC. Credential files must contain authorized_user or service_account JSON; service-account registration and SEARCH_CONSOLE_AXI_SA_KEY require service_account JSON. To switch from a saved key to ADC, run search-console-axi setup uninstall; this also removes the CLI's saved quota-project setting. Set the ADC quota project with gcloud auth application-default set-quota-project <project> or use GOOGLE_CLOUD_QUOTA_PROJECT.

Run search-console-axi setup to check credentials and accessible sites. search-console-axi setup status reports local credential configuration, not API access or token validity. It includes the credential type and available account email, never credential contents. search-console-axi setup uninstall removes only the CLI's local configuration. Registration, saved quota-project updates, and removal re-read the configuration before reporting success.

Invalid setup arguments, malformed config, and malformed or unsupported credential data produce VALIDATION_ERROR with exit code 2. Config I/O failures produce CONFIG_ERROR; missing or unreadable credential-file paths produce AUTH_CONFIG_ERROR, both with exit code 1 and repair guidance. search-console-axi setup status instead reports invalid config or credentials as auth.status: invalid with exit code 0; config I/O failures remain errors. Missing credentials produce setup guidance with auth.status: not configured for search-console-axi setup, search-console-axi setup check, and search-console-axi setup status.

Read Search Console

Run search-console-axi for the default site's last seven complete days of clicks, impressions, CTR, position, top queries and pages, and low-CTR opportunities. Set a default site with search-console-axi setup site <site-url>. Reports resolve the site from --site, SEARCH_CONSOLE_AXI_SITE, the saved default, then the first verified site. Use search-console-axi inspect <url> to inspect indexing for a URL; --site is optional and uses the same resolution order. Reporting and inspection do not modify Search Console data; setup may write or remove local configuration.

Read and submit sitemaps

search-console-axi sitemaps list --site sc-domain:example.com
search-console-axi sitemaps get https://example.com/sitemap.xml --site sc-domain:example.com
search-console-axi sitemaps submit https://example.com/sitemap.xml --site sc-domain:example.com
search-console-axi sitemaps submit https://example.com/sitemap.xml --site sc-domain:example.com --confirm

Reads use the same credentials and site resolution as reports. Lists include the path, type, isSitemapsIndex, lastSubmitted, lastDownloaded (last read), isPending, derived status, errors, warnings, and contents[] counts. Status is derived from pending/error fields, not the Search Console UI's status text. Discovered pages are contents[].submitted counts by content type; the API has no separate UI discovered-pages column, so no total across content types is invented. contents[].indexed is deprecated and is shown only as returned, not reliable index coverage. Missing fields are null (unknown), not zero.

Submit requires an explicit --site naming the exact property, even if a default is configured. Without --confirm, it previews the exact property, sitemap and PUT request locally without credentials or network access. With --confirm, it submits once, without retries. An acknowledgement does not guarantee a crawl or indexing. If the outcome is unknown, use sitemaps get before retrying.

Submission requests https://www.googleapis.com/auth/webmasters; reads still request only webmasters.readonly. Read-only user ADC cannot submit: explicitly reauthorize your own Desktop OAuth client with the write scope. Existing refresh tokens are never silently widened. The authenticated account also needs permission to submit sitemaps on the property; Restricted access is not sufficient. No confirmed live submissions should be used for development or tests.

List pages by indexing state

coverage reads URL Inspection for URLs you supply. The API does not expose the Page indexing report or its example URLs. Results describe Google's indexed version, not a live inspection or an exhaustive list of a property's pages.

search-console-axi coverage --sitemap https://example.com/sitemap.xml --site sc-domain:example.com
search-console-axi coverage urls.txt --state /tmp/example-coverage.json
search-console-axi coverage - --format json < urls.txt
search-console-axi coverage urls.txt --format csv > coverage.csv

File and stdin input contain one absolute HTTP or HTTPS URL per line. Blank lines are ignored and duplicates are inspected once. URLs outside the selected property are reported as skipped (out of property) without consuming inspection quota. Domain properties include subdomains; URL-prefix properties restrict requests to their origin and path. Narrow the input or select the matching property to inspect skipped URLs. An exact verified --site is preferred over broader properties. Sitemap input supports XML sitemap indexes, child sitemaps, and gzip. Index cycles are ignored. A run accepts at most 1,000 sitemap documents, each up to 50 MiB uncompressed, and 100,000 total sitemap entries. HTTP redirects are rejected, and child sitemaps must share the root sitemap's origin. To use a trusted external sitemap, invoke coverage with that sitemap directly. DTDs are rejected. Coverage never submits URLs or calls the Indexing API.

TOON output groups counts and URL lists by coverageState, verdict, Google's canonical URL (or unknown), canonical match (same, different, or unknown), and last-crawl age. Crawl buckets are under 7 days, 7–29 days, 30 days or older, and unknown. Missing canonical fields do not imply a mismatch. JSON output includes per-URL rows plus progress and quota metadata. CSV output contains per-URL rows on stdout and TOON progress metadata on stderr. Exports retain the documented field names coverageState, verdict, googleCanonical, userCanonical, and lastCrawlTime, plus url and inspectedAt.

Google's URL Inspection limits are 2,000 requests per property per day and 600 per minute. Coverage spaces requests at least 110 ms apart and uses a conservative rolling 24-hour local budget. It reserves quota before each attempt, including failed or interrupted requests. A shared per-property ledger prevents separate progress files from resetting local accounting. External usage is unknown, not reported as zero. Any API quota error stops the run and conservatively pauses that property for 24 hours. Output reports requests inspected in this run, URLs remaining, locally observed attempts, and the earliest local resume time. A quota stop exits successfully with partial results; check remaining and stop before treating an export as complete.

Rerun the same command to resume. Finished URLs are not inspected again unless you pass --refresh; refresh does not reset quota. A refresh pass saves its target URLs and completed URLs, so rerunning an interrupted or quota-limited pass continues the unfinished targets, even without --refresh. Once that pass finishes, --refresh starts a new one. Keep the same input when resuming a pass. Each result is appended to a private <state>.jsonl journal, then compacted into the state snapshot once the run ends. Interrupted final journal records are discarded, while committed rows are replayed on resume. Snapshot compaction and quota accounting use atomic file replacement. Keep the journal alongside the snapshot until compaction removes it. The default state lives under $XDG_STATE_HOME/search-console-axi/coverage, or ~/.local/state/search-console-axi/coverage, never the repository. --state names a different progress file but leaves quota accounting in the user state directory. Do not delete the ledger to bypass limits. Progress files belong to one property and contain URL data; protect them accordingly.

Ctrl-C and SIGTERM finish the in-flight inspection, save it, and stop before the next URL. Concurrent runs for the same property or progress file fail with a lock error. After a forced kill, remove only the lock file named by the error, and only after confirming no coverage process is running. The saved results remain intact.

Send Indexing API notifications

Google supports the Indexing API only for pages with JobPosting or BroadcastEvent embedded in VideoObject structured data. Job-posting pages fit this scope. It is not a general-purpose indexing API. A successful submission acknowledges a notification, not a crawl or index guarantee.

Enable the Indexing API in your Google Cloud project. The service account must be an owner of the Search Console property, not merely a Restricted or Full user. The same credential precedence and local configuration apply. Notification commands request https://www.googleapis.com/auth/indexing; reporting still requests only webmasters.readonly. For user ADC, reauthorize your own Desktop OAuth client with the indexing scope as well as the reporting scopes above. Existing refresh tokens cannot gain scopes automatically.

search-console-axi indexing publish https://example.com/jobs/1 --type updated
search-console-axi indexing publish https://example.com/jobs/1 --type updated --confirm
search-console-axi indexing publish https://example.com/jobs/1 --type deleted
search-console-axi indexing status https://example.com/jobs/1
search-console-axi indexing batch urls.txt --type updated
search-console-axi indexing batch - --type deleted --confirm < urls.txt
search-console-axi indexing quota

publish and batch are local previews until --confirm. Previews list every explicit URL target, the notification count, and the HTTP request count without loading credentials or calling Google. Batch input contains one absolute HTTP or HTTPS URL per line; blank lines are ignored. Duplicate URLs remain separate requests. URLs with embedded credentials, fragments, or whitespace are rejected. All input is validated before any submission. Each multipart batch contains at most 100 notifications, and each notification consumes quota separately.

Before --type deleted, the page must return HTTP 404 or 410 or contain a noindex directive. status reads urlNotifications.getMetadata: the last notification times, not the page's indexing status. Use search-console-axi inspect for index status.

Confirmed batches report every URL as submitted, failed, or unknown, with an HTTP status where available. Any failed or unknown result sets exit code 1. Authentication, API, and transport errors omit raw server messages and credential contents. A 403 explains the owner, API enablement, and scope requirements; a 429 explains quota exhaustion. Requests are not automatically retried. An unknown outcome may already have reached Google; check notification status before retrying. Successful URLs in a partially failed batch must not be resubmitted blindly.

Read project quota

The Indexing API has no usage endpoint. search-console-axi indexing quota reads effective limits from Service Usage and today's observed request counts from Cloud Monitoring. The selected project is the configured quota project sent with requests, or the credential's project_id if no override exists. The output identifies that project and the source. User ADC without either project requires search-console-axi setup --quota-project <project>.

Quota reads request cloud-platform.read-only and monitoring.read OAuth scopes. User ADC with cloud-platform also supports both endpoints. Limits require serviceusage.quotas.get; usage requires monitoring.timeSeries.list on the selected project. These optional IAM permissions are separate from Search Console ownership. The Service Usage and Cloud Monitoring APIs must be enabled.

Usage covers midnight Pacific Time through the query time. Counts include completed requests and failures, grouped by API method, and may lag up to 30 minutes. These are observed requests, not authoritative daily publish quota consumption. Empty time series mean unknown, not zero. Unreadable limits or usage identify the required permission rather than inventing a number. A readable half remains available if the other fails.

The documented defaults are labelled separately: 200 publish requests per day, 180 metadata requests per minute, and 380 total requests per minute. They are not reported as your project's actual limit or remaining allowance.

About

Google Analytics 4 and Search Console for agents: read-only, token-efficient TOON output

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages