gatekeep-mcp 0.2.0__tar.gz

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.
Files changed (45) hide show
  1. gatekeep_mcp-0.2.0/LICENSE-APACHE +172 -0
  2. gatekeep_mcp-0.2.0/LICENSE-MIT +21 -0
  3. gatekeep_mcp-0.2.0/PKG-INFO +245 -0
  4. gatekeep_mcp-0.2.0/README.md +198 -0
  5. gatekeep_mcp-0.2.0/gatekeep/__init__.py +135 -0
  6. gatekeep_mcp-0.2.0/gatekeep/__main__.py +6 -0
  7. gatekeep_mcp-0.2.0/gatekeep/cli.py +5 -0
  8. gatekeep_mcp-0.2.0/gatekeep/control_plane.py +1043 -0
  9. gatekeep_mcp-0.2.0/gatekeep/decorator.py +137 -0
  10. gatekeep_mcp-0.2.0/gatekeep/gate.py +1816 -0
  11. gatekeep_mcp-0.2.0/gatekeep/ledger.py +1021 -0
  12. gatekeep_mcp-0.2.0/gatekeep/mcp/__init__.py +51 -0
  13. gatekeep_mcp-0.2.0/gatekeep/mcp/__main__.py +8 -0
  14. gatekeep_mcp-0.2.0/gatekeep/mcp/cli.py +603 -0
  15. gatekeep_mcp-0.2.0/gatekeep/mcp/http_server.py +1696 -0
  16. gatekeep_mcp-0.2.0/gatekeep/mcp/onboarding.py +583 -0
  17. gatekeep_mcp-0.2.0/gatekeep/mcp/proxy.py +1858 -0
  18. gatekeep_mcp-0.2.0/gatekeep/middleware.py +359 -0
  19. gatekeep_mcp-0.2.0/gatekeep/persistence.py +1688 -0
  20. gatekeep_mcp-0.2.0/gatekeep/policy.py +260 -0
  21. gatekeep_mcp-0.2.0/gatekeep/redaction.py +206 -0
  22. gatekeep_mcp-0.2.0/gatekeep/registry.py +314 -0
  23. gatekeep_mcp-0.2.0/gatekeep/saga.py +609 -0
  24. gatekeep_mcp-0.2.0/gatekeep/security.py +536 -0
  25. gatekeep_mcp-0.2.0/gatekeep_mcp.egg-info/PKG-INFO +245 -0
  26. gatekeep_mcp-0.2.0/gatekeep_mcp.egg-info/SOURCES.txt +43 -0
  27. gatekeep_mcp-0.2.0/gatekeep_mcp.egg-info/dependency_links.txt +1 -0
  28. gatekeep_mcp-0.2.0/gatekeep_mcp.egg-info/entry_points.txt +2 -0
  29. gatekeep_mcp-0.2.0/gatekeep_mcp.egg-info/requires.txt +24 -0
  30. gatekeep_mcp-0.2.0/gatekeep_mcp.egg-info/top_level.txt +1 -0
  31. gatekeep_mcp-0.2.0/pyproject.toml +87 -0
  32. gatekeep_mcp-0.2.0/setup.cfg +4 -0
  33. gatekeep_mcp-0.2.0/tests/test_compliance_hardening.py +751 -0
  34. gatekeep_mcp-0.2.0/tests/test_control_plane_mcp.py +450 -0
  35. gatekeep_mcp-0.2.0/tests/test_decorator.py +188 -0
  36. gatekeep_mcp-0.2.0/tests/test_false_positive_tuning.py +536 -0
  37. gatekeep_mcp-0.2.0/tests/test_ha_postgres_redis_integration.py +335 -0
  38. gatekeep_mcp-0.2.0/tests/test_http_gateway_postgres.py +664 -0
  39. gatekeep_mcp-0.2.0/tests/test_incident_commander_e2e.py +10 -0
  40. gatekeep_mcp-0.2.0/tests/test_multi_agent_gatekeep.py +152 -0
  41. gatekeep_mcp-0.2.0/tests/test_registry.py +369 -0
  42. gatekeep_mcp-0.2.0/tests/test_runtime_scaling.py +533 -0
  43. gatekeep_mcp-0.2.0/tests/test_saga.py +144 -0
  44. gatekeep_mcp-0.2.0/tests/test_security_hardening.py +727 -0
  45. gatekeep_mcp-0.2.0/tests/test_temporal_envoy_features.py +450 -0
@@ -0,0 +1,172 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Work; and
105
+
106
+ (d) If the Work includes a "NOTICE" file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a copy of the NOTICE file in a readable form with
109
+ all attribution notices from the NOTICE file, excluding those
110
+ notices that do not pertain to any part of the Work.
111
+
112
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
113
+ any Contribution intentionally submitted for inclusion in the Work
114
+ by You to the Licensor shall be under the terms and conditions of
115
+ this License, without any additional terms or conditions.
116
+ Notwithstanding the above, nothing herein shall supersede or modify
117
+ the terms of any separate license agreement you may have executed
118
+ with Licensor regarding such Contributions.
119
+
120
+ 6. Trademarks. This License does not grant permission to use the trade
121
+ names, trademarks, service marks, or product names of the Licensor,
122
+ except as required for reasonable and customary use in describing the
123
+ origin of the Work and reproducing the copyright notice.
124
+
125
+ 7. Disclaimer of Warranty. Unless required by applicable law or
126
+ agreed to in writing, Licensor provides the Work (and each
127
+ Contributor provides its Contributions) on an "AS IS" BASIS,
128
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
129
+ implied, including, without limitation, any warranties or conditions
130
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
131
+ PARTICULAR PURPOSE. You are solely responsible for determining the
132
+ appropriateness of using or redistributing the Work and assume any
133
+ risks associated with Your exercise of permissions under this License.
134
+
135
+ 8. Limitation of Liability. In no event and under no legal theory,
136
+ whether in tort (including negligence), contract, or otherwise,
137
+ unless required by applicable law (such as deliberate acts) or
138
+ agreed to in writing, shall any Contributor be liable to You for
139
+ damages, including any direct, indirect, special, incidental, or
140
+ consequential damages of any character arising as a result of this
141
+ License or out of the use or inability to use the Work (including
142
+ but not limited to damages for loss of goodwill, work stoppage,
143
+ computer failure or malfunction, or any and all other commercial
144
+ damages or losses), even if such Contributor has been advised of the
145
+ possibility of such damages.
146
+
147
+ 9. Accepting Warranty or Additional Liability. While redistributing
148
+ the Work or Derivative Works thereof, You may choose to offer,
149
+ and charge a fee for, acceptance of support, warranty, indemnity,
150
+ or other liability obligations and/or rights consistent with this
151
+ License. However, in accepting such obligations, You may act only
152
+ on Your own behalf and on Your sole responsibility, not on behalf
153
+ of any other Contributor, and only if You agree to indemnify,
154
+ defend, and hold each Contributor harmless for any liability
155
+ incurred by, or claims asserted against, such Contributor by reason
156
+ of your accepting any such warranty or additional liability.
157
+
158
+ END OF TERMS AND CONDITIONS
159
+
160
+ Copyright 2026 Gatekeep Contributors
161
+
162
+ Licensed under the Apache License, Version 2.0 (the "License");
163
+ you may not use this file except in compliance with the License.
164
+ You may obtain a copy of the License at
165
+
166
+ http://www.apache.org/licenses/LICENSE-2.0
167
+
168
+ Unless required by applicable law or agreed to in writing, software
169
+ distributed under the License is distributed on an "AS IS" BASIS,
170
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
171
+ See the License for the specific language governing permissions and
172
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gatekeep Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,245 @@
1
+ Metadata-Version: 2.4
2
+ Name: gatekeep-mcp
3
+ Version: 0.2.0
4
+ Summary: Zero-dependency sub-millisecond firewall and automatic Saga undo proxy for MCP AI agents
5
+ Author: Gatekeep Contributors
6
+ License: MIT OR Apache-2.0
7
+ Project-URL: Homepage, https://github.com/pavan-fulmamdikar/gatekeep-mcp
8
+ Project-URL: Repository, https://github.com/pavan-fulmamdikar/gatekeep-mcp
9
+ Project-URL: Issues, https://github.com/pavan-fulmamdikar/gatekeep-mcp/issues
10
+ Keywords: mcp,ai-agents,security-proxy,firewall,dlp,ssrf,saga,rollback,hitl,provenance,gatekeep
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Security
22
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE-APACHE
26
+ License-File: LICENSE-MIT
27
+ Provides-Extra: gateway
28
+ Requires-Dist: uvicorn>=0.27.0; extra == "gateway"
29
+ Requires-Dist: httpx>=0.26.0; extra == "gateway"
30
+ Provides-Extra: postgres
31
+ Requires-Dist: psycopg[binary]>=3.1.0; extra == "postgres"
32
+ Requires-Dist: psycopg-pool>=3.2.0; extra == "postgres"
33
+ Provides-Extra: redis
34
+ Requires-Dist: redis>=5.0.0; extra == "redis"
35
+ Provides-Extra: all
36
+ Requires-Dist: uvicorn>=0.27.0; extra == "all"
37
+ Requires-Dist: httpx>=0.26.0; extra == "all"
38
+ Requires-Dist: psycopg[binary]>=3.1.0; extra == "all"
39
+ Requires-Dist: psycopg-pool>=3.2.0; extra == "all"
40
+ Requires-Dist: redis>=5.0.0; extra == "all"
41
+ Provides-Extra: dev
42
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
43
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
44
+ Requires-Dist: httpx>=0.26.0; extra == "dev"
45
+ Requires-Dist: uvicorn>=0.27.0; extra == "dev"
46
+ Dynamic: license-file
47
+
48
+ <h1 align="center">Gatekeep</h1>
49
+
50
+ <p align="center">
51
+ <strong>Zero-dependency, sub-millisecond firewall &amp; automatic Saga undo proxy for MCP AI agents.</strong><br>
52
+ <em>Stop prompt-injected writes, secret exfiltration, SSRF, rug-pulled MCP servers, and half-finished DB mutations — with zero LLM judges and zero required third-party dependencies.</em>
53
+ </p>
54
+
55
+ <p align="center">
56
+ <a href="https://github.com/pavan-fulmamdikar/gatekeep-mcp/actions/workflows/ci.yml"><img src="https://github.com/pavan-fulmamdikar/gatekeep-mcp/actions/workflows/ci.yml/badge.svg" alt="Gatekeep CI" /></a>
57
+ </p>
58
+
59
+ <p align="center">
60
+ <code>Pure Python Stdlib (0 deps)</code> &nbsp;·&nbsp;
61
+ <code>&lt;1ms Deterministic Gate</code> &nbsp;·&nbsp;
62
+ <code>MCP Stdio / HTTP / SSE</code> &nbsp;·&nbsp;
63
+ <code>MIT / Apache-2.0</code>
64
+ </p>
65
+
66
+ <p align="center">
67
+ <img src="assets/gatekeep_demo_45s.gif" alt="Gatekeep 45-second live demo: real MCP filesystem firewall and automatic LIFO Saga rollback" width="820" />
68
+ </p>
69
+
70
+ ---
71
+
72
+ ## Why Gatekeep Exists (In 15 Seconds)
73
+
74
+ Frontier models still obey indirect prompt injections inside support tickets, logs, or compromised third-party MCP servers—and when an agent crashes mid-workflow on an upstream `503`, it leaves half-charged orders or orphaned cloud nodes behind.
75
+
76
+ ```text
77
+ WITHOUT GATEKEEP WITH GATEKEEP (0.3ms – 2ms deterministic proxy)
78
+ ─────────────────────────────────────────────────── ─────────────────────────────────────────────────────────────
79
+ 1. Compromised MCP plugin mutates schema mid-run ──▶ [BLOCK] mcp_tool_rug_pull (SHA-256 schema hash mismatch)
80
+ 2. Ticket tricks agent into reading .env.secrets ──▶ [BLOCK] sensitive_path_access (0.23ms)
81
+ 3. Agent probes AWS IMDS 169.254.169.254 ──▶ [BLOCK] ssrf_blocked_target (0.27ms)
82
+ 4. Agent pastes leaked Bearer JWT into Slack ──▶ [BLOCK] outbound_secret_dlp (0.29ms)
83
+ 5. Agent runs DELETE FROM service_events; ──▶ [BLOCK] destructive_payload_blocked
84
+ 6. Step 1 scales cluster (+4 nodes), Step 2 hits ──▶ [AUTO-ROLLBACK] LIFO Saga releases all 4 nodes back to 0
85
+ HTTP 503 -> orphaned billable nodes left behind + refunds cumulative spend cap + writes SHA-256 AuditReceipt
86
+ ```
87
+
88
+ ```mermaid
89
+ flowchart LR
90
+ Agent["AI Agent / Claude / Cursor / Java / LangGraph"] -->|"MCP tools/list & tools/call"| Proxy["Gatekeep Proxy (<1ms)"]
91
+ Proxy -->|"1. Provenance & Taint Ledger\n2. DLP / SSRF / Path / SQL Guards\n3. MCP Schema Pinning & Quotas\n4. Saga WAL + HITL Escalations"| Upstream["Upstream MCP Servers\n(DB, Stripe, Slack, FS, Cloud)"]
92
+ Upstream -.->|"HTTP 503 / Crash"| Saga["LIFO Auto-Rollback\n(Compensating Tools)"]
93
+ Proxy -->|"SHA-256 Hash Chain"| Audit["AuditVault / WORM JSONL / /metrics"]
94
+ ```
95
+
96
+ ---
97
+
98
+ ## 30-Second Quickstart
99
+
100
+ ### 1. Install (Pure Python Stdlib — Zero Required Dependencies)
101
+
102
+ ```bash
103
+ pip install gatekeep-mcp
104
+
105
+ # Optional production extras:
106
+ pip install "gatekeep-mcp[gateway]" # uvicorn + httpx for ASGI HTTP/SSE & pooled async upstream
107
+ pip install "gatekeep-mcp[postgres]" # psycopg[binary] + psycopg-pool for multi-worker Postgres
108
+ pip install "gatekeep-mcp[redis]" # redis for distributed session locks & cross-pod SSE Pub/Sub
109
+ ```
110
+
111
+ ### 2. Wrap Any Claude Desktop / Cursor MCP Server (Safe `--shadow` Dry-Run First)
112
+
113
+ Copy [examples/claude_desktop_config.example.json](examples/claude_desktop_config.example.json) into your Claude Desktop or Cursor MCP config to inspect what Gatekeep *would* block before enforcing:
114
+
115
+ ```json
116
+ {
117
+ "mcpServers": {
118
+ "filesystem-protected": {
119
+ "command": "gatekeep",
120
+ "args": [
121
+ "--upstream",
122
+ "npx -y @modelcontextprotocol/server-filesystem /path/to/workspace",
123
+ "--db",
124
+ "/tmp/gatekeep_state.db",
125
+ "--shadow"
126
+ ]
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ Or generate a starter policy automatically from any upstream MCP catalog:
133
+
134
+ ```bash
135
+ gatekeep --upstream "python my_mcp_server.py" --init-policy ./policies.json
136
+ gatekeep --upstream "python my_mcp_server.py" --policy ./policies.json --db ./gatekeep.db
137
+ ```
138
+
139
+ ### 3. Run as a Language-Agnostic HTTP Sidecar (Java / Spring Boot, Go, Node)
140
+
141
+ Non-Python services don't import Python—run Gatekeep as an HTTP sidecar container (just like Envoy or Redis) and call `POST /mcp` over JSON-RPC 2.0:
142
+
143
+ ```bash
144
+ gatekeep \
145
+ --upstream http://host.docker.internal:8081/mcp \
146
+ --db ./gatekeep.db \
147
+ --http 0.0.0.0:8080 \
148
+ --agent-key myservice=secret_agent_key \
149
+ --policy-admin-key myservice=secret_admin_key \
150
+ --approver-key myservice=secret_approver_key \
151
+ --strict-rbac
152
+
153
+ # Or boot Multi-Replica HA stack (2 ASGI Gatekeep pods + PostgreSQL 16 + Redis 7 Pub/Sub SSE):
154
+ docker compose -f docker-compose.ha.yml up -d
155
+ ```
156
+
157
+ Built-in HTTP endpoints:
158
+ - `POST /mcp` (Streamable-HTTP) and `GET /sse` + `POST /messages` (with automatic Redis Pub/Sub cross-replica SSE fan-out when backed by Redis or `--redis-url`)
159
+ - `GET /healthz` and `GET /metrics` (O(1) session counts via `SELECT COUNT(*)` / Redis `SCARD`, Prometheus gauges including `slim_gateway_quarantined_tools`)
160
+ - `GET /dashboard` (live approvals & audit web console)
161
+ - `GET|POST /admin/policies`, `POST /admin/policies/simulate`, `GET /admin/tools/quarantined`, `POST /admin/tools/trust`
162
+ - `GET /admin/escalations`, `POST /admin/escalations/{id}/approve`, `GET /admin/audit`, `GET /admin/audit/verify`, `POST /admin/recovery/sweep`
163
+
164
+ ---
165
+
166
+ ## Defense Matrix
167
+
168
+ | Threat / Failure Mode | Gatekeep Rule | How It Stops / Recovers |
169
+ | --- | --- | --- |
170
+ | **Hallucinated IDs & Indirect Prompt Injection** | `unverified_entity_provenance`, `tainted_entity_target`, `unsolicited_tainted_write` | Tracks structured read outputs vs. untrusted text (`body`, `content`, `html`) in `ToolReturnLedger`; blocks tainted targets and unsolicited writes. |
171
+ | **Secret & PII Exfiltration** | `outbound_secret_dlp` | Scans outbound write payloads (including base64 segments & Unicode/zero-width obfuscation) for Bearer tokens, API keys, PEM keys, DB URIs, SSNs, and Luhn cards. |
172
+ | **SSRF & Credential File Access** | `ssrf_blocked_target`, `sensitive_path_access` | Blocks `file://`/`gopher://`, localhost, RFC1918, cloud IMDS (`169.254.169.254`), decimal/hex/octal/IPv4-mapped IPv6 bypasses, optional DNS resolution (`resolve_dns_for_ssrf=True`), URL-encoded `..` traversal, `.env*`, `.ssh/`, `.aws/credentials`, `/etc/shadow`. |
173
+ | **Destructive SQL & Shell Commands** | `destructive_payload_blocked` | Strips SQL comments (`/*...*/`, `--`) and blocks `DROP`, `TRUNCATE`, chained `; DROP/DELETE`, un-`WHERE`d & tautological (`WHERE 1=1`) `DELETE`/`UPDATE`, and dangerous shell commands (`rm -rf /`, `curl ... \| bash`). |
174
+ | **Poisoned / Rug-Pulled MCP Servers** | `mcp_tool_poisoning`, `mcp_tool_rug_pull` | Detects hidden instruction tags/directives in tool descriptions & JSON schemas; pins canonical SHA-256 tool hashes across restarts in `SessionStateStore` until explicitly trusted (`trust_updated_tool` / `POST /admin/tools/trust`). |
175
+ | **Runaway Spend, Loops & Half-Finished Failures** | `rate_limit_exceeded`, `cumulative_spend_limit_exceeded`, `retry_spiral_circuit_breaker`, LIFO Saga | Enforces sliding 60s rate limits & atomic cross-session spend caps (`update_control_doc`), per-payload read circuit breakers, `Idempotency-Key` deduplication, and automatic LIFO Saga rollback on upstream errors (`auto_rollback_on_error=True`). |
176
+ | **Risky High-Impact Actions** | `human_approval_required`, `approval_token_scope_mismatch` | Pauses sensitive actions (`Verdict.ESCALATE`), enforces Separation of Duties (requester cannot self-approve), and cryptographically binds one-time approval tokens to the exact payload fingerprint. |
177
+
178
+ ---
179
+
180
+ ## Runnable End-to-End Demos
181
+
182
+ All examples run locally in seconds with zero API keys required (and support `--live` with an LLM):
183
+
184
+ ```bash
185
+ # 1. Zero-dependency IPI block + SQLite Saga rollback + AuditVault proof
186
+ python examples/mcp_transaction_gateway_demo.py
187
+
188
+ # 2. Federated DevSecOps & FinOps Incident Commander (6 stages: rug-pull, SSRF, DLP, SQL, $500 cap + 503 rollback, SoD HITL)
189
+ python examples/incident_commander_e2e.py
190
+
191
+ # 3. Multi-Agent Coordinator + 3 Sub-Agents (Research, Finance, Comms) with per-actor latency flight recorder
192
+ python examples/multi_agent_gatekeep_runner.py
193
+
194
+ # 4. Multi-tenant HTTP Gateway + HITL approval flow
195
+ python examples/http_gateway_hitl_demo.py
196
+
197
+ # 5. Live Field Test against unmodified third-party MCP server (@modelcontextprotocol/server-filesystem via npx)
198
+ python examples/field_test_third_party_mcp.py
199
+ ```
200
+
201
+ ---
202
+
203
+ ## Benchmarks & Honest Limitations
204
+
205
+ ### Local Verification (`pytest tests/`, Live `uvicorn` Load, & Real Third-Party MCP Field Test)
206
+ - **Unit, Runtime Scaling & Live HA Container Suite:** **`131 passed`** (`tests/test_runtime_scaling.py` verifies O(1) `count_sessions()`, auto `psycopg_pool.ConnectionPool`, non-blocking async cross-session concurrency, pooled `httpx.AsyncClient`, and cross-replica Redis Pub/Sub SSE fan-out; `tests/test_ha_postgres_redis_integration.py` passes **4/4 live non-mocked multi-replica tests** against real PostgreSQL 16 + Redis 7 containers in `docker-compose.ha.yml`).
207
+ - **70-Scenario Security & False-Positive Suite ([bench_adversarial_security.py](benchmarks/bench_adversarial_security.py)):** `35/35 (100.0%)` synthetic attacks mitigated, `35/35` legitimate workflows allowed (`0.0%` false-block rate), **`~2–5ms` p50** proxy+SQLite latency.
208
+ - **Live `uvicorn` ASGI HTTP Load Benchmark ([bench_http_load.py](benchmarks/bench_http_load.py), single worker sharing Windows loopback host with `httpx` client across all 4 storage backends):**
209
+ - `InMemorySessionStore` (`c=10`, 400 mixed reqs): **`121.5 req/s`**, `p50=70.7ms`, `p95=145.4ms`, `0` HTTP errors, `100/100` attacks blocked, RSS `54.8 -> 59.0 MiB` (`104.9 req/s` at `c=30`).
210
+ - `SQLiteSessionStore` WAL (`c=10`, 400 mixed reqs): **`96.5 req/s`**, `p50=104.7ms`, `p95=141.3ms`, `/healthz` `p50=39.6ms`, `0` HTTP errors, `100/100` attacks blocked, RSS `56.4 -> 64.9 MiB` (`70.6 req/s` at `c=25`).
211
+ - `RedisSessionStore` live Redis 7 container (`c=15`, 400 mixed reqs): **`49.4 req/s`**, `p50=258.2ms`, `p95=590.7ms`, `0` HTTP errors, `100/100` attacks blocked, RSS `68.0 -> 89.0 MiB`.
212
+ - `PostgresSessionStore` live PostgreSQL 16 container + `psycopg_pool` (`c=15`, 400 mixed reqs): **`30.6 req/s`**, `p50=514.0ms`, `p95=707.5ms`, `0` HTTP errors, `100/100` attacks blocked, RSS `67.4 -> 89.0 MiB`.
213
+ - **Live Third-Party MCP Server Field Test ([field_test_third_party_mcp.py](examples/field_test_third_party_mcp.py)):**
214
+ - Wrapped unmodified Anthropic `@modelcontextprotocol/server-filesystem` over real `npx` stdio (`16` real tools auto-classified by `generate_starter_policy()`).
215
+ - Enforcing mode: `3/3` benign operations allowed (`list_directory`, `read_text_file`, `write_file`), `4/4` live attacks blocked before reaching Node.js (`../../etc/passwd`, `.env.production`, `.ssh/id_rsa`, outbound AWS key DLP in `write_file`), **`0.463ms` median Gatekeep evaluation latency** (`0.694ms` max), valid SHA-256 audit chain (`7` receipts).
216
+ - Shadow mode also accurately demonstrated real-world prompt-intent behavior: vague user prompts (`"Work with files in ..."`) surfaced `unsolicited_tainted_write` shadow flags on `write_file`/`edit_file` without blocking execution (`14.1ms` median e2e).
217
+ - **Zero-Help Live Multi-Agent Stress Findings (`groq / openai/gpt-oss-120b`):**
218
+ Running an uncoached autonomous coordinator with unfiltered tools across hostile workspace SOP traps added **`0.30–0.35ms` p50** Gatekeep overhead, blocked `.env.secrets`, IMDS `169.254.169.254`, `VENDOR-EVIL-99`, and leaked `Bearer` exfiltration, and cleanly reverted SQLite rows on `503` failures.
219
+
220
+ ### Known Limitations (Read Before Deploying to High-Scale Prod)
221
+ 1. **Heuristics vs. Vague Prompts:** When `_meta.user_prompt` is supplied and contains only read-phrased language without mutating verbs, zero-config intent checks can flag writes after untrusted reads as `unsolicited_tainted_write`—configure explicit `ToolPolicySpec` rules or validate in `--shadow` first.
222
+ 2. **Non-Reversible External Side Effects:** Saga compensation (`compensates_with`) cleanly undoes reversible actions (DB rows, cloud allocations, payment authorizations), but cannot un-send emails or undo irreversible third-party webhooks—gate those with `requires_approval=True`.
223
+ 3. **DNS SSRF Check Is Opt-In (`resolve_dns_for_ssrf=False`):** By default, SSRF protection inspects URL schemes, IP literals, obfuscated IPs, and metadata hostnames with zero network latency; enable `resolve_dns_for_ssrf=True` (and pair with network egress controls) where DNS-rebinding attacks are in scope.
224
+ 4. **Live Postgres 16 / Redis 7 HA Verification Requires Docker:** `tests/test_ha_postgres_redis_integration.py` skips cleanly when `GATEKEEP_LIVE_PG_DSN` / `GATEKEEP_LIVE_REDIS_URL` are unset; run against real containers via `docker compose -f docker-compose.ha.yml up -d` in CI/staging before high-QPS multi-replica rollout.
225
+
226
+ ---
227
+
228
+ ## Development
229
+
230
+ ```bash
231
+ pip install -e ".[dev]"
232
+ pytest tests/ -v
233
+ python benchmarks/bench_adversarial_security.py
234
+ python benchmarks/bench_http_load.py --store sqlite --requests 500 --concurrency 25
235
+
236
+ # Live Multi-Replica PostgreSQL 16 + Redis 7 HA Soak Tests (requires Docker):
237
+ docker compose -f docker-compose.ha.yml up -d postgres redis
238
+ GATEKEEP_LIVE_PG_DSN=postgresql://gatekeep:gatekeep_dev@localhost:5439/gatekeep \
239
+ GATEKEEP_LIVE_REDIS_URL=redis://localhost:6379/0 \
240
+ pytest tests/test_ha_postgres_redis_integration.py -v
241
+ ```
242
+
243
+ ## License
244
+
245
+ Dual-licensed under either **MIT** ([LICENSE-MIT](LICENSE-MIT)) or **Apache-2.0** ([LICENSE-APACHE](LICENSE-APACHE)), at your option.
@@ -0,0 +1,198 @@
1
+ <h1 align="center">Gatekeep</h1>
2
+
3
+ <p align="center">
4
+ <strong>Zero-dependency, sub-millisecond firewall &amp; automatic Saga undo proxy for MCP AI agents.</strong><br>
5
+ <em>Stop prompt-injected writes, secret exfiltration, SSRF, rug-pulled MCP servers, and half-finished DB mutations — with zero LLM judges and zero required third-party dependencies.</em>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="https://github.com/pavan-fulmamdikar/gatekeep-mcp/actions/workflows/ci.yml"><img src="https://github.com/pavan-fulmamdikar/gatekeep-mcp/actions/workflows/ci.yml/badge.svg" alt="Gatekeep CI" /></a>
10
+ </p>
11
+
12
+ <p align="center">
13
+ <code>Pure Python Stdlib (0 deps)</code> &nbsp;·&nbsp;
14
+ <code>&lt;1ms Deterministic Gate</code> &nbsp;·&nbsp;
15
+ <code>MCP Stdio / HTTP / SSE</code> &nbsp;·&nbsp;
16
+ <code>MIT / Apache-2.0</code>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <img src="assets/gatekeep_demo_45s.gif" alt="Gatekeep 45-second live demo: real MCP filesystem firewall and automatic LIFO Saga rollback" width="820" />
21
+ </p>
22
+
23
+ ---
24
+
25
+ ## Why Gatekeep Exists (In 15 Seconds)
26
+
27
+ Frontier models still obey indirect prompt injections inside support tickets, logs, or compromised third-party MCP servers—and when an agent crashes mid-workflow on an upstream `503`, it leaves half-charged orders or orphaned cloud nodes behind.
28
+
29
+ ```text
30
+ WITHOUT GATEKEEP WITH GATEKEEP (0.3ms – 2ms deterministic proxy)
31
+ ─────────────────────────────────────────────────── ─────────────────────────────────────────────────────────────
32
+ 1. Compromised MCP plugin mutates schema mid-run ──▶ [BLOCK] mcp_tool_rug_pull (SHA-256 schema hash mismatch)
33
+ 2. Ticket tricks agent into reading .env.secrets ──▶ [BLOCK] sensitive_path_access (0.23ms)
34
+ 3. Agent probes AWS IMDS 169.254.169.254 ──▶ [BLOCK] ssrf_blocked_target (0.27ms)
35
+ 4. Agent pastes leaked Bearer JWT into Slack ──▶ [BLOCK] outbound_secret_dlp (0.29ms)
36
+ 5. Agent runs DELETE FROM service_events; ──▶ [BLOCK] destructive_payload_blocked
37
+ 6. Step 1 scales cluster (+4 nodes), Step 2 hits ──▶ [AUTO-ROLLBACK] LIFO Saga releases all 4 nodes back to 0
38
+ HTTP 503 -> orphaned billable nodes left behind + refunds cumulative spend cap + writes SHA-256 AuditReceipt
39
+ ```
40
+
41
+ ```mermaid
42
+ flowchart LR
43
+ Agent["AI Agent / Claude / Cursor / Java / LangGraph"] -->|"MCP tools/list & tools/call"| Proxy["Gatekeep Proxy (<1ms)"]
44
+ Proxy -->|"1. Provenance & Taint Ledger\n2. DLP / SSRF / Path / SQL Guards\n3. MCP Schema Pinning & Quotas\n4. Saga WAL + HITL Escalations"| Upstream["Upstream MCP Servers\n(DB, Stripe, Slack, FS, Cloud)"]
45
+ Upstream -.->|"HTTP 503 / Crash"| Saga["LIFO Auto-Rollback\n(Compensating Tools)"]
46
+ Proxy -->|"SHA-256 Hash Chain"| Audit["AuditVault / WORM JSONL / /metrics"]
47
+ ```
48
+
49
+ ---
50
+
51
+ ## 30-Second Quickstart
52
+
53
+ ### 1. Install (Pure Python Stdlib — Zero Required Dependencies)
54
+
55
+ ```bash
56
+ pip install gatekeep-mcp
57
+
58
+ # Optional production extras:
59
+ pip install "gatekeep-mcp[gateway]" # uvicorn + httpx for ASGI HTTP/SSE & pooled async upstream
60
+ pip install "gatekeep-mcp[postgres]" # psycopg[binary] + psycopg-pool for multi-worker Postgres
61
+ pip install "gatekeep-mcp[redis]" # redis for distributed session locks & cross-pod SSE Pub/Sub
62
+ ```
63
+
64
+ ### 2. Wrap Any Claude Desktop / Cursor MCP Server (Safe `--shadow` Dry-Run First)
65
+
66
+ Copy [examples/claude_desktop_config.example.json](examples/claude_desktop_config.example.json) into your Claude Desktop or Cursor MCP config to inspect what Gatekeep *would* block before enforcing:
67
+
68
+ ```json
69
+ {
70
+ "mcpServers": {
71
+ "filesystem-protected": {
72
+ "command": "gatekeep",
73
+ "args": [
74
+ "--upstream",
75
+ "npx -y @modelcontextprotocol/server-filesystem /path/to/workspace",
76
+ "--db",
77
+ "/tmp/gatekeep_state.db",
78
+ "--shadow"
79
+ ]
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ Or generate a starter policy automatically from any upstream MCP catalog:
86
+
87
+ ```bash
88
+ gatekeep --upstream "python my_mcp_server.py" --init-policy ./policies.json
89
+ gatekeep --upstream "python my_mcp_server.py" --policy ./policies.json --db ./gatekeep.db
90
+ ```
91
+
92
+ ### 3. Run as a Language-Agnostic HTTP Sidecar (Java / Spring Boot, Go, Node)
93
+
94
+ Non-Python services don't import Python—run Gatekeep as an HTTP sidecar container (just like Envoy or Redis) and call `POST /mcp` over JSON-RPC 2.0:
95
+
96
+ ```bash
97
+ gatekeep \
98
+ --upstream http://host.docker.internal:8081/mcp \
99
+ --db ./gatekeep.db \
100
+ --http 0.0.0.0:8080 \
101
+ --agent-key myservice=secret_agent_key \
102
+ --policy-admin-key myservice=secret_admin_key \
103
+ --approver-key myservice=secret_approver_key \
104
+ --strict-rbac
105
+
106
+ # Or boot Multi-Replica HA stack (2 ASGI Gatekeep pods + PostgreSQL 16 + Redis 7 Pub/Sub SSE):
107
+ docker compose -f docker-compose.ha.yml up -d
108
+ ```
109
+
110
+ Built-in HTTP endpoints:
111
+ - `POST /mcp` (Streamable-HTTP) and `GET /sse` + `POST /messages` (with automatic Redis Pub/Sub cross-replica SSE fan-out when backed by Redis or `--redis-url`)
112
+ - `GET /healthz` and `GET /metrics` (O(1) session counts via `SELECT COUNT(*)` / Redis `SCARD`, Prometheus gauges including `slim_gateway_quarantined_tools`)
113
+ - `GET /dashboard` (live approvals & audit web console)
114
+ - `GET|POST /admin/policies`, `POST /admin/policies/simulate`, `GET /admin/tools/quarantined`, `POST /admin/tools/trust`
115
+ - `GET /admin/escalations`, `POST /admin/escalations/{id}/approve`, `GET /admin/audit`, `GET /admin/audit/verify`, `POST /admin/recovery/sweep`
116
+
117
+ ---
118
+
119
+ ## Defense Matrix
120
+
121
+ | Threat / Failure Mode | Gatekeep Rule | How It Stops / Recovers |
122
+ | --- | --- | --- |
123
+ | **Hallucinated IDs & Indirect Prompt Injection** | `unverified_entity_provenance`, `tainted_entity_target`, `unsolicited_tainted_write` | Tracks structured read outputs vs. untrusted text (`body`, `content`, `html`) in `ToolReturnLedger`; blocks tainted targets and unsolicited writes. |
124
+ | **Secret & PII Exfiltration** | `outbound_secret_dlp` | Scans outbound write payloads (including base64 segments & Unicode/zero-width obfuscation) for Bearer tokens, API keys, PEM keys, DB URIs, SSNs, and Luhn cards. |
125
+ | **SSRF & Credential File Access** | `ssrf_blocked_target`, `sensitive_path_access` | Blocks `file://`/`gopher://`, localhost, RFC1918, cloud IMDS (`169.254.169.254`), decimal/hex/octal/IPv4-mapped IPv6 bypasses, optional DNS resolution (`resolve_dns_for_ssrf=True`), URL-encoded `..` traversal, `.env*`, `.ssh/`, `.aws/credentials`, `/etc/shadow`. |
126
+ | **Destructive SQL & Shell Commands** | `destructive_payload_blocked` | Strips SQL comments (`/*...*/`, `--`) and blocks `DROP`, `TRUNCATE`, chained `; DROP/DELETE`, un-`WHERE`d & tautological (`WHERE 1=1`) `DELETE`/`UPDATE`, and dangerous shell commands (`rm -rf /`, `curl ... \| bash`). |
127
+ | **Poisoned / Rug-Pulled MCP Servers** | `mcp_tool_poisoning`, `mcp_tool_rug_pull` | Detects hidden instruction tags/directives in tool descriptions & JSON schemas; pins canonical SHA-256 tool hashes across restarts in `SessionStateStore` until explicitly trusted (`trust_updated_tool` / `POST /admin/tools/trust`). |
128
+ | **Runaway Spend, Loops & Half-Finished Failures** | `rate_limit_exceeded`, `cumulative_spend_limit_exceeded`, `retry_spiral_circuit_breaker`, LIFO Saga | Enforces sliding 60s rate limits & atomic cross-session spend caps (`update_control_doc`), per-payload read circuit breakers, `Idempotency-Key` deduplication, and automatic LIFO Saga rollback on upstream errors (`auto_rollback_on_error=True`). |
129
+ | **Risky High-Impact Actions** | `human_approval_required`, `approval_token_scope_mismatch` | Pauses sensitive actions (`Verdict.ESCALATE`), enforces Separation of Duties (requester cannot self-approve), and cryptographically binds one-time approval tokens to the exact payload fingerprint. |
130
+
131
+ ---
132
+
133
+ ## Runnable End-to-End Demos
134
+
135
+ All examples run locally in seconds with zero API keys required (and support `--live` with an LLM):
136
+
137
+ ```bash
138
+ # 1. Zero-dependency IPI block + SQLite Saga rollback + AuditVault proof
139
+ python examples/mcp_transaction_gateway_demo.py
140
+
141
+ # 2. Federated DevSecOps & FinOps Incident Commander (6 stages: rug-pull, SSRF, DLP, SQL, $500 cap + 503 rollback, SoD HITL)
142
+ python examples/incident_commander_e2e.py
143
+
144
+ # 3. Multi-Agent Coordinator + 3 Sub-Agents (Research, Finance, Comms) with per-actor latency flight recorder
145
+ python examples/multi_agent_gatekeep_runner.py
146
+
147
+ # 4. Multi-tenant HTTP Gateway + HITL approval flow
148
+ python examples/http_gateway_hitl_demo.py
149
+
150
+ # 5. Live Field Test against unmodified third-party MCP server (@modelcontextprotocol/server-filesystem via npx)
151
+ python examples/field_test_third_party_mcp.py
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Benchmarks & Honest Limitations
157
+
158
+ ### Local Verification (`pytest tests/`, Live `uvicorn` Load, & Real Third-Party MCP Field Test)
159
+ - **Unit, Runtime Scaling & Live HA Container Suite:** **`131 passed`** (`tests/test_runtime_scaling.py` verifies O(1) `count_sessions()`, auto `psycopg_pool.ConnectionPool`, non-blocking async cross-session concurrency, pooled `httpx.AsyncClient`, and cross-replica Redis Pub/Sub SSE fan-out; `tests/test_ha_postgres_redis_integration.py` passes **4/4 live non-mocked multi-replica tests** against real PostgreSQL 16 + Redis 7 containers in `docker-compose.ha.yml`).
160
+ - **70-Scenario Security & False-Positive Suite ([bench_adversarial_security.py](benchmarks/bench_adversarial_security.py)):** `35/35 (100.0%)` synthetic attacks mitigated, `35/35` legitimate workflows allowed (`0.0%` false-block rate), **`~2–5ms` p50** proxy+SQLite latency.
161
+ - **Live `uvicorn` ASGI HTTP Load Benchmark ([bench_http_load.py](benchmarks/bench_http_load.py), single worker sharing Windows loopback host with `httpx` client across all 4 storage backends):**
162
+ - `InMemorySessionStore` (`c=10`, 400 mixed reqs): **`121.5 req/s`**, `p50=70.7ms`, `p95=145.4ms`, `0` HTTP errors, `100/100` attacks blocked, RSS `54.8 -> 59.0 MiB` (`104.9 req/s` at `c=30`).
163
+ - `SQLiteSessionStore` WAL (`c=10`, 400 mixed reqs): **`96.5 req/s`**, `p50=104.7ms`, `p95=141.3ms`, `/healthz` `p50=39.6ms`, `0` HTTP errors, `100/100` attacks blocked, RSS `56.4 -> 64.9 MiB` (`70.6 req/s` at `c=25`).
164
+ - `RedisSessionStore` live Redis 7 container (`c=15`, 400 mixed reqs): **`49.4 req/s`**, `p50=258.2ms`, `p95=590.7ms`, `0` HTTP errors, `100/100` attacks blocked, RSS `68.0 -> 89.0 MiB`.
165
+ - `PostgresSessionStore` live PostgreSQL 16 container + `psycopg_pool` (`c=15`, 400 mixed reqs): **`30.6 req/s`**, `p50=514.0ms`, `p95=707.5ms`, `0` HTTP errors, `100/100` attacks blocked, RSS `67.4 -> 89.0 MiB`.
166
+ - **Live Third-Party MCP Server Field Test ([field_test_third_party_mcp.py](examples/field_test_third_party_mcp.py)):**
167
+ - Wrapped unmodified Anthropic `@modelcontextprotocol/server-filesystem` over real `npx` stdio (`16` real tools auto-classified by `generate_starter_policy()`).
168
+ - Enforcing mode: `3/3` benign operations allowed (`list_directory`, `read_text_file`, `write_file`), `4/4` live attacks blocked before reaching Node.js (`../../etc/passwd`, `.env.production`, `.ssh/id_rsa`, outbound AWS key DLP in `write_file`), **`0.463ms` median Gatekeep evaluation latency** (`0.694ms` max), valid SHA-256 audit chain (`7` receipts).
169
+ - Shadow mode also accurately demonstrated real-world prompt-intent behavior: vague user prompts (`"Work with files in ..."`) surfaced `unsolicited_tainted_write` shadow flags on `write_file`/`edit_file` without blocking execution (`14.1ms` median e2e).
170
+ - **Zero-Help Live Multi-Agent Stress Findings (`groq / openai/gpt-oss-120b`):**
171
+ Running an uncoached autonomous coordinator with unfiltered tools across hostile workspace SOP traps added **`0.30–0.35ms` p50** Gatekeep overhead, blocked `.env.secrets`, IMDS `169.254.169.254`, `VENDOR-EVIL-99`, and leaked `Bearer` exfiltration, and cleanly reverted SQLite rows on `503` failures.
172
+
173
+ ### Known Limitations (Read Before Deploying to High-Scale Prod)
174
+ 1. **Heuristics vs. Vague Prompts:** When `_meta.user_prompt` is supplied and contains only read-phrased language without mutating verbs, zero-config intent checks can flag writes after untrusted reads as `unsolicited_tainted_write`—configure explicit `ToolPolicySpec` rules or validate in `--shadow` first.
175
+ 2. **Non-Reversible External Side Effects:** Saga compensation (`compensates_with`) cleanly undoes reversible actions (DB rows, cloud allocations, payment authorizations), but cannot un-send emails or undo irreversible third-party webhooks—gate those with `requires_approval=True`.
176
+ 3. **DNS SSRF Check Is Opt-In (`resolve_dns_for_ssrf=False`):** By default, SSRF protection inspects URL schemes, IP literals, obfuscated IPs, and metadata hostnames with zero network latency; enable `resolve_dns_for_ssrf=True` (and pair with network egress controls) where DNS-rebinding attacks are in scope.
177
+ 4. **Live Postgres 16 / Redis 7 HA Verification Requires Docker:** `tests/test_ha_postgres_redis_integration.py` skips cleanly when `GATEKEEP_LIVE_PG_DSN` / `GATEKEEP_LIVE_REDIS_URL` are unset; run against real containers via `docker compose -f docker-compose.ha.yml up -d` in CI/staging before high-QPS multi-replica rollout.
178
+
179
+ ---
180
+
181
+ ## Development
182
+
183
+ ```bash
184
+ pip install -e ".[dev]"
185
+ pytest tests/ -v
186
+ python benchmarks/bench_adversarial_security.py
187
+ python benchmarks/bench_http_load.py --store sqlite --requests 500 --concurrency 25
188
+
189
+ # Live Multi-Replica PostgreSQL 16 + Redis 7 HA Soak Tests (requires Docker):
190
+ docker compose -f docker-compose.ha.yml up -d postgres redis
191
+ GATEKEEP_LIVE_PG_DSN=postgresql://gatekeep:gatekeep_dev@localhost:5439/gatekeep \
192
+ GATEKEEP_LIVE_REDIS_URL=redis://localhost:6379/0 \
193
+ pytest tests/test_ha_postgres_redis_integration.py -v
194
+ ```
195
+
196
+ ## License
197
+
198
+ Dual-licensed under either **MIT** ([LICENSE-MIT](LICENSE-MIT)) or **Apache-2.0** ([LICENSE-APACHE](LICENSE-APACHE)), at your option.