--- name: "kw-research-pipeline" description: Run a complete 9-step SEO keyword-research pipeline for a seed keyword and domain — seed metrics, real organic competitors, long-tail discovery, competitor gap analysis, People-Also-Ask questions, topic + page-type clustering, traffic estimates, and a prioritised list of pages to create. Pulls live data from the Mangools API (KWFinder + SERPChecker) using the user's own Mangools key. Use this whenever the user wants keyword research, an SEO content plan, competitor keyword gaps, a topic/content map, "what pages should I build to rank for X", or mentions Mangools/KWFinder — even if they don't say "pipeline". Requires the Code Execution tool and a Mangools API key. Version 7.4. --- # KW Research Pipeline (v7.4) Turn one **seed keyword** + one **domain** into a prioritised SEO content plan, backed by live Mangools data. You (Claude) orchestrate nine steps: some pull data via the bundled Mangools script, others are your own analysis. **Read `references/methodology.md` before running the pipeline.** It holds every threshold, formula, list, class definition and response field name. This file is the map; that file is the detail. ## Before you start 1. **Mangools API key (required).** Ask the user to upload `mangools.env` (one line: `MANGOOLS_API_KEY=...`). The bundled `scripts/loadkey.py` prints the key from that file, or a short error. Only ever call it inside `$(...)` as shown here, never on its own. A shell variable lives only inside the bash call that sets it, so load the key in the same call as every command that needs it, with this prefix: ```bash export MANGOOLS_API_KEY="$(python3 /scripts/loadkey.py )"; ``` If the loader prints `no MANGOOLS_API_KEY=... line found`, do not open or print the file; ask the user to re-save it as a plain text file with exactly one line, `MANGOOLS_API_KEY=`, and upload it again. If it prints `cannot open`, fix the path. If the user pasted the key as text instead, save it once with `printf 'MANGOOLS_API_KEY=%s\n' '' > mangools.env` (in Claude Code, `mkdir -p /tmp/kw-research` and write it to `/tmp/kw-research/mangools.env`, never inside a repository; this is the only command that may ever contain the key), use that full path from then on, and tell them the key is now in this chat's history and should be reset at mangools.com/api-token after the session. Never print, echo or quote the key in a reply, in any other command or file, and never use the script's `--apikey` flag. Every lookup bills the user's own Mangools account; say so. 2. **Seed keyword + domain (required).** The domain is the user's own site: it is excluded from competitor results, is the baseline for the gap analysis (Step 4), and its profile (Step 0b) is the yardstick for relevance. 3. **Region (optional).** Default US/English. Built-in countries, with city suggestions: `us=2840 gb=2826 au=2036 ca=2124 de=2276 fr=2250`. Any other country works too: look up its ID (free) with `locations --query ""` and take the `Country` row (Spain 2724, Czechia 2203). Pass the country ID as `--location` on `related`, `serp`, `gap`, `import-keywords` and `domain-keywords`; on `serp-dual` and `suggest-cities` pass `--country ` as the built-in code, the country ID or the country name (a two-letter code outside the six is rejected); `locations --country ` takes the two-letter code, which `suggest-cities` returns in its `country` field. Pass the seed language as `--language` on `related` and `import-keywords`, using Google Ads IDs: verified `en=1000 de=1001 fr=1002 es=1003 cs=1021 pl=1030 sk=1033`; other languages follow the same Google Ads list. A keyword in one language with another language's ID fails with a 500 "No available SERP provider". ## Commands, files and how to read them The script `/scripts/mangools.py` uses only the standard library. Commands: `limits`, `related`, `serp` (one location), `serp-dual` (country + city; use it for every SERP check except the seed's national SERP in Step 1), `gap`, `import-keywords`, `domain-keywords`, `suggest-cities`, `locations`, `show` and `slug`. `--help` lists the flags. Run every command from the sandbox's default working folder, never from inside the skill folder, and call the script by its full path. In Claude Code, local or cloud, write nothing inside a repository: use absolute paths under `/tmp/kw-research/` for the key file and the run folders (the shell can be back in the project folder between commands, and a relative `data/` would then land in the repository). **Each run has its own folder, `` = `data/-`** (in Claude Code `/tmp/kw-research/data/-`; `` is the seed's ``, below, or the user's domain for a request without a seed; `` is the two-letter code). If that folder already exists from an earlier run, add `-2`, `-3` and keep that name for the whole run. Create it in Step 0 and write every file of the run there; nothing is read from another run's folder. A new seed or region in the same chat is a new run: start it at Step 0, keep the confirmed profile unless the domain changed, and ask the city question again, offering the previous city first. A seed switch in Step 1 also starts a new folder. **Always redirect script output to a file under `/` and never print a full response.** ```bash mkdir -p export MANGOOLS_API_KEY="$(python3 /scripts/loadkey.py )"; python3 /scripts/mangools.py related --kw "" --location --language > /related-.json python3 /scripts/mangools.py show /related-.json --rows 40 ``` `` is what `python3 /scripts/mangools.py slug --kw ""` prints (no key, no API call): the keyword in lowercase, letters of every language kept as typed ("gartenmöbel lounge" → "gartenmöbel-lounge", "купити диван" → "купити-диван"), every run of spaces and other characters replaced by one hyphen. When punctuation was dropped or the keyword is very long, a 6-character code is added, so two keywords never share a file ("c++ tutorial" and "c tutorial" get different names). The loops below and the export file names use it. Read every saved file with `show` (no key, no API call). It detects the file type and prints a compact summary: rows with `countKeywordsBeforeLimit` for `related`; overlap stats, KD, both result lists and `PAA` lines for `serp-dual`. A broken file (error, empty, not JSON, cut off) gives one `call failed: ...` message and exit 1, the error to handle under Output principles; `unrecognised file` (or `call failed: unexpected response shape`) means the call succeeded with an unexpected shape (inspect the file with a short script); `no location matched` is an empty `locations` result. `show` prints files in API order: whenever a step says to filter or sort, do it in a short Python script over the saved file and print only the matching rows; never pick keywords from the first rows of `show`. Field names are in the reference, §1. ## Every SERP check is dual: country + one city Google often serves a city-located searcher a very different SERP; in testing the national and city top 10 for the same keyword shared as few as 1 of 9 domains, sometimes none. So every SERP check runs `serp-dual` for the country and one city (the seed's national half is fetched in Step 1 and completed in Step 2): ```bash export MANGOOLS_API_KEY="$(python3 /scripts/loadkey.py )"; python3 /scripts/mangools.py serp-dual --kw "" --country --city-id --city-label "