mcpknight 0.1.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 (52) hide show
  1. mcpknight-0.1.0/PKG-INFO +284 -0
  2. mcpknight-0.1.0/README.md +258 -0
  3. mcpknight-0.1.0/cli.py +818 -0
  4. mcpknight-0.1.0/config_patcher.py +211 -0
  5. mcpknight-0.1.0/firewall_cli.py +166 -0
  6. mcpknight-0.1.0/intent_analyser/__init__.py +43 -0
  7. mcpknight-0.1.0/intent_analyser/schemas.py +90 -0
  8. mcpknight-0.1.0/intent_analyser/semantic_analyser.py +537 -0
  9. mcpknight-0.1.0/intent_analyser/static_analyser.py +296 -0
  10. mcpknight-0.1.0/main.py +8 -0
  11. mcpknight-0.1.0/mcp_firewall_client.py +203 -0
  12. mcpknight-0.1.0/mcp_proxy.py +280 -0
  13. mcpknight-0.1.0/mcpknight.egg-info/PKG-INFO +284 -0
  14. mcpknight-0.1.0/mcpknight.egg-info/SOURCES.txt +50 -0
  15. mcpknight-0.1.0/mcpknight.egg-info/dependency_links.txt +1 -0
  16. mcpknight-0.1.0/mcpknight.egg-info/entry_points.txt +4 -0
  17. mcpknight-0.1.0/mcpknight.egg-info/requires.txt +9 -0
  18. mcpknight-0.1.0/mcpknight.egg-info/top_level.txt +11 -0
  19. mcpknight-0.1.0/pyproject.toml +53 -0
  20. mcpknight-0.1.0/quarantine_engine/__init__.py +19 -0
  21. mcpknight-0.1.0/quarantine_engine/quarantine_engine/__init__.py +19 -0
  22. mcpknight-0.1.0/quarantine_engine/quarantine_engine/analyzer_integration.py +89 -0
  23. mcpknight-0.1.0/quarantine_engine/quarantine_engine/audit_log.py +49 -0
  24. mcpknight-0.1.0/quarantine_engine/quarantine_engine/core.py +177 -0
  25. mcpknight-0.1.0/quarantine_engine/quarantine_engine/models.py +59 -0
  26. mcpknight-0.1.0/quarantine_engine/quarantine_engine/version_store.py +42 -0
  27. mcpknight-0.1.0/quarantine_engine/tests/test_quarantine_engine.py +113 -0
  28. mcpknight-0.1.0/runtime_firewall.py +479 -0
  29. mcpknight-0.1.0/sentinel_logger.py +158 -0
  30. mcpknight-0.1.0/setup.cfg +4 -0
  31. mcpknight-0.1.0/tests/test_config_patcher.py +92 -0
  32. mcpknight-0.1.0/tests/test_current_implementation_regressions.py +203 -0
  33. mcpknight-0.1.0/tests/test_firewall_cli.py +252 -0
  34. mcpknight-0.1.0/tests/test_intent_analyser.py +131 -0
  35. mcpknight-0.1.0/tests/test_intent_quarantine_integration.py +214 -0
  36. mcpknight-0.1.0/tests/test_mcp_firewall_client.py +247 -0
  37. mcpknight-0.1.0/tests/test_mcp_proxy.py +204 -0
  38. mcpknight-0.1.0/tests/test_runtime_firewall.py +152 -0
  39. mcpknight-0.1.0/tests/test_sentinel_logger.py +30 -0
  40. mcpknight-0.1.0/tests/test_trust_betray.py +239 -0
  41. mcpknight-0.1.0/trust_betray/__init__.py +151 -0
  42. mcpknight-0.1.0/trust_betray/attacks/__init__.py +13 -0
  43. mcpknight-0.1.0/trust_betray/attacks/gradual_drift.py +25 -0
  44. mcpknight-0.1.0/trust_betray/attacks/mimicry.py +14 -0
  45. mcpknight-0.1.0/trust_betray/attacks/sudden_pivot.py +15 -0
  46. mcpknight-0.1.0/trust_betray/classifier.py +76 -0
  47. mcpknight-0.1.0/trust_betray/drift.py +242 -0
  48. mcpknight-0.1.0/trust_betray/fingerprint.py +202 -0
  49. mcpknight-0.1.0/trust_betray/models.py +261 -0
  50. mcpknight-0.1.0/trust_betray/quarantine.py +121 -0
  51. mcpknight-0.1.0/trust_betray/store.py +352 -0
  52. mcpknight-0.1.0/trust_betray/timeline.py +243 -0
@@ -0,0 +1,284 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcpknight
3
+ Version: 0.1.0
4
+ Summary: Active Runtime Security Firewall & Interceptor Gateway for Agent Tools & MCP Servers
5
+ License: Apache-2.0
6
+ Keywords: mcp,security,firewall,llm,ai,claude,cursor,zero-trust,prompt-injection
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Security
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: typer>=0.12.0
19
+ Requires-Dist: rich>=13.0.0
20
+ Requires-Dist: pydantic>=2.0
21
+ Requires-Dist: loguru>=0.7.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
24
+ Requires-Dist: build>=1.0.0; extra == "dev"
25
+ Requires-Dist: twine>=5.0.0; extra == "dev"
26
+
27
+ # MCPSentinel
28
+
29
+ **Active Zero-Trust Runtime Security Firewall & Interceptor Gateway for AI Agent Tools & MCP Servers.**
30
+
31
+ MCPSentinel provides real-time security gating for Agentic tools and MCP servers across 4 critical lifecycle phases:
32
+ 1. **Pre-Registration Intent & Threat Inspection**: Static and semantic analysis detecting covert exfiltration, indirect prompt injection, privilege escalation, and schema manipulation.
33
+ 2. **Pre-Execution Argument Gating**: Sandboxing and runtime inspection blocking unauthorized path traversal, command injection, and sensitive parameter overrides.
34
+ 3. **Execution & Latency Profiling**: Tamper-proof telemetry profiling execution latency and outputs.
35
+ 4. **Post-Execution Behavioral Drift Verification**: Intercepts outputs and quarantines tools exhibiting sudden behavioral shifts, capability creep, or mimicry attacks.
36
+
37
+ ---
38
+
39
+ ## โšก 1-Click Auto-Protect for Claude Desktop, Cursor & Codex
40
+
41
+ Instead of manually editing JSON configs, MCPSentinel can **automatically detect, backup, and wrap** all configured MCP servers with one command:
42
+
43
+ ```bash
44
+ # Automatically scan & protect Claude Desktop, Cursor, and Codex / Claude Code configs
45
+ mcpsentinel protect
46
+
47
+ # Or target a specific application / config file
48
+ mcpsentinel protect --claude
49
+ mcpsentinel protect --cursor
50
+ mcpsentinel protect --codex
51
+ mcpsentinel protect --config /path/to/custom_mcp_config.json
52
+
53
+ # Restore / unwrap servers at any time
54
+ mcpsentinel unwrap
55
+ ```
56
+
57
+ ---
58
+
59
+ ## ๐Ÿ”’ Transparent MCP Proxy (`mcpsentinel wrap`)
60
+
61
+ MCPSentinel can transparently wrap any standard MCP server over stdio without any code modifications.
62
+
63
+ ### MCP Client Configuration (`claude_desktop_config.json`, Cursor, etc.)
64
+
65
+ ```json
66
+ {
67
+ "mcpServers": {
68
+ "filesystem": {
69
+ "command": "mcpsentinel",
70
+ "args": ["wrap", "npx", "@modelcontextprotocol/server-filesystem", "/workspace"]
71
+ },
72
+ "custom_server": {
73
+ "command": "mcpsentinel",
74
+ "args": ["wrap", "python3", "my_mcp_server.py"]
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ When wrapped, MCPSentinel automatically:
81
+ - Intercepts `tools/list` with zero startup handshake latency by caching tool definitions without eager evaluation.
82
+ - Intercepts `tools/call` requests with JIT Intent & Security Analysis upon first call, blocking malicious schemas, sensitive parameter overrides (e.g. `/etc/shadow`), and quarantined tools fail-fast before execution.
83
+ - Intercepts `tools/call` responses, detecting prompt injections and behavioral drift to suppress malicious payloads before they reach the LLM.
84
+
85
+ ---
86
+
87
+ ## ๐Ÿ“Š Structured Logging & Telemetry (Loguru & Loki)
88
+
89
+ MCPSentinel provides dual real-time and persistent telemetry:
90
+
91
+ - **Stdio Safe**: Real-time console logs are streamed exclusively to `sys.stderr`, ensuring MCP JSON-RPC protocol messages over `stdout` are never corrupted.
92
+ - **Persistent Local Logs**:
93
+ - Formatted text log: `~/.mcpsentinel/logs/mcpsentinel.log` (automatic 10MB rotation, 14-day retention).
94
+ - Structured JSONL log: `~/.mcpsentinel/logs/mcpsentinel.jsonl` (machine-readable SIEM format).
95
+ - **Grafana Loki Streaming**: Set `MCPSENTINEL_LOKI_URL="http://localhost:3100"` to stream telemetry asynchronously in background daemon threads.
96
+
97
+ ```bash
98
+ # Stream live logs with the built-in CLI monitor
99
+ mcpsentinel logs
100
+
101
+ # Follow only ERROR / WARNING logs
102
+ mcpsentinel logs --level ERROR
103
+
104
+ # View last 50 lines without following
105
+ mcpsentinel logs --no-follow -n 50
106
+
107
+ # Stream raw structured JSONL SIEM events
108
+ mcpsentinel logs --json
109
+
110
+ # Clear stored logs
111
+ mcpsentinel logs --clear
112
+ ```
113
+
114
+ ---
115
+
116
+ ## ๐Ÿ› ๏ธ Python SDK Usage
117
+
118
+ You can also protect native Python tools and functions directly using the `@firewall.protect` decorator:
119
+
120
+ ```python
121
+ from mcpsentinel import RuntimeFirewall
122
+
123
+ firewall = RuntimeFirewall()
124
+
125
+ @firewall.protect()
126
+ def query_database(query: str) -> dict:
127
+ """Executes a database query."""
128
+ return {"status": "success", "rows": []}
129
+
130
+ # Calls are gated through pre-call checks and post-call drift verification
131
+ result = query_database(query="SELECT * FROM users")
132
+ ```
133
+
134
+ ---
135
+
136
+ ## ๐Ÿ’ป CLI Usage
137
+
138
+ MCPSentinel includes a full CLI powered by **Typer** and **Rich**.
139
+
140
+ ### Installation
141
+
142
+ ```bash
143
+ # Global installation via pipx / pip
144
+ pip install mcpsentinel
145
+ # or
146
+ pipx install mcpsentinel
147
+
148
+ # Or for local development:
149
+ pip install -e .
150
+ ```
151
+
152
+ ---
153
+
154
+ ### Commands Overview
155
+
156
+ #### 1. Transparent MCP Server Wrap (`mcpsentinel wrap`)
157
+ ```bash
158
+ mcpsentinel wrap npx @modelcontextprotocol/server-filesystem /tmp
159
+ ```
160
+
161
+ #### 2. Auto-Protect MCP Client Configurations (`mcpsentinel protect`)
162
+ ```bash
163
+ mcpsentinel protect --claude
164
+ mcpsentinel protect --cursor
165
+ mcpsentinel protect --codex
166
+ ```
167
+
168
+ #### 3. Inspect / Analyze Tool Security (`mcpsentinel inspect`)
169
+ ```bash
170
+ # Inspect via JSON string
171
+ mcpsentinel inspect --tool-json '{"name": "search_docs", "description": "Search public docs", "parameters": {"query": "string"}}'
172
+
173
+ # Inspect via JSON file
174
+ mcpsentinel inspect --file tool_definition.json
175
+ ```
176
+
177
+ #### 4. Execute / Call Tools Through Firewall (`mcpsentinel call`)
178
+ ```bash
179
+ # Call a safe tool
180
+ mcpsentinel call search_docs --tool-json '{"name": "search_docs"}' --arguments '{"query": "firewall"}'
181
+
182
+ # Malicious arguments will be blocked fail-fast
183
+ mcpsentinel call read_file --tool-json '{"name": "read_file"}' --arguments '{"path": "/etc/shadow"}'
184
+ ```
185
+
186
+ #### 5. Manually Approve Blocked Tools (`mcpsentinel approve`)
187
+ ```bash
188
+ mcpsentinel approve fetch_notes --operator alice --reviewer-note "Approved for restricted debug environment"
189
+ ```
190
+
191
+ #### 6. Quarantine Management (`mcpsentinel quarantine`)
192
+ ```bash
193
+ # List all quarantined tools
194
+ mcpsentinel quarantine list
195
+
196
+ # Check status of a specific tool
197
+ mcpsentinel quarantine status fetch_notes
198
+
199
+ # Release a tool from quarantine
200
+ mcpsentinel quarantine release fetch_notes --operator admin --reviewer-note "Audit resolved"
201
+ ```
202
+
203
+ #### 7. Audit Trail (`mcpsentinel audit`)
204
+ ```bash
205
+ mcpsentinel audit logs --limit 20
206
+ ```
207
+
208
+ #### 8. Live Log Monitoring (`mcpsentinel logs` / `mcpsentinel monitor`)
209
+ ```bash
210
+ # Follow formatted live logs
211
+ mcpsentinel logs
212
+
213
+ # Filter by log level
214
+ mcpsentinel logs --level WARNING
215
+
216
+ # Output in JSON format
217
+ mcpsentinel logs --json
218
+ ```
219
+
220
+ ---
221
+
222
+ ## ๐Ÿ“ Project Structure
223
+
224
+ ```text
225
+ mcpsentinel/
226
+ โ”œโ”€โ”€ cli.py # Unified CLI entrypoint (Typer & Rich)
227
+ โ”œโ”€โ”€ config_patcher.py # Automatic client config scanner & patcher
228
+ โ”œโ”€โ”€ firewall_cli.py # Standalone firewall CLI interface
229
+ โ”œโ”€โ”€ main.py # Top-level executable entry
230
+ โ”œโ”€โ”€ mcp_firewall_client.py # MCP Firewall client wrapper
231
+ โ”œโ”€โ”€ mcp_proxy.py # Transparent stdio MCP JSON-RPC proxy gateway
232
+ โ”œโ”€โ”€ runtime_firewall.py # Core 4-phase runtime security firewall engine
233
+ โ”œโ”€โ”€ sentinel_logger.py # Dual console/file & Grafana Loki logger
234
+ โ”œโ”€โ”€ pyproject.toml # Package metadata & build configuration
235
+ โ”œโ”€โ”€ README.md # Project documentation
236
+ โ”‚
237
+ โ”œโ”€โ”€ intent_analyser/ # Phase 1: Static & LLM semantic intent analysis
238
+ โ”‚ โ”œโ”€โ”€ static_analyser.py # AST & regex threat pattern matching
239
+ โ”‚ โ”œโ”€โ”€ semantic_analyser.py # Zero-dependency LLM caller (Ollama/OpenAI/Claude/Gemini/Groq)
240
+ โ”‚ โ””โ”€โ”€ schemas.py # Security intent schemas & data models
241
+ โ”‚
242
+ โ”œโ”€โ”€ quarantine_engine/ # Quarantine persistence & manual review workflow
243
+ โ”‚ โ”œโ”€โ”€ quarantine_engine/
244
+ โ”‚ โ”‚ โ”œโ”€โ”€ core.py # Quarantine manager core logic
245
+ โ”‚ โ”‚ โ”œโ”€โ”€ models.py # Quarantine & audit state models
246
+ โ”‚ โ”‚ โ”œโ”€โ”€ audit_log.py # Immutable audit logging engine
247
+ โ”‚ โ”‚ โ”œโ”€โ”€ version_store.py # Schema & tool version store
248
+ โ”‚ โ”‚ โ””โ”€โ”€ analyzer_integration.py# Firewall integration hook
249
+ โ”‚ โ””โ”€โ”€ tests/ # Quarantine unit test suite
250
+ โ”‚
251
+ โ”œโ”€โ”€ trust_betray/ # Phase 4: Post-execution drift & mimicry detection
252
+ โ”‚ โ”œโ”€โ”€ classifier.py # Threat classification engine
253
+ โ”‚ โ”œโ”€โ”€ drift.py # Statistical & semantic drift analyzer
254
+ โ”‚ โ”œโ”€โ”€ fingerprint.py # Behavioral fingerprinting
255
+ โ”‚ โ”œโ”€โ”€ store.py # Behavioral state storage
256
+ โ”‚ โ”œโ”€โ”€ timeline.py # Event timeline generator
257
+ โ”‚ โ””โ”€โ”€ attacks/ # Attack simulation modules (drift, mimicry, pivot)
258
+ โ”‚
259
+ โ””โ”€โ”€ tests/ # Comprehensive pytest test suite
260
+ โ”œโ”€โ”€ test_cli.py
261
+ โ”œโ”€โ”€ test_config_patcher.py
262
+ โ”œโ”€โ”€ test_firewall_cli.py
263
+ โ”œโ”€โ”€ test_intent_analyser.py
264
+ โ”œโ”€โ”€ test_intent_quarantine_integration.py
265
+ โ”œโ”€โ”€ test_mcp_firewall_client.py
266
+ โ”œโ”€โ”€ test_mcp_proxy.py
267
+ โ”œโ”€โ”€ test_runtime_firewall.py
268
+ โ”œโ”€โ”€ test_sentinel_logger.py
269
+ โ””โ”€โ”€ test_trust_betray.py
270
+ ```
271
+
272
+ ---
273
+
274
+ ## ๐Ÿงช Running Tests
275
+
276
+ Run the full pytest suite from the `mcpsentinel/` directory:
277
+
278
+ ```bash
279
+ # Using pytest directly
280
+ python3 -m pytest
281
+
282
+ # Or using uv
283
+ uv run --with pytest pytest
284
+ ```
@@ -0,0 +1,258 @@
1
+ # MCPSentinel
2
+
3
+ **Active Zero-Trust Runtime Security Firewall & Interceptor Gateway for AI Agent Tools & MCP Servers.**
4
+
5
+ MCPSentinel provides real-time security gating for Agentic tools and MCP servers across 4 critical lifecycle phases:
6
+ 1. **Pre-Registration Intent & Threat Inspection**: Static and semantic analysis detecting covert exfiltration, indirect prompt injection, privilege escalation, and schema manipulation.
7
+ 2. **Pre-Execution Argument Gating**: Sandboxing and runtime inspection blocking unauthorized path traversal, command injection, and sensitive parameter overrides.
8
+ 3. **Execution & Latency Profiling**: Tamper-proof telemetry profiling execution latency and outputs.
9
+ 4. **Post-Execution Behavioral Drift Verification**: Intercepts outputs and quarantines tools exhibiting sudden behavioral shifts, capability creep, or mimicry attacks.
10
+
11
+ ---
12
+
13
+ ## โšก 1-Click Auto-Protect for Claude Desktop, Cursor & Codex
14
+
15
+ Instead of manually editing JSON configs, MCPSentinel can **automatically detect, backup, and wrap** all configured MCP servers with one command:
16
+
17
+ ```bash
18
+ # Automatically scan & protect Claude Desktop, Cursor, and Codex / Claude Code configs
19
+ mcpsentinel protect
20
+
21
+ # Or target a specific application / config file
22
+ mcpsentinel protect --claude
23
+ mcpsentinel protect --cursor
24
+ mcpsentinel protect --codex
25
+ mcpsentinel protect --config /path/to/custom_mcp_config.json
26
+
27
+ # Restore / unwrap servers at any time
28
+ mcpsentinel unwrap
29
+ ```
30
+
31
+ ---
32
+
33
+ ## ๐Ÿ”’ Transparent MCP Proxy (`mcpsentinel wrap`)
34
+
35
+ MCPSentinel can transparently wrap any standard MCP server over stdio without any code modifications.
36
+
37
+ ### MCP Client Configuration (`claude_desktop_config.json`, Cursor, etc.)
38
+
39
+ ```json
40
+ {
41
+ "mcpServers": {
42
+ "filesystem": {
43
+ "command": "mcpsentinel",
44
+ "args": ["wrap", "npx", "@modelcontextprotocol/server-filesystem", "/workspace"]
45
+ },
46
+ "custom_server": {
47
+ "command": "mcpsentinel",
48
+ "args": ["wrap", "python3", "my_mcp_server.py"]
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ When wrapped, MCPSentinel automatically:
55
+ - Intercepts `tools/list` with zero startup handshake latency by caching tool definitions without eager evaluation.
56
+ - Intercepts `tools/call` requests with JIT Intent & Security Analysis upon first call, blocking malicious schemas, sensitive parameter overrides (e.g. `/etc/shadow`), and quarantined tools fail-fast before execution.
57
+ - Intercepts `tools/call` responses, detecting prompt injections and behavioral drift to suppress malicious payloads before they reach the LLM.
58
+
59
+ ---
60
+
61
+ ## ๐Ÿ“Š Structured Logging & Telemetry (Loguru & Loki)
62
+
63
+ MCPSentinel provides dual real-time and persistent telemetry:
64
+
65
+ - **Stdio Safe**: Real-time console logs are streamed exclusively to `sys.stderr`, ensuring MCP JSON-RPC protocol messages over `stdout` are never corrupted.
66
+ - **Persistent Local Logs**:
67
+ - Formatted text log: `~/.mcpsentinel/logs/mcpsentinel.log` (automatic 10MB rotation, 14-day retention).
68
+ - Structured JSONL log: `~/.mcpsentinel/logs/mcpsentinel.jsonl` (machine-readable SIEM format).
69
+ - **Grafana Loki Streaming**: Set `MCPSENTINEL_LOKI_URL="http://localhost:3100"` to stream telemetry asynchronously in background daemon threads.
70
+
71
+ ```bash
72
+ # Stream live logs with the built-in CLI monitor
73
+ mcpsentinel logs
74
+
75
+ # Follow only ERROR / WARNING logs
76
+ mcpsentinel logs --level ERROR
77
+
78
+ # View last 50 lines without following
79
+ mcpsentinel logs --no-follow -n 50
80
+
81
+ # Stream raw structured JSONL SIEM events
82
+ mcpsentinel logs --json
83
+
84
+ # Clear stored logs
85
+ mcpsentinel logs --clear
86
+ ```
87
+
88
+ ---
89
+
90
+ ## ๐Ÿ› ๏ธ Python SDK Usage
91
+
92
+ You can also protect native Python tools and functions directly using the `@firewall.protect` decorator:
93
+
94
+ ```python
95
+ from mcpsentinel import RuntimeFirewall
96
+
97
+ firewall = RuntimeFirewall()
98
+
99
+ @firewall.protect()
100
+ def query_database(query: str) -> dict:
101
+ """Executes a database query."""
102
+ return {"status": "success", "rows": []}
103
+
104
+ # Calls are gated through pre-call checks and post-call drift verification
105
+ result = query_database(query="SELECT * FROM users")
106
+ ```
107
+
108
+ ---
109
+
110
+ ## ๐Ÿ’ป CLI Usage
111
+
112
+ MCPSentinel includes a full CLI powered by **Typer** and **Rich**.
113
+
114
+ ### Installation
115
+
116
+ ```bash
117
+ # Global installation via pipx / pip
118
+ pip install mcpsentinel
119
+ # or
120
+ pipx install mcpsentinel
121
+
122
+ # Or for local development:
123
+ pip install -e .
124
+ ```
125
+
126
+ ---
127
+
128
+ ### Commands Overview
129
+
130
+ #### 1. Transparent MCP Server Wrap (`mcpsentinel wrap`)
131
+ ```bash
132
+ mcpsentinel wrap npx @modelcontextprotocol/server-filesystem /tmp
133
+ ```
134
+
135
+ #### 2. Auto-Protect MCP Client Configurations (`mcpsentinel protect`)
136
+ ```bash
137
+ mcpsentinel protect --claude
138
+ mcpsentinel protect --cursor
139
+ mcpsentinel protect --codex
140
+ ```
141
+
142
+ #### 3. Inspect / Analyze Tool Security (`mcpsentinel inspect`)
143
+ ```bash
144
+ # Inspect via JSON string
145
+ mcpsentinel inspect --tool-json '{"name": "search_docs", "description": "Search public docs", "parameters": {"query": "string"}}'
146
+
147
+ # Inspect via JSON file
148
+ mcpsentinel inspect --file tool_definition.json
149
+ ```
150
+
151
+ #### 4. Execute / Call Tools Through Firewall (`mcpsentinel call`)
152
+ ```bash
153
+ # Call a safe tool
154
+ mcpsentinel call search_docs --tool-json '{"name": "search_docs"}' --arguments '{"query": "firewall"}'
155
+
156
+ # Malicious arguments will be blocked fail-fast
157
+ mcpsentinel call read_file --tool-json '{"name": "read_file"}' --arguments '{"path": "/etc/shadow"}'
158
+ ```
159
+
160
+ #### 5. Manually Approve Blocked Tools (`mcpsentinel approve`)
161
+ ```bash
162
+ mcpsentinel approve fetch_notes --operator alice --reviewer-note "Approved for restricted debug environment"
163
+ ```
164
+
165
+ #### 6. Quarantine Management (`mcpsentinel quarantine`)
166
+ ```bash
167
+ # List all quarantined tools
168
+ mcpsentinel quarantine list
169
+
170
+ # Check status of a specific tool
171
+ mcpsentinel quarantine status fetch_notes
172
+
173
+ # Release a tool from quarantine
174
+ mcpsentinel quarantine release fetch_notes --operator admin --reviewer-note "Audit resolved"
175
+ ```
176
+
177
+ #### 7. Audit Trail (`mcpsentinel audit`)
178
+ ```bash
179
+ mcpsentinel audit logs --limit 20
180
+ ```
181
+
182
+ #### 8. Live Log Monitoring (`mcpsentinel logs` / `mcpsentinel monitor`)
183
+ ```bash
184
+ # Follow formatted live logs
185
+ mcpsentinel logs
186
+
187
+ # Filter by log level
188
+ mcpsentinel logs --level WARNING
189
+
190
+ # Output in JSON format
191
+ mcpsentinel logs --json
192
+ ```
193
+
194
+ ---
195
+
196
+ ## ๐Ÿ“ Project Structure
197
+
198
+ ```text
199
+ mcpsentinel/
200
+ โ”œโ”€โ”€ cli.py # Unified CLI entrypoint (Typer & Rich)
201
+ โ”œโ”€โ”€ config_patcher.py # Automatic client config scanner & patcher
202
+ โ”œโ”€โ”€ firewall_cli.py # Standalone firewall CLI interface
203
+ โ”œโ”€โ”€ main.py # Top-level executable entry
204
+ โ”œโ”€โ”€ mcp_firewall_client.py # MCP Firewall client wrapper
205
+ โ”œโ”€โ”€ mcp_proxy.py # Transparent stdio MCP JSON-RPC proxy gateway
206
+ โ”œโ”€โ”€ runtime_firewall.py # Core 4-phase runtime security firewall engine
207
+ โ”œโ”€โ”€ sentinel_logger.py # Dual console/file & Grafana Loki logger
208
+ โ”œโ”€โ”€ pyproject.toml # Package metadata & build configuration
209
+ โ”œโ”€โ”€ README.md # Project documentation
210
+ โ”‚
211
+ โ”œโ”€โ”€ intent_analyser/ # Phase 1: Static & LLM semantic intent analysis
212
+ โ”‚ โ”œโ”€โ”€ static_analyser.py # AST & regex threat pattern matching
213
+ โ”‚ โ”œโ”€โ”€ semantic_analyser.py # Zero-dependency LLM caller (Ollama/OpenAI/Claude/Gemini/Groq)
214
+ โ”‚ โ””โ”€โ”€ schemas.py # Security intent schemas & data models
215
+ โ”‚
216
+ โ”œโ”€โ”€ quarantine_engine/ # Quarantine persistence & manual review workflow
217
+ โ”‚ โ”œโ”€โ”€ quarantine_engine/
218
+ โ”‚ โ”‚ โ”œโ”€โ”€ core.py # Quarantine manager core logic
219
+ โ”‚ โ”‚ โ”œโ”€โ”€ models.py # Quarantine & audit state models
220
+ โ”‚ โ”‚ โ”œโ”€โ”€ audit_log.py # Immutable audit logging engine
221
+ โ”‚ โ”‚ โ”œโ”€โ”€ version_store.py # Schema & tool version store
222
+ โ”‚ โ”‚ โ””โ”€โ”€ analyzer_integration.py# Firewall integration hook
223
+ โ”‚ โ””โ”€โ”€ tests/ # Quarantine unit test suite
224
+ โ”‚
225
+ โ”œโ”€โ”€ trust_betray/ # Phase 4: Post-execution drift & mimicry detection
226
+ โ”‚ โ”œโ”€โ”€ classifier.py # Threat classification engine
227
+ โ”‚ โ”œโ”€โ”€ drift.py # Statistical & semantic drift analyzer
228
+ โ”‚ โ”œโ”€โ”€ fingerprint.py # Behavioral fingerprinting
229
+ โ”‚ โ”œโ”€โ”€ store.py # Behavioral state storage
230
+ โ”‚ โ”œโ”€โ”€ timeline.py # Event timeline generator
231
+ โ”‚ โ””โ”€โ”€ attacks/ # Attack simulation modules (drift, mimicry, pivot)
232
+ โ”‚
233
+ โ””โ”€โ”€ tests/ # Comprehensive pytest test suite
234
+ โ”œโ”€โ”€ test_cli.py
235
+ โ”œโ”€โ”€ test_config_patcher.py
236
+ โ”œโ”€โ”€ test_firewall_cli.py
237
+ โ”œโ”€โ”€ test_intent_analyser.py
238
+ โ”œโ”€โ”€ test_intent_quarantine_integration.py
239
+ โ”œโ”€โ”€ test_mcp_firewall_client.py
240
+ โ”œโ”€โ”€ test_mcp_proxy.py
241
+ โ”œโ”€โ”€ test_runtime_firewall.py
242
+ โ”œโ”€โ”€ test_sentinel_logger.py
243
+ โ””โ”€โ”€ test_trust_betray.py
244
+ ```
245
+
246
+ ---
247
+
248
+ ## ๐Ÿงช Running Tests
249
+
250
+ Run the full pytest suite from the `mcpsentinel/` directory:
251
+
252
+ ```bash
253
+ # Using pytest directly
254
+ python3 -m pytest
255
+
256
+ # Or using uv
257
+ uv run --with pytest pytest
258
+ ```