---
name: policygrain
description: Agent-first DPDP Act 2023 & DPDP Rules 2025 tooling — scan public websites with CheckMyDPDP, generate cited Indian legal notices from deterministic templates, publish hosted legal pages, install the consent banner, and verify live banner installations.
version: 0.9.1
---

# PolicyGrain & CheckMyDPDP Agent Skill (v0.9)

PolicyGrain is an API-first DPDP Act, 2023 and DPDP Rules, 2025 platform. **CheckMyDPDP** (`checkmydpdp.com`) is PolicyGrain's public website scanner, sharing the same API (`https://api.policygrain.com`), SSRF-hardened browser sandbox, and pinned statutory citations.

> **Notice (ADR 0014):** PolicyGrain is not a law firm. Generated documents and scanner explanations are derived from the DPDP Act, 2023, the DPDP Rules, 2025, and the adjacent Indian laws they cite, using your answers. Nothing here is legal advice; you can have outputs reviewed by your own lawyer. PolicyGrain is **not** a registered Consent Manager under DPDP Act s.6(9). Never claim a site or document is "DPDP compliant" or "certified".

> **Pre-release (v0.9):** the npm packages `@policygrain/mcp`, `policygrain` and `checkmydpdp` are not on the npm registry yet, so `npx` cannot fetch them; run them from a checkout of the PolicyGrain repository (below) or call the HTTP API directly. Set `POLICYGRAIN_API_URL` to the API you were given (for example `https://staging.policygrain.com`); the CLI, the MCP server and the banner's `data-pg-api` all read it or take it explicitly. Check the API with `GET /v1/status` before you start.

## 1. Quick onboarding (Claude Code, Cursor, Codex)

### Option A — MCP server (`@policygrain/mcp`)

Configure the stdio MCP server in Claude Code, Cursor, or Codex, passing `POLICYGRAIN_API_KEY` solely via environment variables:

```json
{
  "mcpServers": {
    "policygrain": {
      "command": "npx",
      "args": ["-y", "@policygrain/mcp"],
      "env": {
        "POLICYGRAIN_API_KEY": "${POLICYGRAIN_API_KEY}",
        "POLICYGRAIN_API_URL": "https://api.policygrain.com"
      }
    }
  }
}
```

Until the package is published, use `"command": "node"` with `"args": ["<checkout>/clients/mcp/src/bin.ts"]` (Node 26, after `pnpm install` in the checkout).

MCP tools: `checkmydpdp_scan`, `checkmydpdp_get_scan`, `checkmydpdp_create_handoff`, `policygrain_account`, `policygrain_list_questions`, `policygrain_list_profiles`, `policygrain_create_profile`, `policygrain_update_profile`, `policygrain_generate_documents`, `policygrain_get_generation`, `policygrain_list_documents`, `policygrain_get_document_version`, `policygrain_publish_document`, `policygrain_list_sites`, `policygrain_verify_domain`, `policygrain_start_verification`. Creating sites and banner configs is HTTP-only for now (Step 4).

### Option B — CLI (`npx policygrain` / `npx checkmydpdp`)

```bash
# Run a free public CheckMyDPDP scan (no API key required for up to 3 scans/IP/day)
npx checkmydpdp https://example.in --json

# Initialise a local PolicyGrain project config (.policygrain.json; reads POLICYGRAIN_API_KEY from env)
npx policygrain init --domain example.in

# List generated documents for a profile, or start a live banner check for a site
npx policygrain docs <profile-id> --json
npx policygrain verify <site-id> --json
```

Every command takes `--api-url <url>` (default: `POLICYGRAIN_API_URL`, then `https://api.policygrain.com`) and `--help`; unknown flags are refused. Until the package is published, run `node <checkout>/clients/cli/src/bin-policygrain.ts` or `node <checkout>/clients/cli/src/bin-checkmydpdp.ts` with the same arguments.

### Option C — Direct HTTP API

`GET /v1/openapi.json` is the full OpenAPI 3.1 contract for every route below, with request and response schemas. `GET /v1/questions` is the question set.

## 2. Authentication & secret hygiene

- **Never** hard-code, print, log, or commit `pgk_*`, `pgs_*`, `pgr_*`, or `pgt_*` secrets.
- Always read credentials from `POLICYGRAIN_API_KEY` in the shell environment.
- Request a scoped key if the user has none:
  - `POST /v1/keys` with `{"email": "owner@example.in", "scopes": ["documents", "sites:write"]}`
  - The response's `key` field holds the one-time `pgk_...` secret (`key_id` is its id). Store it in the user's secret manager or shell env (never write it to tracked files).
  - Scopes: `documents` (profiles, generations, documents, publication), `sites:write` (sites, domains, banner configs, verifications), `evidence:read` (receipts and consent events), `keys` (list and revoke keys). Omit `scopes` to get all four. Reading consent records also needs the email's owner to sign in once.
- Send `Authorization: Bearer $POLICYGRAIN_API_KEY` on authenticated routes.
- Send a unique `Idempotency-Key` header on `POST` creation routes (`POST /v1/profiles`, `POST /v1/generations`, `POST /v1/sites`, `POST /v1/sites/{id}/domains`, `POST /v1/sites/{id}/configs`, `POST /v1/sites/{id}/configs/{ref}/publish`, `POST /v1/scans`) so a retry never creates a second copy. `PUT` and `DELETE` are idempotent and need none.

## 3. Verified API routes (v0.9)

### Step 1 — Free CheckMyDPDP scan (ask user permission before sending their URL)

Ask first: _"I can run a free CheckMyDPDP scan of `<url>`. It sends the URL to checkmydpdp.com (run by PolicyGrain). Proceed?"_

| Method & Path                 | Auth                                       | Purpose                                                                         |
| ----------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------- |
| `POST /v1/scans`              | None (3/IP/day) or Bearer (50/account/day) | Queue a 3-pass sandbox scan (`{"url": "https://example.in"}`) → `202` with `id` |
| `GET /v1/scans/{id}`          | None (capability ID)                       | Poll every `poll_after_ms` until `completed` or `couldnt_check`                 |
| `POST /v1/scans/{id}/handoff` | Bearer                                     | Issue a 24h single-use handoff link (`policygrain.com/start?handoff=...`)       |
| `POST /v1/handoffs/redeem`    | Bearer (same account)                      | Consume handoff token (`{"token": "..."}`) and get `agent_inferred` suggestions |

Report scan outcomes factually: `seen` (with evidence, register rows, settledness, commencement date), `not_seen`, or `couldnt_check` (never "clean" or "pass"). Quote `explanation.text` when present; if `null`, display `"Explanation pending approval"`. A server without a scanning sandbox answers `503 scanner_unavailable`: say the scan couldn't run, and carry on from the site's code.

### Step 2 — Identity & keys

| Method & Path             | Auth                  | Purpose                                                   |
| ------------------------- | --------------------- | --------------------------------------------------------- |
| `POST /v1/keys`           | None / Bearer         | Create a scoped API key (`pgk_...`, shown once)           |
| `GET /v1/keys`            | Bearer (`keys` scope) | List active and revoked keys (prefixes only)              |
| `POST /v1/keys/{id}/keep` | Session               | Unsuspend a pre-claim key after account claim             |
| `DELETE /v1/keys/{id}`    | Bearer (`keys` scope) | Revoke a key immediately                                  |
| `GET /v1/account`         | Bearer                | Inspect account state, key scopes, and email verification |

### Step 3 — Questions, profiles, document generation & hosted publication

| Method & Path                           | Auth   | Purpose                                                                                     |
| --------------------------------------- | ------ | ------------------------------------------------------------------------------------------- |
| `GET /v1/questions`                     | None   | Fetch the versioned question spine, field rules, and corpus metadata                        |
| `GET /v1/profiles`                      | Bearer | List business answer profiles                                                               |
| `POST /v1/profiles`                     | Bearer | Create a profile (`{"answers": {...}, "fields": {...}}`)                                    |
| `GET /v1/profiles/{id}`                 | Bearer | Read one profile; `unconfirmed` lists what the owner still has to confirm                   |
| `PATCH /v1/profiles/{id}`               | Bearer | Update answers/fields (`{"answers": {...}, "fields": {...}}`); `null` removes a value       |
| `POST /v1/generations`                  | Bearer | Start an async document generation run (`{"profile_id": "..."}`)                            |
| `GET /v1/generations/{id}`              | Bearer | Poll generation status (`queued` → `running` → `done` \| `failed`)                          |
| `GET /v1/documents?profile_id=...`      | Bearer | List generated documents, their `state` (`draft`/`final`) and `waiting_on`                  |
| `GET /v1/documents/{id}`                | Bearer | Read document summary                                                                       |
| `GET /v1/documents/{id}/versions/{n}`   | Bearer | Fetch rendered version (`n` or `latest`; JSON, or `?format=html\|md`) with provenance       |
| `GET /v1/documents/{id}/publication`    | Bearer | Read current hosted publication status on `pages.policygrain.com`                           |
| `PUT /v1/documents/{id}/publication`    | Bearer | Publish the newest version of a `final` document (`{"slug": "acme-privacy"}` on first only) |
| `DELETE /v1/documents/{id}/publication` | Bearer | Unpublish and purge hosted page                                                             |

How to fill a profile from a codebase:

1. Read `GET /v1/questions`. Choice questions (`single`, `multi`, `yes_no`) go in `answers` as an option `value`, an array of values, or `"yes"`/`"no"`. Text questions are answered through the fields listed in their `fills` (for example M-01 fills `org.legal_name` and `org.website`), never in `answers`. `required_fields` lists the fields every set needs.
2. Plain values sent with an API key are stored as `agent_inferred`. Send `{"value": "...", "source": "owner"}` only for a value the owner gave you in their own words; the key id is recorded as the one asserting it.
3. `POST /v1/generations`, then poll. A run can be `done` while some documents are blocked: each entry in `documents` has an `outcome` (`new_version`, `unchanged`, `blocked`) and `problems` with a `target` (question or field id) and a `fix`. `PATCH` the missing answers or fields and generate again; new targets can appear once earlier ones are answered.
4. Documents built on `agent_inferred` values stay `draft` (`draft_reasons: ["unconfirmed_answers"]`) and can be downloaded but not published.

### Step 4 — Sites, domain verification, banner configs & live browser verification

| Method & Path                                                       | Auth                     | Purpose                                                                                                                          |
| ------------------------------------------------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| `GET /v1/sites` / `POST /v1/sites`                                  | Bearer                   | List or register a site (`{"name": "Acme", "domains": ["acme.in"], "notice_profile_id": "..."}`)                                 |
| `GET /v1/sites/{id}` / `PATCH /v1/sites/{id}`                       | Bearer                   | Read site details (domains, challenges, `live_config_version`) or update `name`/`notice_profile_id`                              |
| `GET /v1/sites/{id}/domains` / `POST /v1/sites/{id}/domains`        | Bearer                   | List or add a domain (`{"domain": "www.acme.in"}`)                                                                               |
| `POST /v1/sites/{id}/domains/{domain}/verify`                       | Bearer                   | Verify ownership via the DNS TXT record or HTTPS well-known file in `verification`                                               |
| `DELETE /v1/sites/{id}/domains/{domain}`                            | Bearer                   | Remove a domain                                                                                                                  |
| `GET /v1/sites/{id}/configs` / `POST /v1/sites/{id}/configs`        | Bearer                   | List or create a draft banner config (`{"position": "bottom", "withdraw": "floating", "notice_url": "https://acme.in/privacy"}`) |
| `GET /v1/sites/{id}/configs/{ref}`                                  | Bearer                   | Read one banner config version (`live`, `latest`, or version number)                                                             |
| `POST /v1/sites/{id}/configs/{ref}/publish`                         | Bearer                   | Publish a banner configuration to `cdn.policygrain.com`                                                                          |
| `POST /v1/sites/{id}/verifications`                                 | Bearer                   | Trigger a live 3-pass browser sandbox check on a verified domain (`{"url": "https://acme.in/"}`, optional)                       |
| `GET /v1/sites/{id}/verifications` / `GET /v1/verifications/{id}`   | Bearer                   | Read verification signals and evidence                                                                                           |
| `GET /v1/verifications/{id}/diff`                                   | Bearer                   | Compare a verification with the previous one                                                                                     |
| `POST /v1/receipts`                                                 | Public (site origin)     | Ingest signed browser consent receipts (the banner sends these itself)                                                           |
| `GET /v1/sites/{id}/receipts` / `GET /v1/sites/{id}/consent-events` | Bearer (`evidence:read`) | Read stored consent receipts and events                                                                                          |

Banner config fields: `position` (default `bottom`), `withdraw` (`floating` adds a button; `footer_link` means you place an element with `data-pg-open`), `notice_url`, `colors` (`#rrggbb` values), `material_change`. The config's purposes and wording come from the site's notice profile; `config.purposes[].id` are the ids the snippet uses. Publishing a config is refused (`409 config_not_publishable`) while that profile has unconfirmed `agent_inferred` answers.

### Step 5 — Install the consent banner snippet

Put the loader first in `<head>`, before any analytics or marketing tag, with the site's `id` from `POST /v1/sites`:

```html
<script src="https://cdn.policygrain.com/b/v1/loader.js" data-pg-site="SITE_ID"></script>

<!-- Optional scripts stay inert until the visitor grants every purpose they name -->
<script
  type="text/plain"
  data-pg-purpose="analytics"
  src="https://www.googletagmanager.com/gtag/js?id=G-XXXX"
  async
></script>
<script type="text/plain" data-pg-purpose="advertising">
  /* Meta Pixel init */
</script>

<!-- Embeds show a click-to-load placeholder until their purpose is granted -->
<iframe
  data-pg-purpose="marketing"
  data-pg-src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
  title="Product video"
></iframe>

<!-- Reopens the preferences (needed when withdraw is footer_link) -->
<button type="button" data-pg-open>Privacy choices</button>
```

- `data-pg-purpose` takes purpose ids from the published config (`analytics`, `marketing`, `advertising`, `personalisation`, …), space-separated when a script needs several. Strictly necessary scripts (payments, security) stay untagged.
- Add `data-pg-api="https://..."` to the loader only when the API is not `https://api.policygrain.com`. `data-pg-type="module"` restores a module script's type.
- Next.js App Router: write plain `<script>` elements in the root `app/layout.tsx` `<head>` (inline code via `dangerouslySetInnerHTML`), not `next/script`, so the tags are in the server-rendered HTML as written.
- The banner shows once a config is published and serves from the CDN; until then the gated scripts simply stay off.

## 4. Guardrails for coding agents

1. **Human confirmation before finalisation:** Never silently confirm `agent_inferred` answers on behalf of a business owner. Present every inferred answer, marked as inferred, and tell the owner to sign in at policygrain.com and confirm them: only a signed-in owner can send `PATCH /v1/profiles/{id}` with `confirm` (a key gets `403 confirm_needs_person`). Publish (`PUT /v1/documents/{id}/publication`, `POST /v1/sites/{id}/configs/{ref}/publish`) only after the owner has confirmed and asked you to.
2. **Respect error `fix` fields:** Every non-2xx API error returns `{code, message, field?, fix}`. Read `fix` before retrying; obey `Retry-After` on `429` or `503`.
3. **Never touch `.env` or commit secrets:** Read `POLICYGRAIN_API_KEY` from the process environment only.
4. **Honest reporting:** Report factual evidence, statutory citations, settledness, and commencement dates — never invent legal text or claim legal review.
