airlock-rls-mcp 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,11 +4,33 @@
4
4
 
5
5
  The engine is [Airlock RLS](https://github.com/mateuszingano/airlock-rls) (`npm i airlock-rls`), the CI gate for Supabase RLS. This package is a thin MCP wrapper around it.
6
6
 
7
- ## Two tools
7
+ ## Ten tools
8
+
9
+ ### Local (no account needed)
8
10
 
9
11
  **`scan_site_for_exposed_key`** — give it a deployed URL. It reads the page and its JS bundles for an exposed Supabase `service_role` key (a `service_role` JWT or an `sb_secret_...` key). No database, no credentials, just the public URL. A hit means anyone who reads it bypasses **every** RLS policy. It never prints the full key.
10
12
 
11
- **`audit_supabase_rls`** — give it a Postgres connection string. It fails on RLS-off tables, permissive (always-true) policies, and anon/authenticated tenant leaks. It reads **only** catalog metadata (`pg_tables`, `pg_policies`, grants), never your row data, so a read-only role is enough.
13
+ **`audit_supabase_rls`** — give it a Postgres connection string. It fails on RLS-off tables, permissive (always-true) policies, and anon/authenticated tenant leaks. It reads **only** catalog metadata (`pg_tables`, `pg_policies`, grants), never your row data, so a read-only role is enough. Returns a human-readable summary.
14
+
15
+ **`get_findings`** — same audit as `audit_supabase_rls`, but returns machine-readable structured JSON: findings grouped by severity, severity counts, table count, allowed (waived) findings, and stats. Built for agents that need to iterate over findings, generate fixes, or build reports programmatically.
16
+
17
+ **`explain_finding`** — pure lookup, no database needed. Give it a finding `kind` string (e.g. `rls_disabled`, `permissive_true`, `cross_tenant_read_leak`) and it returns: what it means, why it's dangerous, how to fix it with example SQL, and related finding kinds. Use after `get_findings` or `audit_supabase_rls` to understand a finding before fixing it.
18
+
19
+ **`generate_fix`** — pure function, no database needed. Give it a finding `kind`, a `table_name`, and optionally a `policy_name`, and it returns the exact SQL to fix that specific finding, ready to paste into a migration file.
20
+
21
+ ### Hosted Monitor (needs an API key)
22
+
23
+ These tools talk to the [Airlock Monitor](https://shipsealed.com) REST API. Get an API key from the Monitor dashboard.
24
+
25
+ **`list_monitor_projects`** — list the Supabase projects connected to your Monitor account.
26
+
27
+ **`start_monitor_run`** — start an RLS audit + DAST run on a connected project. Returns a run id to poll.
28
+
29
+ **`get_monitor_run`** — check the status of a run (queued → running → completed/failed).
30
+
31
+ **`get_monitor_findings`** — get the findings (leaks, warnings, suggested SQL fixes) from a completed run.
32
+
33
+ **`get_monitor_attestation`** — download the signed attestation (Ed25519 + SHA-256) for a completed run. Anyone can verify it at shipsealed.com/verify without an account.
12
34
 
13
35
  ## Add it to your MCP client
14
36
 
@@ -29,7 +51,7 @@ That's the same block for Cursor (`~/.cursor/mcp.json`), Claude Desktop (`claude
29
51
  claude mcp add airlock -- npx -y airlock-rls-mcp
30
52
  ```
31
53
 
32
- Then ask the agent things like *"scan https://myapp.com for an exposed Supabase key"* or *"audit the RLS on this database"* and it calls the tools.
54
+ Then ask the agent things like *"scan https://myapp.com for an exposed Supabase key"*, *"audit the RLS on this database"*, *"explain the rls_disabled finding"*, *"generate the fix for permissive_true on my profiles table"*, or *"run a Monitor check on my project and show the findings"* and it calls the tools.
33
55
 
34
56
  ## Requirements
35
57
 
@@ -39,7 +61,7 @@ Node.js 18 or newer.
39
61
 
40
62
  ```bash
41
63
  npm install
42
- npm run smoke # starts the server and checks both tools are advertised
64
+ npm run smoke # starts the server and checks all tools are advertised
43
65
  ```
44
66
 
45
67
  ## More
package/index.mjs CHANGED
@@ -4,8 +4,8 @@
4
4
  // One dependency (airlock-rls, the engine). Speaks MCP's JSON-RPC 2.0 over stdio
5
5
  // (newline-delimited) directly, so it starts instantly inside an agent.
6
6
  //
7
- // Two tools an agent (Cursor, Claude Code, any MCP client) can call while it is
8
- // building a Supabase app:
7
+ // Five local tools an agent (Cursor, Claude Code, any MCP client) can call while
8
+ // it is building a Supabase app:
9
9
  //
10
10
  // 1. scan_site_for_exposed_key — point it at a DEPLOYED URL. Reads the page
11
11
  // and its JS bundles for a Supabase service_role key shipped to the
@@ -17,11 +17,24 @@
17
17
  // anon/authenticated tenant leaks. Reads only catalog metadata
18
18
  // (pg_tables, pg_policies, grants) — never your row data.
19
19
  //
20
+ // 3. get_findings — like audit_supabase_rls but returns machine-readable
21
+ // structured JSON (severity counts, grouped findings) instead of a
22
+ // human-readable summary. Built for programmatic consumption.
23
+ //
24
+ // 4. explain_finding — pure lookup: given a finding kind (e.g. 'rls_disabled'),
25
+ // returns what it means, why it's dangerous, the fix pattern with example
26
+ // SQL, and related findings. No database connection needed.
27
+ //
28
+ // 5. generate_fix — pure function: given a finding kind, table name, and
29
+ // optional policy name, returns the exact SQL to fix that specific finding.
30
+ // No database connection needed.
31
+ //
20
32
  // The heavy lifting is the published Airlock engine (npm: airlock-rls). This file
21
33
  // is only the MCP wrapper.
22
34
 
23
35
  import { audit } from 'airlock-rls'
24
36
  import { scanSiteForServiceRole } from 'airlock-rls/service-role'
37
+ import { MONITOR_TOOLS, callMonitorTool } from './monitor.mjs'
25
38
 
26
39
  const SERVER_INFO = { name: 'airlock-mcp', version: '0.1.1' }
27
40
  const PROTOCOL_VERSION = '2025-06-18'
@@ -106,6 +119,101 @@ const TOOLS = [
106
119
  required: ['db_url'],
107
120
  },
108
121
  },
122
+ {
123
+ name: 'get_findings',
124
+ description:
125
+ "Audit a Supabase/Postgres database's Row Level Security and return " +
126
+ 'machine-readable structured JSON. Unlike audit_supabase_rls (which ' +
127
+ 'returns a human-readable summary), this tool returns findings grouped ' +
128
+ 'by severity with counts, suitable for programmatic consumption by an ' +
129
+ 'agent that needs to iterate over findings, generate fixes, or build a ' +
130
+ 'report. Same engine, same checks, different output shape.',
131
+ inputSchema: {
132
+ type: 'object',
133
+ properties: {
134
+ db_url: {
135
+ type: 'string',
136
+ description:
137
+ 'Postgres connection string for the project to audit (e.g. ' +
138
+ 'postgresql://... — a read-only role is enough).',
139
+ },
140
+ schema: {
141
+ type: 'string',
142
+ description: 'Schema to audit (default: public).',
143
+ default: 'public',
144
+ },
145
+ allow: {
146
+ type: 'array',
147
+ items: { type: 'string' },
148
+ description:
149
+ 'Policy names that are intentionally permissive. Prefer the qualified form "table.policy".',
150
+ },
151
+ },
152
+ required: ['db_url'],
153
+ },
154
+ },
155
+ {
156
+ name: 'explain_finding',
157
+ description:
158
+ 'Explain what an Airlock finding kind means, why it is dangerous, how to ' +
159
+ 'fix it (with example SQL), and which other findings are related. Pure ' +
160
+ 'lookup — no database connection needed. Use this after get_findings or ' +
161
+ 'audit_supabase_rls to understand a specific finding before fixing it. ' +
162
+ 'Supported kinds: rls_disabled, permissive_true, anon_unscoped, ' +
163
+ 'authenticated_unscoped, write_unchecked, write_unscoped, ' +
164
+ 'update_using_unscoped, or_branch_unscoped, helper_scoped, ' +
165
+ 'security_definer, anon_executes_definer, definer_search_path_mutable, ' +
166
+ 'view_bypasses_rls, matview_exposed, public_bucket, realtime_exposure, ' +
167
+ 'cross_tenant_read_leak, cross_tenant_write_leak, ' +
168
+ 'cross_tenant_delete_leak, bypassrls_role, owner_bypasses_rls.',
169
+ inputSchema: {
170
+ type: 'object',
171
+ properties: {
172
+ finding_kind: {
173
+ type: 'string',
174
+ description:
175
+ "The finding kind string from an audit result (e.g. 'rls_disabled', " +
176
+ "'permissive_true', 'cross_tenant_read_leak').",
177
+ },
178
+ },
179
+ required: ['finding_kind'],
180
+ },
181
+ },
182
+ {
183
+ name: 'generate_fix',
184
+ description:
185
+ 'Generate the exact SQL to fix a specific Airlock finding. Pure function — ' +
186
+ 'no database connection needed. Returns a ready-to-run SQL statement ' +
187
+ 'tailored to the table and policy names you provide. Use after ' +
188
+ 'get_findings or audit_supabase_rls to get a fix you can paste into a ' +
189
+ 'migration file.',
190
+ inputSchema: {
191
+ type: 'object',
192
+ properties: {
193
+ finding_kind: {
194
+ type: 'string',
195
+ description:
196
+ "The finding kind to fix (e.g. 'rls_disabled', 'permissive_true').",
197
+ },
198
+ table_name: {
199
+ type: 'string',
200
+ description: 'The table the finding applies to (e.g. "profiles").',
201
+ },
202
+ policy_name: {
203
+ type: 'string',
204
+ description:
205
+ 'The policy name, if the finding is about a specific policy. ' +
206
+ 'Not needed for table-level findings like rls_disabled.',
207
+ },
208
+ schema: {
209
+ type: 'string',
210
+ description: 'Schema the table lives in (default: public).',
211
+ default: 'public',
212
+ },
213
+ },
214
+ required: ['finding_kind', 'table_name'],
215
+ },
216
+ },
109
217
  ]
110
218
 
111
219
  function summarize(findings) {
@@ -167,10 +275,524 @@ async function handleAuditRls(args) {
167
275
  }
168
276
  }
169
277
 
278
+ // ── Finding knowledge base (pure data, no DB) ──────────────────────────────
279
+
280
+ const FINDING_KNOWLEDGE = {
281
+ rls_disabled: {
282
+ title: 'RLS Disabled',
283
+ severity: 'fail',
284
+ what: 'The table has Row Level Security turned off. Every row is exposed to any API role (anon, authenticated) through PostgREST/Supabase.',
285
+ why: 'Without RLS, the Supabase anon key (public, in every browser bundle) gives full read/write to every row. This is the most common vibe-coding leak.',
286
+ fix: 'Enable RLS and add at least one policy.',
287
+ example_sql: (table, _policy, schema) =>
288
+ `ALTER TABLE "${schema}"."${table}" ENABLE ROW LEVEL SECURITY;\n\n` +
289
+ `-- Then add a policy, e.g. restrict reads to the row owner:\n` +
290
+ `CREATE POLICY "owner_read" ON "${schema}"."${table}"\n` +
291
+ ` FOR SELECT USING (auth.uid() = user_id);`,
292
+ related: ['permissive_true', 'anon_unscoped'],
293
+ },
294
+ permissive_true: {
295
+ title: 'Permissive USING(true) or WITH CHECK(true)',
296
+ severity: 'fail',
297
+ what: 'A policy uses USING(true) or WITH CHECK(true), making it always pass. RLS is on but the policy does not filter anything.',
298
+ why: 'USING(true) means every row is visible. WITH CHECK(true) means any row can be written, including rows belonging to other users. It is RLS in name only.',
299
+ fix: 'Replace the tautology with a real scope that ties the row to the caller.',
300
+ example_sql: (table, policy, schema) =>
301
+ policy
302
+ ? `-- Drop the permissive policy and replace it:\n` +
303
+ `DROP POLICY "${policy}" ON "${schema}"."${table}";\n\n` +
304
+ `CREATE POLICY "${policy}" ON "${schema}"."${table}"\n` +
305
+ ` FOR SELECT USING (auth.uid() = user_id);`
306
+ : `-- Replace USING(true) with a real scope:\n` +
307
+ `-- Example: restrict to the row owner\n` +
308
+ `CREATE POLICY "owner_only" ON "${schema}"."${table}"\n` +
309
+ ` USING (auth.uid() = user_id)\n` +
310
+ ` WITH CHECK (auth.uid() = user_id);`,
311
+ related: ['rls_disabled', 'anon_unscoped', 'write_unscoped'],
312
+ },
313
+ anon_unscoped: {
314
+ title: 'Anonymous Read Without Scoping',
315
+ severity: 'fail',
316
+ what: 'The anon role can read rows without the policy scoping to a specific user. The USING clause does not reference auth.uid() or equivalent.',
317
+ why: 'Anyone with the public anon key (in the browser) reads every row. If the table holds user data, it is a full data breach.',
318
+ fix: 'Scope the USING clause to the caller, or revoke SELECT from anon if the table should not be publicly readable.',
319
+ example_sql: (table, policy, schema) =>
320
+ policy
321
+ ? `DROP POLICY "${policy}" ON "${schema}"."${table}";\n\n` +
322
+ `CREATE POLICY "${policy}" ON "${schema}"."${table}"\n` +
323
+ ` FOR SELECT TO anon\n` +
324
+ ` USING (auth.uid() = user_id);`
325
+ : `-- Option A: scope to the caller\n` +
326
+ `CREATE POLICY "anon_scoped" ON "${schema}"."${table}"\n` +
327
+ ` FOR SELECT TO anon\n` +
328
+ ` USING (auth.uid() = user_id);\n\n` +
329
+ `-- Option B: revoke anon access entirely\n` +
330
+ `REVOKE SELECT ON "${schema}"."${table}" FROM anon;`,
331
+ related: ['permissive_true', 'authenticated_unscoped', 'cross_tenant_read_leak'],
332
+ },
333
+ authenticated_unscoped: {
334
+ title: 'Authenticated Read Without Scoping (Cross-Tenant)',
335
+ severity: 'fail',
336
+ what: 'Any logged-in user can read all rows — the policy does not scope to auth.uid(). This is a cross-tenant / IDOR leak.',
337
+ why: 'User A can read user B\'s data. In a multi-tenant app, every tenant sees every other tenant\'s rows.',
338
+ fix: 'Add auth.uid() scoping to the USING clause.',
339
+ example_sql: (table, policy, schema) =>
340
+ policy
341
+ ? `DROP POLICY "${policy}" ON "${schema}"."${table}";\n\n` +
342
+ `CREATE POLICY "${policy}" ON "${schema}"."${table}"\n` +
343
+ ` FOR SELECT TO authenticated\n` +
344
+ ` USING (auth.uid() = user_id);`
345
+ : `CREATE POLICY "tenant_read" ON "${schema}"."${table}"\n` +
346
+ ` FOR SELECT TO authenticated\n` +
347
+ ` USING (auth.uid() = user_id);`,
348
+ related: ['anon_unscoped', 'permissive_true', 'cross_tenant_read_leak'],
349
+ },
350
+ write_unchecked: {
351
+ title: 'Write Without WITH CHECK',
352
+ severity: 'warn',
353
+ what: 'An INSERT or UPDATE policy has no WITH CHECK clause and the USING clause does not scope to the caller. Writes are not tied to a tenant.',
354
+ why: 'A user can insert or update rows attributed to another user. The row "owner" field can be set to anyone.',
355
+ fix: 'Add a WITH CHECK clause that ties the written row to the caller.',
356
+ example_sql: (table, policy, schema) =>
357
+ policy
358
+ ? `DROP POLICY "${policy}" ON "${schema}"."${table}";\n\n` +
359
+ `CREATE POLICY "${policy}" ON "${schema}"."${table}"\n` +
360
+ ` FOR INSERT TO authenticated\n` +
361
+ ` WITH CHECK (auth.uid() = user_id);`
362
+ : `CREATE POLICY "write_scoped" ON "${schema}"."${table}"\n` +
363
+ ` FOR INSERT TO authenticated\n` +
364
+ ` WITH CHECK (auth.uid() = user_id);`,
365
+ related: ['write_unscoped', 'permissive_true'],
366
+ },
367
+ write_unscoped: {
368
+ title: 'Write WITH CHECK Not Scoped to Caller',
369
+ severity: 'fail',
370
+ what: 'The WITH CHECK clause exists but does not tie the row to the caller (no auth.uid() comparison). A user can forge rows as another tenant.',
371
+ why: 'Cross-tenant write: user A inserts or updates a row setting the owner to user B.',
372
+ fix: 'Rewrite WITH CHECK to include auth.uid() = user_id (or your tenant column).',
373
+ example_sql: (table, policy, schema) =>
374
+ policy
375
+ ? `DROP POLICY "${policy}" ON "${schema}"."${table}";\n\n` +
376
+ `CREATE POLICY "${policy}" ON "${schema}"."${table}"\n` +
377
+ ` FOR INSERT TO authenticated\n` +
378
+ ` WITH CHECK (auth.uid() = user_id);`
379
+ : `CREATE POLICY "write_owned" ON "${schema}"."${table}"\n` +
380
+ ` FOR ALL TO authenticated\n` +
381
+ ` USING (auth.uid() = user_id)\n` +
382
+ ` WITH CHECK (auth.uid() = user_id);`,
383
+ related: ['write_unchecked', 'permissive_true', 'cross_tenant_write_leak'],
384
+ },
385
+ update_using_unscoped: {
386
+ title: 'UPDATE USING Not Scoped (Row Takeover)',
387
+ severity: 'fail',
388
+ what: 'An UPDATE policy\'s USING clause does not scope to the caller. A user can overwrite any row, including rows belonging to other tenants.',
389
+ why: 'Row takeover: user A can UPDATE user B\'s row, changing its contents or re-assigning its ownership. This destroys data and is irreversible.',
390
+ fix: 'Scope the USING clause to auth.uid() so a user can only update their own rows.',
391
+ example_sql: (table, policy, schema) =>
392
+ policy
393
+ ? `DROP POLICY "${policy}" ON "${schema}"."${table}";\n\n` +
394
+ `CREATE POLICY "${policy}" ON "${schema}"."${table}"\n` +
395
+ ` FOR UPDATE TO authenticated\n` +
396
+ ` USING (auth.uid() = user_id)\n` +
397
+ ` WITH CHECK (auth.uid() = user_id);`
398
+ : `CREATE POLICY "update_own" ON "${schema}"."${table}"\n` +
399
+ ` FOR UPDATE TO authenticated\n` +
400
+ ` USING (auth.uid() = user_id)\n` +
401
+ ` WITH CHECK (auth.uid() = user_id);`,
402
+ related: ['write_unscoped', 'cross_tenant_write_leak'],
403
+ },
404
+ or_branch_unscoped: {
405
+ title: 'OR Branch Widens Access',
406
+ severity: 'warn',
407
+ what: 'The policy is scoped by auth.uid() but an OR branch widens it (e.g. "auth.uid() = user_id OR is_public"). The OR may let unscoped rows through.',
408
+ why: 'An OR branch that does not restrict to the caller can leak rows to any user. "auth.uid() = user_id OR status = \'published\'" exposes all published rows to everyone.',
409
+ fix: 'Prove the OR branch restricts to the caller, or split into two policies (one scoped, one for public rows on a separate allow-listed table).',
410
+ example_sql: (table, policy, schema) =>
411
+ `-- Option A: remove the OR and use a separate policy for public rows\n` +
412
+ `DROP POLICY "${policy || 'read_policy'}" ON "${schema}"."${table}";\n\n` +
413
+ `CREATE POLICY "owner_read" ON "${schema}"."${table}"\n` +
414
+ ` FOR SELECT TO authenticated\n` +
415
+ ` USING (auth.uid() = user_id);\n\n` +
416
+ `CREATE POLICY "public_read" ON "${schema}"."${table}"\n` +
417
+ ` FOR SELECT TO authenticated\n` +
418
+ ` USING (is_public = true);`,
419
+ related: ['anon_unscoped', 'authenticated_unscoped'],
420
+ },
421
+ helper_scoped: {
422
+ title: 'Scoped Through Helper Function',
423
+ severity: 'warn',
424
+ what: 'The policy delegates scoping to a helper function. A static scan cannot see inside it to verify it actually restricts to the caller.',
425
+ why: 'If the helper function does not check auth.uid() internally, the policy is effectively unscoped. Static analysis cannot prove this either way.',
426
+ fix: 'Verify the helper function restricts to the caller. If it does, add the policy to the allow list. If not, rewrite it to check auth.uid().',
427
+ example_sql: (table, policy, schema) =>
428
+ `-- Verify the helper function, then allow-list if intentional:\n` +
429
+ `-- airlock audit --allow "${table}.${policy || 'policy_name'}"\n\n` +
430
+ `-- Or rewrite the policy to use auth.uid() directly:\n` +
431
+ `DROP POLICY "${policy || 'policy_name'}" ON "${schema}"."${table}";\n\n` +
432
+ `CREATE POLICY "${policy || 'policy_name'}" ON "${schema}"."${table}"\n` +
433
+ ` FOR SELECT USING (auth.uid() = user_id);`,
434
+ related: ['anon_unscoped', 'authenticated_unscoped', 'security_definer'],
435
+ },
436
+ security_definer: {
437
+ title: 'SECURITY DEFINER Function',
438
+ severity: 'warn',
439
+ what: 'A function is marked SECURITY DEFINER, meaning it runs as its owner (usually postgres) and bypasses RLS.',
440
+ why: 'If any API-reachable role can call this function, it can read/write data that RLS would otherwise block. Legitimate for RLS helpers and triggers, but dangerous if it does data mutations.',
441
+ fix: 'Review who can call it. Revoke EXECUTE from public/anon if not needed. Pin its search_path.',
442
+ example_sql: (table, _policy, schema) =>
443
+ `-- Revoke from public (stops anon and authenticated):\n` +
444
+ `REVOKE EXECUTE ON FUNCTION "${schema}"."${table}" FROM PUBLIC;\n\n` +
445
+ `-- Pin search_path to prevent hijacking:\n` +
446
+ `ALTER FUNCTION "${schema}"."${table}" SET search_path = '';`,
447
+ related: ['anon_executes_definer', 'definer_search_path_mutable'],
448
+ },
449
+ anon_executes_definer: {
450
+ title: 'Anonymous Can Execute SECURITY DEFINER',
451
+ severity: 'warn',
452
+ what: 'The anon role can EXECUTE a SECURITY DEFINER function. It runs as the function owner, bypassing RLS.',
453
+ why: 'An unauthenticated user (anyone with the public anon key) can call a function that runs with elevated privileges. If the function reads or mutates data, it is a privilege escalation.',
454
+ fix: 'Revoke EXECUTE from anon (and from PUBLIC, which includes anon).',
455
+ example_sql: (table, _policy, schema) =>
456
+ `REVOKE EXECUTE ON FUNCTION "${schema}"."${table}" FROM PUBLIC;\n` +
457
+ `REVOKE EXECUTE ON FUNCTION "${schema}"."${table}" FROM anon;`,
458
+ related: ['security_definer', 'definer_search_path_mutable'],
459
+ },
460
+ definer_search_path_mutable: {
461
+ title: 'SECURITY DEFINER Without Pinned search_path',
462
+ severity: 'warn',
463
+ what: 'A SECURITY DEFINER function does not pin its search_path. It resolves unqualified names against the caller\'s search_path.',
464
+ why: 'A privilege escalation path: an attacker sets search_path to a schema containing a malicious function with the same name as one the DEFINER calls, hijacking execution with owner privileges.',
465
+ fix: 'Pin the search_path on the function.',
466
+ example_sql: (table, _policy, schema) =>
467
+ `ALTER FUNCTION "${schema}"."${table}" SET search_path = '';`,
468
+ related: ['security_definer', 'anon_executes_definer'],
469
+ },
470
+ view_bypasses_rls: {
471
+ title: 'View Bypasses RLS',
472
+ severity: 'warn',
473
+ what: 'A view runs as its owner (security_invoker is off). It can bypass RLS on the tables it reads.',
474
+ why: 'If anon or authenticated can SELECT from this view, they see rows the underlying table policies would block. The view owner (usually postgres) is not subject to RLS.',
475
+ fix: 'Set security_invoker = on so the view runs as the querying role, or restrict access.',
476
+ example_sql: (table, _policy, schema) =>
477
+ `ALTER VIEW "${schema}"."${table}" SET (security_invoker = on);`,
478
+ related: ['matview_exposed', 'security_definer'],
479
+ },
480
+ matview_exposed: {
481
+ title: 'Materialized View Exposed',
482
+ severity: 'fail',
483
+ what: 'A materialized view is accessible to anon or authenticated. RLS does not apply to materialized views — every row it holds is exposed.',
484
+ why: 'Materialized views are not subject to RLS. If they contain user data and an API role can SELECT from them, it is a full data leak.',
485
+ fix: 'Revoke SELECT from anon/authenticated, or move the matview to a schema PostgREST does not expose.',
486
+ example_sql: (table, _policy, schema) =>
487
+ `REVOKE SELECT ON "${schema}"."${table}" FROM anon;\n` +
488
+ `REVOKE SELECT ON "${schema}"."${table}" FROM authenticated;`,
489
+ related: ['view_bypasses_rls', 'rls_disabled'],
490
+ },
491
+ public_bucket: {
492
+ title: 'Public Storage Bucket',
493
+ severity: 'warn',
494
+ what: 'A Supabase Storage bucket is marked public. Anyone with the URL can read its files.',
495
+ why: 'Files in a public bucket are accessible without authentication. If it holds private user uploads, it is a data leak.',
496
+ fix: 'Set the bucket to private, or confirm it is intentionally public (e.g. avatars, marketing assets).',
497
+ example_sql: (table) =>
498
+ `-- Make the bucket private:\n` +
499
+ `UPDATE storage.buckets SET public = false WHERE id = '${table}';\n\n` +
500
+ `-- Or allow-list if intentional:\n` +
501
+ `-- airlock audit --allow "storage.${table}"`,
502
+ related: ['anon_unscoped'],
503
+ },
504
+ realtime_exposure: {
505
+ title: 'Realtime Streams Anon-Readable Table',
506
+ severity: 'warn',
507
+ what: 'A table published to Supabase Realtime is also anon-readable. Its row changes stream to anonymous subscribers.',
508
+ why: 'Anonymous WebSocket subscribers receive every INSERT, UPDATE, DELETE on this table in real time — including rows that belong to other users.',
509
+ fix: 'Restrict Realtime to authenticated users, or remove the table from the Realtime publication.',
510
+ example_sql: (table) =>
511
+ `-- Remove from the Realtime publication:\n` +
512
+ `ALTER PUBLICATION supabase_realtime DROP TABLE "${table}";\n\n` +
513
+ `-- Or restrict anon access:\n` +
514
+ `REVOKE SELECT ON "${table}" FROM anon;`,
515
+ related: ['anon_unscoped', 'public_bucket'],
516
+ },
517
+ cross_tenant_read_leak: {
518
+ title: 'Cross-Tenant Read Leak (DAST-Proven)',
519
+ severity: 'fail',
520
+ what: 'Dynamic Application Security Testing (DAST) proved that user B can read user A\'s rows. This is not a static guess — the attack succeeded.',
521
+ why: 'An actual cross-tenant read was executed and confirmed. User B retrieved rows belonging to user A through the Supabase API.',
522
+ fix: 'Add or fix the RLS policy to scope SELECT to auth.uid().',
523
+ example_sql: (table, _policy, schema) =>
524
+ `-- Ensure RLS is enabled:\n` +
525
+ `ALTER TABLE "${schema}"."${table}" ENABLE ROW LEVEL SECURITY;\n\n` +
526
+ `-- Add a scoped read policy:\n` +
527
+ `CREATE POLICY "tenant_read" ON "${schema}"."${table}"\n` +
528
+ ` FOR SELECT TO authenticated\n` +
529
+ ` USING (auth.uid() = user_id);`,
530
+ related: ['anon_unscoped', 'authenticated_unscoped', 'cross_tenant_write_leak'],
531
+ },
532
+ cross_tenant_write_leak: {
533
+ title: 'Cross-Tenant Write Leak (DAST-Proven)',
534
+ severity: 'fail',
535
+ what: 'DAST proved that user B can insert or update rows as user A. The attack succeeded — this is confirmed, not theoretical.',
536
+ why: 'User B modified or created rows attributed to user A. Data integrity is broken.',
537
+ fix: 'Add or fix the RLS policy to scope INSERT/UPDATE to auth.uid() in both USING and WITH CHECK.',
538
+ example_sql: (table, _policy, schema) =>
539
+ `ALTER TABLE "${schema}"."${table}" ENABLE ROW LEVEL SECURITY;\n\n` +
540
+ `CREATE POLICY "tenant_write" ON "${schema}"."${table}"\n` +
541
+ ` FOR ALL TO authenticated\n` +
542
+ ` USING (auth.uid() = user_id)\n` +
543
+ ` WITH CHECK (auth.uid() = user_id);`,
544
+ related: ['write_unscoped', 'write_unchecked', 'cross_tenant_read_leak', 'cross_tenant_delete_leak'],
545
+ },
546
+ cross_tenant_delete_leak: {
547
+ title: 'Cross-Tenant Delete Leak (DAST-Proven)',
548
+ severity: 'fail',
549
+ what: 'DAST proved that user B can delete user A\'s rows. The attack succeeded.',
550
+ why: 'User B deleted rows belonging to user A. Data loss is confirmed and irreversible.',
551
+ fix: 'Add or fix the RLS policy to scope DELETE to auth.uid().',
552
+ example_sql: (table, _policy, schema) =>
553
+ `ALTER TABLE "${schema}"."${table}" ENABLE ROW LEVEL SECURITY;\n\n` +
554
+ `CREATE POLICY "tenant_delete" ON "${schema}"."${table}"\n` +
555
+ ` FOR DELETE TO authenticated\n` +
556
+ ` USING (auth.uid() = user_id);`,
557
+ related: ['cross_tenant_write_leak', 'cross_tenant_read_leak'],
558
+ },
559
+ cross_tenant_discrepancy: {
560
+ title: 'Cross-Tenant Discrepancy (Static Missed, DAST Caught)',
561
+ severity: 'fail',
562
+ what: 'DAST proved a cross-tenant leak that the static analysis did NOT flag. The policy text looked safe but the attack succeeded.',
563
+ why: 'This is the worst case: the static checker said "clean" but the real database is leaking. The policy qualifier may use a function or construct that fools static analysis.',
564
+ fix: 'Investigate why static analysis missed it. The DAST result is ground truth — fix the policy.',
565
+ example_sql: (table, _policy, schema) =>
566
+ `-- The static checker missed this — review the actual policy:\n` +
567
+ `SELECT * FROM pg_policies WHERE tablename = '${table}' AND schemaname = '${schema}';\n\n` +
568
+ `-- Then fix it:\n` +
569
+ `ALTER TABLE "${schema}"."${table}" ENABLE ROW LEVEL SECURITY;\n\n` +
570
+ `CREATE POLICY "tenant_scoped" ON "${schema}"."${table}"\n` +
571
+ ` FOR ALL TO authenticated\n` +
572
+ ` USING (auth.uid() = user_id)\n` +
573
+ ` WITH CHECK (auth.uid() = user_id);`,
574
+ related: ['cross_tenant_read_leak', 'cross_tenant_write_leak', 'helper_scoped'],
575
+ },
576
+ bypassrls_role: {
577
+ title: 'Non-Managed Role With BYPASSRLS',
578
+ severity: 'warn',
579
+ what: 'A database role outside the standard Supabase-managed set has the BYPASSRLS privilege.',
580
+ why: 'If this role is reachable through the API (via SET ROLE or a function), it bypasses all RLS policies.',
581
+ fix: 'Remove BYPASSRLS from the role, or confirm it is intentional and not API-reachable.',
582
+ example_sql: (table) =>
583
+ `ALTER ROLE "${table}" NOBYPASSRLS;`,
584
+ related: ['owner_bypasses_rls', 'security_definer'],
585
+ },
586
+ owner_bypasses_rls: {
587
+ title: 'Table Owner Bypasses RLS',
588
+ severity: 'warn',
589
+ what: 'The table owner is a role the API can reach, and FORCE ROW LEVEL SECURITY is not set. The owner bypasses RLS.',
590
+ why: 'If the API can reach the owner role (via SET ROLE), RLS policies do not apply — the owner sees and writes all rows.',
591
+ fix: 'Force RLS on the table owner, or reassign the table to a non-API-reachable role.',
592
+ example_sql: (table, _policy, schema) =>
593
+ `ALTER TABLE "${schema}"."${table}" FORCE ROW LEVEL SECURITY;`,
594
+ related: ['bypassrls_role', 'rls_disabled'],
595
+ },
596
+ nothing_audited: {
597
+ title: 'Nothing Audited',
598
+ severity: 'fail',
599
+ what: 'No tables or policies were found in the specified schema. The audit checked nothing.',
600
+ why: 'Either the schema is empty, the connection role cannot see the tables, or the schema name is wrong.',
601
+ fix: 'Verify the schema name and the connection role\'s privileges.',
602
+ example_sql: (table, _policy, schema) =>
603
+ `-- Check what tables exist:\n` +
604
+ `SELECT tablename FROM pg_tables WHERE schemaname = '${schema}';\n\n` +
605
+ `-- Check grants:\n` +
606
+ `SELECT grantee, privilege_type FROM information_schema.table_privileges\n` +
607
+ ` WHERE table_schema = '${schema}';`,
608
+ related: [],
609
+ },
610
+ check_skipped: {
611
+ title: 'Check Skipped (Insufficient Access)',
612
+ severity: 'warn',
613
+ what: 'A check did not run because the audit role lacks read access to the required catalog tables.',
614
+ why: 'The result for this check is UNKNOWN, not clean. A missing check is not a passing check.',
615
+ fix: 'Grant the audit role read access to the relevant catalog, or re-run with a more privileged role.',
616
+ example_sql: () =>
617
+ `-- Grant read access to the storage schema (example):\n` +
618
+ `GRANT USAGE ON SCHEMA storage TO your_audit_role;\n` +
619
+ `GRANT SELECT ON storage.buckets TO your_audit_role;`,
620
+ related: [],
621
+ },
622
+ allow_unused: {
623
+ title: 'Allow-List Entry Unused',
624
+ severity: 'warn',
625
+ what: 'An --allow entry matched nothing in this audit. The object was renamed, dropped, or never existed.',
626
+ why: 'A waiver that applies to nothing is not protecting anything. It may hide a real finding on a renamed table.',
627
+ fix: 'Remove the entry or fix its spelling.',
628
+ example_sql: () => `-- No SQL fix — remove the stale --allow entry from your config.`,
629
+ related: ['allow_ambiguous'],
630
+ },
631
+ allow_ambiguous: {
632
+ title: 'Allow-List Entry Ambiguous',
633
+ severity: 'warn',
634
+ what: 'An --allow entry matches multiple tables. It was NOT applied because it is ambiguous.',
635
+ why: 'A bare policy name that matches in two tables would silently waive both. Use the qualified "table.policy" form.',
636
+ fix: 'Qualify the allow entry, e.g. --allow "users.read_all".',
637
+ example_sql: () => `-- No SQL fix — qualify the --allow entry in your config.`,
638
+ related: ['allow_unused'],
639
+ },
640
+ }
641
+
642
+ // Strip the storage_ prefix for lookup — storage findings reuse the base kind
643
+ function normalizeFindingKind(kind) {
644
+ return kind.replace(/^storage_/, '')
645
+ }
646
+
647
+ // ── New tool handlers ───────────────────────────────────────────────────────
648
+
649
+ async function handleGetFindings(args) {
650
+ const dbUrl = args?.db_url
651
+ if (!dbUrl || typeof dbUrl !== 'string') {
652
+ throw new Error('db_url is required (a Postgres connection string).')
653
+ }
654
+ const schema = typeof args?.schema === 'string' && args.schema ? args.schema : 'public'
655
+ const allow = Array.isArray(args?.allow) ? args.allow : []
656
+ const result = await audit({ dbUrl, schema, allow })
657
+ const { findings, allowed, problems, warnings, passed, tables, stats } = result
658
+ const { fails, warns } = summarize(findings)
659
+ return {
660
+ content: [
661
+ {
662
+ type: 'text',
663
+ text: JSON.stringify(
664
+ {
665
+ schema,
666
+ passed,
667
+ problems,
668
+ warnings,
669
+ table_count: tables?.length ?? 0,
670
+ severity_counts: { fail: fails.length, warn: warns.length },
671
+ findings,
672
+ allowed,
673
+ stats: stats || null,
674
+ },
675
+ null,
676
+ 2,
677
+ ),
678
+ },
679
+ ],
680
+ structuredContent: {
681
+ schema,
682
+ passed,
683
+ problems,
684
+ warnings,
685
+ table_count: tables?.length ?? 0,
686
+ severity_counts: { fail: fails.length, warn: warns.length },
687
+ findings,
688
+ allowed,
689
+ stats: stats || null,
690
+ },
691
+ isError: false,
692
+ }
693
+ }
694
+
695
+ function handleExplainFinding(args) {
696
+ const kind = args?.finding_kind
697
+ if (!kind || typeof kind !== 'string') {
698
+ throw new Error('finding_kind is required (e.g. "rls_disabled", "permissive_true").')
699
+ }
700
+ const normalized = normalizeFindingKind(kind)
701
+ const entry = FINDING_KNOWLEDGE[normalized]
702
+ if (!entry) {
703
+ const known = Object.keys(FINDING_KNOWLEDGE).join(', ')
704
+ throw new Error(`Unknown finding kind: "${kind}". Known kinds: ${known}`)
705
+ }
706
+ const isStorage = kind.startsWith('storage_') && kind !== normalized
707
+ const explanation = {
708
+ kind,
709
+ title: isStorage ? `Storage: ${entry.title}` : entry.title,
710
+ default_severity: entry.severity,
711
+ what: entry.what,
712
+ why_dangerous: entry.why,
713
+ how_to_fix: entry.fix,
714
+ example_sql: entry.example_sql('your_table', 'your_policy', 'public'),
715
+ related_findings: entry.related,
716
+ }
717
+ const text = [
718
+ `## ${explanation.title}`,
719
+ `**Kind:** ${kind}`,
720
+ `**Default severity:** ${entry.severity}`,
721
+ '',
722
+ `### What it means`,
723
+ entry.what,
724
+ '',
725
+ `### Why it's dangerous`,
726
+ entry.why,
727
+ '',
728
+ `### How to fix`,
729
+ entry.fix,
730
+ '',
731
+ `### Example SQL`,
732
+ '```sql',
733
+ explanation.example_sql,
734
+ '```',
735
+ '',
736
+ entry.related.length
737
+ ? `### Related findings\n${entry.related.join(', ')}`
738
+ : '',
739
+ ]
740
+ .filter(Boolean)
741
+ .join('\n')
742
+ return {
743
+ content: [{ type: 'text', text }],
744
+ structuredContent: explanation,
745
+ isError: false,
746
+ }
747
+ }
748
+
749
+ function handleGenerateFix(args) {
750
+ const kind = args?.finding_kind
751
+ const table = args?.table_name
752
+ if (!kind || typeof kind !== 'string') {
753
+ throw new Error('finding_kind is required (e.g. "rls_disabled", "permissive_true").')
754
+ }
755
+ if (!table || typeof table !== 'string') {
756
+ throw new Error('table_name is required (the table the finding applies to).')
757
+ }
758
+ const policy = typeof args?.policy_name === 'string' ? args.policy_name : null
759
+ const schema = typeof args?.schema === 'string' && args.schema ? args.schema : 'public'
760
+ const normalized = normalizeFindingKind(kind)
761
+ const entry = FINDING_KNOWLEDGE[normalized]
762
+ if (!entry) {
763
+ const known = Object.keys(FINDING_KNOWLEDGE).join(', ')
764
+ throw new Error(`Unknown finding kind: "${kind}". Known kinds: ${known}`)
765
+ }
766
+ const sql = entry.example_sql(table, policy, schema)
767
+ const text = [
768
+ `-- Fix for ${kind} on ${schema}.${table}${policy ? ` (policy: ${policy})` : ''}`,
769
+ `-- ${entry.fix}`,
770
+ '',
771
+ sql,
772
+ ].join('\n')
773
+ return {
774
+ content: [{ type: 'text', text }],
775
+ structuredContent: {
776
+ kind,
777
+ table: table,
778
+ policy: policy || null,
779
+ schema,
780
+ sql,
781
+ description: entry.fix,
782
+ },
783
+ isError: false,
784
+ }
785
+ }
786
+
170
787
  async function callTool(name, args) {
171
788
  try {
172
789
  if (name === 'scan_site_for_exposed_key') return await handleScanSite(args)
173
790
  if (name === 'audit_supabase_rls') return await handleAuditRls(args)
791
+ if (name === 'get_findings') return await handleGetFindings(args)
792
+ if (name === 'explain_finding') return handleExplainFinding(args)
793
+ if (name === 'generate_fix') return handleGenerateFix(args)
794
+ const monitorResult = await callMonitorTool(name, args)
795
+ if (monitorResult) return monitorResult
174
796
  throw new Error(`Unknown tool: ${name}`)
175
797
  } catch (err) {
176
798
  return {
@@ -202,7 +824,7 @@ async function handle(msg) {
202
824
  },
203
825
  }
204
826
  case 'tools/list':
205
- return { jsonrpc: '2.0', id, result: { tools: TOOLS } }
827
+ return { jsonrpc: '2.0', id, result: { tools: [...TOOLS, ...MONITOR_TOOLS] } }
206
828
  case 'tools/call': {
207
829
  const result = await callTool(params?.name, params?.arguments || {})
208
830
  return { jsonrpc: '2.0', id, result }
@@ -248,4 +870,4 @@ process.stdin.on('data', (chunk) => {
248
870
  })
249
871
  process.stdin.on('end', () => process.exit(0))
250
872
 
251
- console.error('airlock-mcp running (stdio, zero-dep). Tools: scan_site_for_exposed_key, audit_supabase_rls')
873
+ console.error('airlock-mcp running (stdio). Tools: scan_site_for_exposed_key, audit_supabase_rls, get_findings, explain_finding, generate_fix, list_monitor_projects, start_monitor_run, get_monitor_run, get_monitor_findings, get_monitor_attestation')
package/monitor.mjs ADDED
@@ -0,0 +1,248 @@
1
+ // Airlock Monitor — hosted API tools for the MCP server.
2
+ //
3
+ // These tools talk to the Airlock Monitor REST API (future). They let an AI
4
+ // coding agent list projects, trigger runs, read findings and download signed
5
+ // attestations without leaving the editor.
6
+ //
7
+ // The API routes are designed but NOT yet deployed — this module is the
8
+ // client-side contract so the MCP wrapper is ready when the server ships.
9
+
10
+ const DEFAULT_BASE = 'https://app.shipsealed.com'
11
+
12
+ async function apiCall(method, path, { apiKey, baseUrl, body } = {}) {
13
+ const base = (baseUrl || DEFAULT_BASE).replace(/\/$/, '')
14
+ const url = `${base}${path}`
15
+ const headers = {
16
+ Authorization: `Bearer ${apiKey}`,
17
+ 'Content-Type': 'application/json',
18
+ }
19
+ const res = await fetch(url, {
20
+ method,
21
+ headers,
22
+ ...(body ? { body: JSON.stringify(body) } : {}),
23
+ })
24
+ const text = await res.text()
25
+ let data
26
+ try {
27
+ data = JSON.parse(text)
28
+ } catch {
29
+ data = { raw: text }
30
+ }
31
+ if (!res.ok) {
32
+ const msg = data?.error || data?.message || `HTTP ${res.status}`
33
+ throw new Error(`Monitor API ${method} ${path} → ${msg}`)
34
+ }
35
+ return data
36
+ }
37
+
38
+ // ── Tool definitions (MCP schema) ───────────────────────────────────────────
39
+
40
+ const API_KEY_PROP = {
41
+ type: 'string',
42
+ description: 'Airlock Monitor API key (starts with amk_).',
43
+ }
44
+ const BASE_URL_PROP = {
45
+ type: 'string',
46
+ description: `Base URL of the Monitor instance (default: ${DEFAULT_BASE}).`,
47
+ }
48
+
49
+ export const MONITOR_TOOLS = [
50
+ {
51
+ name: 'list_monitor_projects',
52
+ description:
53
+ 'List the Supabase projects connected to your Airlock Monitor account. ' +
54
+ 'Returns project id, label, and last-run timestamp for each.',
55
+ inputSchema: {
56
+ type: 'object',
57
+ properties: {
58
+ api_key: API_KEY_PROP,
59
+ base_url: BASE_URL_PROP,
60
+ },
61
+ required: ['api_key'],
62
+ },
63
+ },
64
+ {
65
+ name: 'start_monitor_run',
66
+ description:
67
+ 'Start an Airlock Monitor run (RLS audit + DAST) on a connected project. ' +
68
+ 'Returns the run id and initial status. Poll with get_monitor_run.',
69
+ inputSchema: {
70
+ type: 'object',
71
+ properties: {
72
+ api_key: API_KEY_PROP,
73
+ project_id: {
74
+ type: 'string',
75
+ description: 'The project id to run against (from list_monitor_projects).',
76
+ },
77
+ base_url: BASE_URL_PROP,
78
+ },
79
+ required: ['api_key', 'project_id'],
80
+ },
81
+ },
82
+ {
83
+ name: 'get_monitor_run',
84
+ description:
85
+ 'Get the status and summary of an Airlock Monitor run. ' +
86
+ 'Status is one of: queued, running, completed, failed.',
87
+ inputSchema: {
88
+ type: 'object',
89
+ properties: {
90
+ api_key: API_KEY_PROP,
91
+ run_id: {
92
+ type: 'string',
93
+ description: 'The run id (from start_monitor_run).',
94
+ },
95
+ base_url: BASE_URL_PROP,
96
+ },
97
+ required: ['api_key', 'run_id'],
98
+ },
99
+ },
100
+ {
101
+ name: 'get_monitor_findings',
102
+ description:
103
+ 'Get the findings (leaks, warnings) from a completed Airlock Monitor run. ' +
104
+ 'Each finding has kind, severity, object, detail and a suggested SQL fix.',
105
+ inputSchema: {
106
+ type: 'object',
107
+ properties: {
108
+ api_key: API_KEY_PROP,
109
+ run_id: {
110
+ type: 'string',
111
+ description: 'The run id of a completed run.',
112
+ },
113
+ base_url: BASE_URL_PROP,
114
+ },
115
+ required: ['api_key', 'run_id'],
116
+ },
117
+ },
118
+ {
119
+ name: 'get_monitor_attestation',
120
+ description:
121
+ 'Download the signed attestation (Ed25519) for a completed run. ' +
122
+ 'Returns the canonical JSON report, its SHA-256 hash, and the signature. ' +
123
+ 'Anyone can verify it at shipsealed.com/verify without an account.',
124
+ inputSchema: {
125
+ type: 'object',
126
+ properties: {
127
+ api_key: API_KEY_PROP,
128
+ run_id: {
129
+ type: 'string',
130
+ description: 'The run id of a completed run.',
131
+ },
132
+ base_url: BASE_URL_PROP,
133
+ },
134
+ required: ['api_key', 'run_id'],
135
+ },
136
+ },
137
+ ]
138
+
139
+ // ── Handlers ────────────────────────────────────────────────────────────────
140
+
141
+ async function handleListProjects(args) {
142
+ const data = await apiCall('GET', '/api/v1/projects', {
143
+ apiKey: args.api_key,
144
+ baseUrl: args.base_url,
145
+ })
146
+ const projects = Array.isArray(data) ? data : data.projects || []
147
+ const lines = projects.length
148
+ ? projects.map((p) => `• ${p.label || p.id} (id: ${p.id}, last run: ${p.last_run_at || 'never'})`).join('\n')
149
+ : 'No projects connected. Add one at the Monitor dashboard.'
150
+ return {
151
+ content: [{ type: 'text', text: `${projects.length} project(s):\n\n${lines}` }],
152
+ structuredContent: { projects },
153
+ }
154
+ }
155
+
156
+ async function handleStartRun(args) {
157
+ const data = await apiCall('POST', '/api/v1/runs', {
158
+ apiKey: args.api_key,
159
+ baseUrl: args.base_url,
160
+ body: { project_id: args.project_id },
161
+ })
162
+ return {
163
+ content: [
164
+ {
165
+ type: 'text',
166
+ text: `Run started: ${data.id || data.run_id}\nStatus: ${data.status || 'queued'}\n\nPoll with get_monitor_run to check progress.`,
167
+ },
168
+ ],
169
+ structuredContent: data,
170
+ }
171
+ }
172
+
173
+ async function handleGetRun(args) {
174
+ const data = await apiCall('GET', `/api/v1/runs/${encodeURIComponent(args.run_id)}`, {
175
+ apiKey: args.api_key,
176
+ baseUrl: args.base_url,
177
+ })
178
+ const status = data.status || 'unknown'
179
+ const summary =
180
+ status === 'completed'
181
+ ? `Completed: ${data.problems ?? '?'} problem(s), ${data.warnings ?? '?'} warning(s). ${data.passed ? 'PASSED' : 'FAILED'}.`
182
+ : `Status: ${status}`
183
+ return {
184
+ content: [{ type: 'text', text: summary }],
185
+ structuredContent: data,
186
+ }
187
+ }
188
+
189
+ async function handleGetFindings(args) {
190
+ const data = await apiCall('GET', `/api/v1/runs/${encodeURIComponent(args.run_id)}/findings`, {
191
+ apiKey: args.api_key,
192
+ baseUrl: args.base_url,
193
+ })
194
+ const findings = Array.isArray(data) ? data : data.findings || []
195
+ const fails = findings.filter((f) => f.severity === 'fail')
196
+ const warns = findings.filter((f) => f.severity === 'warn')
197
+ const lines = []
198
+ if (fails.length) {
199
+ lines.push(`✗ ${fails.length} problem(s):`)
200
+ for (const f of fails) lines.push(` ✗ [${f.kind}] ${f.object} — ${f.detail}`)
201
+ }
202
+ if (warns.length) {
203
+ lines.push(`! ${warns.length} warning(s):`)
204
+ for (const f of warns) lines.push(` ! [${f.kind}] ${f.object} — ${f.detail}`)
205
+ }
206
+ if (!fails.length && !warns.length) lines.push('✓ No findings — sealed.')
207
+ return {
208
+ content: [{ type: 'text', text: lines.join('\n') }],
209
+ structuredContent: { findings },
210
+ }
211
+ }
212
+
213
+ async function handleGetAttestation(args) {
214
+ const data = await apiCall('GET', `/api/v1/runs/${encodeURIComponent(args.run_id)}/attestation`, {
215
+ apiKey: args.api_key,
216
+ baseUrl: args.base_url,
217
+ })
218
+ const lines = [
219
+ `Airlock Attestation — Run ${args.run_id}`,
220
+ '',
221
+ `SHA-256: ${data.sha256 || '(not yet signed)'}`,
222
+ `Ed25519 signature: ${data.signature || '(unsigned)'}`,
223
+ '',
224
+ data.verify_url ? `Verify: ${data.verify_url}` : 'Verify at shipsealed.com/verify',
225
+ ]
226
+ return {
227
+ content: [{ type: 'text', text: lines.join('\n') }],
228
+ structuredContent: data,
229
+ }
230
+ }
231
+
232
+ export async function callMonitorTool(name, args) {
233
+ if (!args?.api_key) throw new Error('api_key is required for Monitor tools.')
234
+ switch (name) {
235
+ case 'list_monitor_projects':
236
+ return await handleListProjects(args)
237
+ case 'start_monitor_run':
238
+ return await handleStartRun(args)
239
+ case 'get_monitor_run':
240
+ return await handleGetRun(args)
241
+ case 'get_monitor_findings':
242
+ return await handleGetFindings(args)
243
+ case 'get_monitor_attestation':
244
+ return await handleGetAttestation(args)
245
+ default:
246
+ return null
247
+ }
248
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "airlock-rls-mcp",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "mcpName": "io.github.mateuszingano/airlock-rls-mcp",
5
5
  "description": "MCP server for Airlock — let an AI coding agent (Cursor, Claude) scan a deployed site for an exposed Supabase service_role key and audit Row Level Security, mid-build. Catches the #1 vibe-coding leak.",
6
6
  "type": "module",
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "files": [
19
19
  "index.mjs",
20
+ "monitor.mjs",
20
21
  "README.md",
21
22
  "LICENSE",
22
23
  "server.json"
package/server.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://static.modelcontextprotocol.io/schemas/2025-09-29/server.schema.json",
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
3
  "name": "io.github.mateuszingano/airlock-rls-mcp",
4
4
  "title": "Airlock RLS",
5
5
  "description": "Scan a deployed site for an exposed Supabase service_role key and audit Row Level Security.",
@@ -8,13 +8,13 @@
8
8
  "source": "github"
9
9
  },
10
10
  "websiteUrl": "https://shipsealed.com/?utm_source=mcp-registry&utm_medium=referral&utm_campaign=airlock-rls-mcp",
11
- "version": "0.1.1",
11
+ "version": "0.1.3",
12
12
  "packages": [
13
13
  {
14
14
  "registryType": "npm",
15
15
  "registryBaseUrl": "https://registry.npmjs.org",
16
16
  "identifier": "airlock-rls-mcp",
17
- "version": "0.1.1",
17
+ "version": "0.1.3",
18
18
  "transport": { "type": "stdio" }
19
19
  }
20
20
  ]