/ranking:ranking-db-queriesfrom ranking
Run safe, read-only SQL against the Ranking Service production MariaDB (`bwp_ranking_service`, plus the external `bwp_seo` DB the auto-queue reads) through the bwp-core DBHub MCP server. Use whenever the user asks to query the prod ranking db, look up or count rows, run ad-hoc SELECTs or audit data: "how many reports are PENDING", "show me failed serp tasks", "score history for keyword X", "why wasn't domain X auto-queued", "select from serp_reports", "audit DataForSEO costs", or "ranking-db-queries". Column reference is the ranking-service repo (`app/models/*.py`; external tables in `app/models/external/`). Four-layer read-only contract (MariaDB role + READ ONLY transaction + DBHub classifier + timeout); never mutates production. Admins can also re-queue, re-score or re-run one engine of a domain's report ("re-queue the ranking report", "report got stuck", "re-run bing for {domain}", "the google SERPs were bad") through the cade-mcp ranking_queue / ranking_rescore / ranking_rerun tools.
Ships in ranking. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Read-only SQL access to the Ranking Service production MariaDB. One job, done safely.
bwp-core plugin's dbhub MCP server, source id ranking (full ids: mcp__plugin_bwp-core_dbhub__<tool>):
execute_sql_ranking { "sql": "..." } — read-only, 30 s timeout, no row cap.search_objects_ranking { "object_type": "table|view|column|index", "pattern": "serp%", "detail_level": "names|summary|full", "table": "..." } — progressive disclosure: names first, full only for the one table you need.explain_sql_ranking { "sql": "..." } — returns the plan without executing (replaces the old --explain).references/schema.md — table catalog for bwp_ranking_service and the relevant bwp_seo tables, verified against live prod. Load when you need column-level detail.references/recipes.md — read-only SELECTs grouped by area (domains/keywords, pipeline health, failures, costs, scores, auto-queue). Load when the user's request matches a common pattern — copy a recipe and narrow the WHERE rather than starting from scratch.bwp-core plugin points at the hosted DBHub gateway (https://dbhub.imagehosting.space/mcp); access is gated by a one-time company Google sign-in (Pomerium), so there is nothing to configure per call.Two databases on the same production MariaDB server; the ranking source defaults to the first:
bwp_ranking_service (default) — this service's own DB: 5 tables (domain, keywords, serp_reports, serp_tasks, serp_rank_scores) plus alembic_version. The schema is owned by the ranking-service repo: app/models/*.py + app/core/enums.py + Alembic migrations are the authoritative column reference.bwp_seo — the external legacy DB the auto-queue reads (~52 tables). Reach it with qualified names (bwp_seo.bwp_domains) — there is no --db switch any more. The 5 tables this service touches are modeled read-only in app/models/external/*.py: bwp_domains, bwp_domain_settings, bwp_services, bwp_bubblefeed, bwp_bubblefeedsupport. For anything else, use live discovery (SHOW COLUMNS FROM bwp_seo.<table>).Enum casing gotcha: enum columns store the UPPERCASE Python enum names, not the lowercase values — in raw SQL write WHERE status = 'PENDING', never 'pending'. See references/schema.md.
The MCP connection is prod only. If the user says "staging" / "stg" / "local" / "dev", do not run it against the ranking source — tell the user non-prod isn't wired to this skill.
Trigger on any "look at the prod ranking data" request. Examples:
bwp_seo eligibility chain)If the user wants source-code investigation, that lives in Read / Grep and code-explorer. This skill may be one input into a larger investigation — but it is not the orchestrator.
Four layers. Any single layer being bypassed leaves the others standing:
claude_readonly (SELECT only). Operator setup snippet below.execute_sql_ranking inside START TRANSACTION READ ONLY; ...; ROLLBACK. MariaDB rejects writes server-side with error 1792.SELECT / WITH / EXPLAIN / SHOW / DESCRIBE / DESC, and rejects any mutating keyword (INSERT|UPDATE|DELETE|DROP|ALTER|CREATE|TRUNCATE|MERGE|GRANT|REVOKE|RENAME|REPLACE INTO) anywhere in the body — including inside CTEs. On MariaDB, DDL implicitly commits and is stopped only by this layer, so layer 1 matters.query_timeout = 30 s. No row cap.If a call is rejected, that's the guardrail doing its job — rephrase, don't try to bypass.
The claude_readonly / claude_rw DB users, their secrets and the DBHub deploy live in seo-money-deployments — see docs/setup-dbhub-tutorial.md there.
// Simple query — always carry a LIMIT (aggregate where you can)
execute_sql_ranking { "sql": "SELECT status, COUNT(*) FROM serp_reports GROUP BY status" }
// External bwp_seo DB — qualify the table (auto-queue investigations)
execute_sql_ranking { "sql": "SELECT id, domain_name, status, deleted, skipfeedchecker FROM bwp_seo.bwp_domains WHERE domain_name = 'example.com' LIMIT 1" }
// Plan only (never executes)
explain_sql_ranking { "sql": "SELECT ... big join ..." }
// Discover columns of one table
search_objects_ranking { "object_type": "column", "table": "serp_tasks", "detail_level": "summary" }
// Wide row — project the columns instead of SELECT *
execute_sql_ranking { "sql": "SELECT id, status, failure_reason, created_at FROM serp_tasks WHERE id = '<uuid>'" }
One statement per call. Results come back as JSON rows; relay them as a compact table.
Reads never mutate. Updates go through a separate tool, execute_sql_ranking_rw, provided by the bwp-rw plugin (Claude Code only — it prompts each person for their own token; Desktop/Cowork users have read access only). Rules:
SELECT the exact rows first with execute_sql_ranking and show them to the user.UPDATE … WHERE <primary key> per call — never a bare UPDATE, never a range unless the user spelled it out. Relay the affected-row count back.claude_rw) can only SELECT and UPDATE: INSERT, DELETE, TRUNCATE and DDL are refused by the engine — don't try.execute_sql_ranking_rw isn't available, say so: the user installs bwp-rw@bwp-tools and enters their token (/plugin → bwp-rw → configuration).execute_sql_ranking { "sql": "SELECT id, status, failure_reason FROM serp_tasks WHERE id = '<uuid>'" } // 1. look
execute_sql_ranking_rw { "sql": "UPDATE serp_tasks SET status = 'PENDING' WHERE id = '<uuid>'" } // 2. change, after confirmation
A report can't be deleted or rebuilt with SQL (no INSERT/DELETE grant). Three cade-mcp connector tools reach ranking-service's admin API instead. All refuse anyone not in cade-mcp's admin list, and all need confirm_domain to repeat domain exactly. Each call is audited.
ranking_queue { domain, confirm_domain } queues a new report, which costs about $0.50 of DataForSEO calls. "Task queued" only means the Celery task was sent. The worker still refuses a domain that already has a PENDING or IN_PROCESS report, and one that isn't active in bwp_seo. Confirm it landed: SELECT id, status, created_at FROM serp_reports WHERE domain_id = '<id>' ORDER BY created_at DESC LIMIT 2.ranking_rescore { domain, confirm_domain } deletes the latest report's scores, resets its tasks to COLLECTED and sets it IN_PROCESS, so the scorer re-runs on SERP data already fetched. Nothing new is bought. Use it after a scoring fix, not when the SERPs themselves were bad. While that report is IN_PROCESS, ranking_queue is refused.ranking_rerun { domain, confirm_domain, engine, serp_type? } fetches one engine's SERPs (google, bing or yahoo) again for the latest report and re-scores them. serp_type (organic or images) narrows it; without it all of that engine's tasks re-run. It buys new SERPs for that engine only; the other engines' tasks and scores stay. The report goes PENDING and is hidden from clients until it is PROCESSED again (~20-45 min); it keeps its original completed_at, so no second "report ready" email goes out. Refused (409) while the latest report isn't PROCESSED. Confirm it finished: SELECT search_engine, serp_type, status, COUNT(*) FROM serp_tasks WHERE report_id = '<id>' GROUP BY 1, 2, 3.Which one: rescore after a scoring fix (buys nothing), re-run when one engine's SERPs were bad (buys that engine only), queue for a whole new report (buys all four checks).
A bad report (e.g. PROCESSED with far fewer scores than the previous one) doesn't block a new one; just queue. Before queuing or re-running, confirm with the user: both spend money. A non-admin is refused; tell them to ask an admin.
You're talking to prod. Be polite:
app/models/*.py (or app/models/external/*.py for bwp_seo), use search_objects_ranking, or fall back to SHOW COLUMNS FROM <table>. Don't fish.'PENDING', 'QUEUED', 'GOOGLE', 'ORGANIC') even though the Python enum values are lowercase.SELECT status, COUNT(*) FROM serp_tasks GROUP BY status beats 1000 raw rows.serp_tasks ~32K, serp_rank_scores ~22K are fine; bwp_seo.bwp_log_page ~6.2M and bwp_seo.bwp_modification_log ~1.1M are not) — explain_sql_ranking returns the plan without executing.SELECT * on bwp_seo.bwp_register or bwp_seo.bwp_creditcardinfo; project columns and mask emails/card data when relaying results.When references/schema.md and search_objects_ranking don't have what you need (swap the table_schema literal for bwp_seo when exploring the external DB):
-- Tables in the database
SHOW TABLES;
-- Columns of a table (compact)
SHOW COLUMNS FROM serp_tasks;
-- Columns with full info
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_schema = 'bwp_ranking_service'
AND table_name = 'serp_tasks'
ORDER BY ordinal_position;
-- Index list for a table
SHOW INDEXES FROM serp_reports;
-- Approximate row count (information_schema, no scan)
SELECT table_name, table_rows
FROM information_schema.tables
WHERE table_schema = 'bwp_ranking_service'
ORDER BY table_rows DESC
LIMIT 25;
-- Foreign keys for a table
SELECT column_name, referenced_table_name, referenced_column_name
FROM information_schema.key_column_usage
WHERE table_schema = 'bwp_ranking_service'
AND table_name = 'serp_tasks'
AND referenced_table_name IS NOT NULL;
cade-db-queries skill (cade plugin).bwp_seo questions, prefer the seolocal-db-queries skill (seolocal plugin); this skill only reaches into bwp_seo for auto-queue eligibility.Read / Grep.UPDATE through execute_sql_ranking_rw only (see Updating rows); INSERT, DELETE and DDL are impossible by DB grant. Queuing, re-scoring and re-running go through the admin-only cade-mcp tools (see Re-queue, re-score or re-run a report). Anything else the user runs themselves (or via Alembic).What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub blackwoodproductions/bwp-tools --plugin ranking