# pokayoke

> pokayoke reviews source code for security defects and returns a validated JSON envelope. Every finding carries its evidence, a verification record and a suggested fix.

## MCP server

- [MCP endpoint](https://pokayoke.sh/mcp): streamable HTTP JSON-RPC 2.0, one object per POST, with no session and no event stream; protocol revisions 2025-11-25, 2025-06-18, 2024-11-05. Send `Authorization: Bearer <api-key>`. A body is at most 1 MiB, a `tools/call` at most 1600 KiB, so a `code` or `diff` argument at its 512 KiB limit fits once JSON escapes it.
- [API keys](https://pokayoke.sh/dashboard): sign in and create the bearer key; it is shown once. The same key calls the HTTP API.
- [Server card](https://pokayoke.sh/.well-known/mcp/server-card.json): the server's name, version, transport and endpoint.
- `review_submit` (one of repo_url, code; optional ref, scope): Queue a security review of a repository URL (https or git@) or inline source text; this server never reads a path on the server, so a path or file: URL is refused as forbidden_target (upload an archive to POST /api/v1/reviews instead).
- `review_get` (one of job_id, review_id): Read one review, by the job_id review_submit or review_patch returned or by a review_id (from review_list, a report link, or a server scan the website started).
- `review_list` (optional page, sort, dir, scope, status): List the calling account’s reviews, queued and running ones included, with the review id, repository, status, trigger, commit, finding count and the fixes open on GitHub, 25 to a numbered page, sorted by any column (newest first by default).
- `finding_get` (review_id, finding_id): Read one finding from one finished review, by review_id and finding_id.
- `review_patch` (diff; optional repo_url): Review a unified diff without cloning anything. repo_url, when given, is the repository the diff targets and supplies its conventions.
- `server_scan` (host): Scan one live HTTP server for the four declared attack-chain contracts and return the pokeyoka-server/1 envelope: the fingerprint, every contract outcome with per-link evidence, and the findings.
- `review_events` (review_id; optional after): Read a review’s progress events (queued, cloning, hunting, verifying, done …) after a sequence number, and whether the review is done.
- `finding_list` (review_id): List the findings of one review: id, severity, verdict, tier, title, file, line, CWE, and, when the review’s envelope is still stored, the evidence and the full verification beside those summary fields, and notProvenHere: true on a finding carried from an earlier review whose proof was not run at this commit.
- `review_fix_prompt` (review_id; optional finding_id): Write a prompt for a coding agent that fixes a finished review’s findings with their full context: confirmed findings first, then unproven ones, never a refuted one, each with its severity, CWE, file:line, the vulnerable line, the evidence, who can reach it, the impact, the proof in plain words and the suggested fix diff with its status; then the instructions and the report link. finding_id narrows it to one finding.
- `account_get` (no arguments): Read the account behind the calling key: user, plan and its limits, the reviews left this month and when they reset, monitored repositories against the plan limit, the install, pricing and docs links, every open finding of the monitored repositories, how many exploits are proven and open, and how many fixes are open on GitHub with the link to them.
- `repository_list` (optional sort, dir): List the repositories a linked GitHub App installation covers or a review named: whether each is monitored (pushes and pull requests reviewed), its branch and head commit, its newest review with confirmed and unproven counts, open findings and pushes skipped this month; sorted by any column, the newest push first by default.
- `repository_monitor` (repo, monitored): Switch push and pull-request reviews of one installed repository on or off.
- `installation_list` (no arguments): List the GitHub App installations linked to the account, with the install link and the fixer App’s.
- `fix_list` (optional limit): List the fix pull requests and private advisories delivered to the account’s repositories, newest first.
- `billing_checkout` (optional plan, interval): Open a Stripe Checkout session for a paid plan (plan pro, the default, team or enterprise; interval month, the default, or year; where this server sells it) and return its link for the user to open in a browser; no payment happens in this call.
- `billing_portal` (no arguments): Open a Stripe billing portal session (invoices, payment method, cancel) and return its link for the user to open in a browser.
- `billing_credits` (no arguments): Open a Stripe Checkout session for one review pack, a one-time purchase of more manual reviews for the current UTC month (they expire at its end), and return its link for the user to open in a browser; no payment happens in this call.
- `api_key_list` (no arguments): List the account’s API keys by label and prefix, with when each was created, last used and revoked.
- `api_key_revoke` (id): Revoke one of the account’s API keys by id (from api_key_list).
- `notifications_get` (no arguments): Read where the account’s exploit alerts go: one email per review that proves an exploit, to a verified address.
- `notifications_set` (optional email, enabled, min_severity): Change the account’s exploit alerts; every argument is optional and an absent one is kept.
- Left out on purpose, `api_key_create`: A new key would land in the agent’s transcript. Keys are created on the dashboard; an agent can list and revoke them.
- Left out on purpose, `archive upload`: MCP has no file transport. Upload an archive over HTTP: POST /api/v1/reviews as multipart/form-data with kind=upload and an archive file part.
- Not a tool: The dashboard’s own live poll; the account tools answer the same facts one resource at a time.
- Not a tool: account_get carries the same plan object (price, status, renewal) as its plan field.
- Not a tool: notifications_set mails the verification link; giving it the same waiting address again mails a fresh one.

## HTTP API

- [OpenAPI](https://pokayoke.sh/openapi.json): every endpoint below with its parameters, request bodies, response schemas and error codes. Paths are relative to https://pokayoke.sh.
- Authentication: send `Authorization: Bearer <api-key>` on every request. Without a valid key every path under `/api/v1` answers `401` with `WWW-Authenticate: Bearer`; the session cookie is never read.
- Bodies: JSON at most 1 MiB, but a review submission (`POST /api/v1/reviews`) at most 1600 KiB, so pasted `code` or a `diff` at its 512 KiB limit (UTF-8) fits once JSON escapes it. An archive upload is `multipart/form-data` with `kind=upload` and one `archive` file part (zip, tar or tar.gz) at most 25 MiB; an archive whose extraction exceeds 2000 files or 100 MiB is refused.
- Pages: the review list is 25 to a numbered page (`?page`, from 1), sorted by any column (`?sort`, `?dir`); another list takes `?limit` (default 20, at most 200). Every answer carries `Cache-Control: no-store`.
- Example: `POST /api/v1/reviews` with `{"kind":"repo","repo_url":"<clone-url>"}` answers `202` with `{"review_id":"<review-id>","status":"queued","report_url":"/r/<review-id>","events_url":"/r/<review-id>/events"}`. Poll `GET /api/v1/reviews/<review-id>` until `envelope` is set.
- `GET /api/v1/account`: The account behind the key: user, plan, usage and links.
- `GET /api/v1/reviews`: Reviews, queued and running included, each with its open fixes on GitHub, 25 to a numbered page: ?page (from 1; past the last, the last), ?sort (when, commit, repo, result, fixes, trigger, branch, took; when by default), ?dir (asc or desc; the column’s own by default), ?scope (all, or repositories: repository reviews with a commit), ?status.
- `POST /api/v1/reviews`: Queue a review: JSON {kind: repo|code|patch|server, ...}, or a multipart upload with kind=upload and an archive file part. Spends one unit of the monthly quota.
- `GET /api/v1/reviews/{id}`: One review, with its envelope once finished.
- `GET /api/v1/reviews/{id}/events`: A review’s progress events after ?after (a sequence number).
- `GET /api/v1/reviews/{id}/findings`: The findings of one review.
- `GET /api/v1/reviews/{id}/findings/{finding_id}`: One finding of one review.
- `GET /api/v1/reviews/{id}/prompt`: A prompt for a coding agent that fixes the review’s confirmed and unproven findings, with their full context, as the prompt field; ?finding for one finding. 202 with prompt null while the review is queued or running.
- `GET /api/v1/repositories`: Installed and reviewed repositories: monitoring, last review, open findings; with the monitored count and the plan limit. ?sort (repo, branch, head, result, monitoring, pushed; pushed, the newest push first, by default), ?dir (asc or desc; the column’s own by default); every tie by the name.
- `PUT /api/v1/repositories/{owner}/{name}/monitoring`: Switch push reviews of one repository on or off: JSON {monitored}. 409 limit_reached past the plan; 404 not_installed.
- `GET /api/v1/installations`: The linked GitHub App installations and the install links.
- `GET /api/v1/fixes`: Fix pull requests and advisories delivered to the account’s repositories; ?limit.
- `GET /api/v1/billing`: The plan, its price, status and renewal.
- `POST /api/v1/billing/checkout`: A Stripe Checkout link for a paid plan: JSON {plan, interval} or ?plan=&interval=; plan pro (the default), team or enterprise, interval month (the default) or year, where this deployment sells it. The quantity is the plan’s own. 409 already_subscribed on any paid plan; 400 invalid_args for an unknown field or a plan and interval not sold here; 503 billing_disabled.
- `POST /api/v1/billing/portal`: A Stripe billing portal link. 409 no_customer; 503 billing_disabled.
- `POST /api/v1/billing/credits`: A Stripe Checkout link for one review pack: more manual reviews, spent in the UTC month it is bought in, for any account, Free included. No body. 400 invalid_args where this deployment sells no pack; 503 billing_disabled.
- `GET /api/v1/keys`: The account’s API keys, without their secrets.
- `DELETE /api/v1/keys/{id}`: Revoke one API key (the calling key included).
- `GET /api/v1/notifications`: Exploit alerts: the verified address they go to, on or off, the least severity that sends one, and any address waiting for verification.
- `PUT /api/v1/notifications`: Change exploit alerts: JSON {email, enabled, min_severity}, each optional. A new address is mailed a verification link and receives alerts once it is opened; null or the sign-in address returns them to that address. 429 rate_limited past 5 links an account an hour, or 3 links an address a day across every account.
- `POST /api/v1/notifications/verify`: Mail a fresh verification link to the address waiting for one. 404 not_found when none waits; 429 rate_limited past 5 links an account an hour, or 3 links an address a day.
- Only on the site, create an API key: A key that could mint keys would survive its own revocation through the key it minted; keys are created on the dashboard, behind the session.
- Not an endpoint: The dashboard’s own live poll; the API answers the same facts one resource at a time (account, reviews, repositories, installations, fixes, keys).

## Errors

- [Error codes](https://pokayoke.sh/docs#errors): the HTTP API answers every refusal as `{"error":{"code","message"}}` at the status below; branch on the code, never on the message. Context rides beside the code: `upgrade_url` on `limit_reached` (it is null on Enterprise, a grant, with billing off, or where no larger plan is sold), `resets_at` on `quota_exhausted`, `retry_after_seconds` on `rate_limited`.
- `invalid_args` (400): A missing or unknown field, a bad value, or a target this server will not take.
- `unauthenticated` (401): No API key, or one that is unknown or revoked; the answer carries WWW-Authenticate: Bearer.
- `forbidden` (403): The key may not do this, or the target is not one this server will take: a private, loopback or local host, a scan host the account has not proven it owns, or a private repository no GitHub App installation linked to the account covers (reason: not_installed, with install_url).
- `forbidden_target` (403): A review target that names a path on this server: a directory, a local path or a file: URL. Review a clone URL, pasted code or an uploaded archive instead.
- `not_found` (404): No such review, finding, repository or key, or one this key may not read; an embargoed review answers exactly as a missing one.
- `method_not_allowed` (405): The path exists, but not for this method; the Allow header names the ones it takes.
- `limit_reached` (409): The plan monitors no more repositories; switch one off, or upgrade at upgrade_url when it is not null (it is null on Enterprise, a grant, with billing off, or where no larger plan is sold).
- `already_subscribed` (409): The account already pays for a plan, a grandfathered one included; switch plans in the billing portal instead.
- `no_customer` (409): The account has no billing history yet; open checkout first.
- `payload_too_large` (413): A JSON body over 1 MiB (a review submission over 1600 KiB), or an upload over 25 MiB.
- `unsupported_media_type` (415): The body is not application/json, or multipart/form-data for an upload.
- `quota_exhausted` (429): The account has used every review of its monthly quota, or (a free account, period: "day") every review of its daily limit; resets_at says when it refills.
- `rate_limited` (429): Too many server scans started recently; retry_after_seconds says how long to wait.
- `internal` (500): The server failed; the message says what, never where.
- `upstream_error` (502): GitHub or Stripe did not answer; try again.
- `billing_disabled` (503): Billing is not enabled on this deployment.
- An MCP tool that fails answers JSON-RPC `-32603` with `tool "<name>" failed: pokayoke-mcp: <code>: <detail>` as its message, where the code is one of `invalid_args`, `not_found`, `pending`, `forbidden_target`, `budget_exhausted`, `quota_exhausted`, `rate_limited`, `limit_reached`, `already_subscribed`, `no_customer`, `billing_disabled`, `not_configured`, `internal`. A missing or invalid key is HTTP `401` and a batch HTTP `400`, before any tool runs.

## Plans and limits

- [Pricing](https://pokayoke.sh/pricing): the plans, their limits and how to upgrade, signed in or out.
- Free (`free`): 3 monitored repositories and 100 reviews a month; 1 contributor on private repositories; no subscription.
- Pro (`pro`): 10 monitored repositories and 1000 reviews a month; 3 contributors included, each one past them billed per contributor; sold monthly or annually.
- Team (`team`): 40 monitored repositories and 5000 reviews a month; 10 contributors included, each one past them billed per contributor; sold monthly or annually.
- Enterprise (`enterprise`): unlimited monitored repositories and 20000 reviews a month; no contributor limit (fair use); sold monthly or annually.
- Contributors: a distinct GitHub user who pushed to, or opened a pull request on, a monitored private repository in the last 90 days. Bots, the fixer App's among them, never count, and neither does anything on a public repository. On Free only one contributor is reviewed, the account's linked GitHub user first, then the earliest seen: a push or pull request by anyone else is answered `204` with `X-Pokayoke-Skip: contributor limit`, is not reviewed, and is counted in that repository's `contributor_skipped_pushes`. Pro and Team are never blocked: the subscription bills each contributor past the plan's included number. Its quantity is the contributors used, at least 1, and the plan price covers the included ones; it rises when a new one arrives and falls as one ages out, with Stripe prorating the change. `usage.contributors` (`{used, included}`, `included` null where the plan does not count them) says where the account stands.
- Grandfathered: an account that existed before this plan catalog (`plan.grandfathered` true) has, on Free, Free's repository limit and no contributor limit. A subscriber on an earlier price keeps the terms it bought, as `legacy_pro`, labelled Pro (original price), or `legacy_max`, labelled Max (original price), never sold again: `plan.repo_limit` and `plan.review_quota` say what it allows, its contributors are not counted against it, and it switches plans in the billing portal.
- Free also has a daily limit: 5 reviews that run the models per UTC day, across the website, the HTTP API, the MCP tools and its pushes and pull requests. A pull request on its repository by an author without write access draws on its own allowance of the same size and never on the account's. A review answered by reuse of one already run, and a server scan, do not count. Past it a submission answers `429 quota_exhausted` with `period: "day"` and `resets_at` (the next 00:00 UTC), and a push or pull request is accepted and its review waits: its check stays open, and it runs after 00:00 UTC, the newest waiting commit of each branch or pull request only: an older one never runs: it carries `replaced: true` and `replaced_by` (the review that ran instead), keeps status `failed` for compatibility with an error beginning "Replaced by a newer push", and is not a failed review. Paid plans and grants have no daily limit.
- The calling account's own plan and usage: `GET /api/v1/account` or `account_get` (`plan.repo_limit`, `plan.review_quota`, `plan.interval`, `plan.grandfathered`, `usage.reviews`, `usage.monitored`, `usage.contributors`, and `usage.daily`: `{used, limit, resets_at, waiting, reached}`, the day's count against the daily limit, `limit` null where there is none). A review waiting for the daily limit carries `waiting_until` (the next 00:00 UTC; null otherwise) in the review list and on its repository's `latest_review`.
- A monitored repository is reviewed on every push and pull request. Switch one with `PUT /api/v1/repositories/{owner}/{name}/monitoring` or `repository_monitor`; past the plan's limit the switch answers `409 limit_reached` with `upgrade_url`; it is null on Enterprise, a grant, with billing off, or where no larger plan is sold: switch another off instead.
- A push or pull request on a repository that is not monitored is not reviewed: the GitHub webhook delivery is answered `204` with `X-Pokayoke-Skip: repository not monitored`, and `GET /api/v1/repositories` counts it in `skipped_pushes` for a repository switched off or paused. With billing off there is no repository limit: every repository a linked installation covers is reviewed unless it was switched off, and each repository record says `enforced: false`; `monitored` is always whether it is reviewed now.
- Each repository record carries its `branch` and `default_branch`, its `head` (`{sha, message, at}`: the default branch's newest push's commit and the first line of its message, or the commit of the default branch's newest review) and its `latest_review` (`{review_id, status, confirmed, proven, confirmed_by_reading, unproven, finished_at}`, the default branch's newest review); a push to another branch or a pull request never moves either, and a push to the default branch of a repository that is not monitored still moves its head.
- A confirmed finding is either proven, an exploit an executed run demonstrated, or confirmed by reading the code, which no run demonstrated: a review's `findings` and a repository's `latest_review` carry `confirmed` and its two parts, `proven` and `confirmed_by_reading`; an open finding carries `proven`, and the account's `open_exploits` counts only the proven ones. Each count is the review report's own: a hardening note an enforced closure holds is in none of them.
- A confirmed finding carried from an earlier review whose proof was not run at this commit carries `notProvenHere: true`: on the review's finding, from `GET /api/v1/reviews/{id}/findings/{finding_id}` or `finding_get`, and on its row from `GET /api/v1/reviews/{id}/findings` or `finding_list`. It keeps its stored verdict, tier and count, so `proven` still counts it, and the report counts it apart from the exploits proven at this commit. Every other finding and row carries no such key.
- A stored finding closes only on what a review established about the code, in one of three states: fixed (its stored proof no longer fires), no longer present (its code changed and the verifier no longer finds it) or code removed (its file is gone or its code can no longer be found); the last two are never called fixed, and a finding a review merely does not report again stays open. A review that closed one carries `closed` (`{fixed, no_longer_present, code_removed}`; absent when it closed nothing) inside `findings` on its record from `GET /api/v1/reviews` and `GET /api/v1/reviews/{id}`, and at the top level of a `review_list` row, whose `findings` is the count. A fix whose finding closed carries `resolved` (`{state, at, commit, review}`) in `GET /api/v1/fixes` or `fix_list`, where `commit` is the reviewed commit at which the site first observed the close, which may be later than the commit that made it. A fix that was never delivered (no pull request or advisory was opened) whose finding closed carries `resolved` too, with `state` `skipped` and a `reason` saying so, and is not delivered while the finding stays closed; a finding proven again takes `resolved` away and the fix reads, and is delivered, as before. A merged fix pull request is delivered once, ever, and its state stays `merged`; it carries `finding_open` (true only when the newest finished push review of the repository's default branch, of the merge or after it, lists the finding open; newest by the chain of pushes, else the push received later, so a review of an older commit that finished later is never the newest; false when that review does not list it or lists it closed, and when no review has finished since the merge), `finding_open_as_of` (that review's commit; null when not open) and `finding_open_proven` (true when that review proved it at that commit, false for one it confirmed by reading) in `GET /api/v1/fixes` or `fix_list`, read when the list is served; no other delivery carries them.
- One monthly review quota: a review started on the website, through `POST /api/v1/reviews` or by an MCP tool spends one, and the quota refills on the first of each UTC month. A review a push or pull request starts spends none of it (it does count against a free account's daily limit). Spent, a submission answers `429 quota_exhausted` with `resets_at`.
- Upgrading: `POST /api/v1/billing/checkout` (`billing_checkout`, `plan` pro, team or enterprise, pro by default, and `interval` month or year, month by default, where this deployment sells that plan at that interval) returns a Stripe Checkout link and `POST /api/v1/billing/portal` (`billing_portal`) a billing portal link, for a person to open in a browser; no payment happens over the API. An account that already pays for a plan, a grandfathered one included, gets `409 already_subscribed` and switches plans in the billing portal.

## Website routes

- [Submit a review](https://pokayoke.sh/submit): `POST` a JSON body `{"kind":"repo","repo_url":"<clone-url>"}` and read `{"id":"<review-id>"}` from the response. A form post answers `303` and redirects to the report. Pasted `code` (`kind=code`) is at most 512 KiB, in a body of at most 1600 KiB. A script holding a key uses `POST /api/v1/reviews` instead.
- Upload an archive: `POST` a `multipart/form-data` body with `kind=upload` and an `archive` file (zip, tar or tar.gz, at most 25 MiB compressed) and read `303` to the report. An archive whose extraction exceeds 2000 files or 100 MiB is refused.
- Read the report at `https://pokayoke.sh/r/<review-id>?format=json`: `202` while the review is queued or running, `200` with the `pokeyoka-review/1` envelope when it is complete.
- Fix it with a coding agent: `https://pokayoke.sh/r/<review-id>?format=prompt` (add `&finding=<finding-id>` for one finding) answers `text/plain`, a prompt with every confirmed and unproven finding's full context and the instructions; `202` while the review runs. `GET /api/v1/reviews/{id}/prompt` and `review_fix_prompt` return the same text.
- Follow progress at `https://pokayoke.sh/r/<review-id>/events`: `200` with the review's progress events; pass back `next_after` as `?after=` to read only newer ones.
- A GitHub-delivered review (a push or a pull request) of a public repository, or of one whose visibility is not known, answers only the key of the account that owns it over the HTTP API and over MCP, and on the site only that account and the repository's maintainers (GitHub write access); everyone else, signed out included, gets the `404` a missing id gets. An embargoed review (a push review of a public repository) is one of these.
- Exploit alerts: a review that proves an exploit emails its account once, at the address `GET /api/v1/notifications` names. The email's links take no key, and neither acts on a `GET`: `/api/v1/notifications/confirm?token=<token>` verifies a new address (`GET` asks, `POST` verifies, once, within 24 hours) and `/api/v1/notifications/off?token=<token>` switches alerts off (`GET` asks, `POST` acts). Both answer an HTML page for a person.

## Envelope schema

- [Envelope field reference](https://pokayoke.sh/docs#schema-title): `pokeyoka-review/1` for a repository review, `pokeyoka-server/1` for a live server scan.
- [Docs](https://pokayoke.sh/docs): the MCP and HTTP reference for this deployment, version 0.1.0.
