mcp-shield-cli 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 (85) hide show
  1. mcp_shield_cli-0.1.0/.gitignore +19 -0
  2. mcp_shield_cli-0.1.0/LICENSE +190 -0
  3. mcp_shield_cli-0.1.0/PKG-INFO +318 -0
  4. mcp_shield_cli-0.1.0/README.md +282 -0
  5. mcp_shield_cli-0.1.0/pyproject.toml +73 -0
  6. mcp_shield_cli-0.1.0/src/mcp_shield/__init__.py +3 -0
  7. mcp_shield_cli-0.1.0/src/mcp_shield/audit/__init__.py +5 -0
  8. mcp_shield_cli-0.1.0/src/mcp_shield/classification/__init__.py +5 -0
  9. mcp_shield_cli-0.1.0/src/mcp_shield/classification/risk.py +197 -0
  10. mcp_shield_cli-0.1.0/src/mcp_shield/cli/__init__.py +1 -0
  11. mcp_shield_cli-0.1.0/src/mcp_shield/cli/audit_cmd.py +288 -0
  12. mcp_shield_cli-0.1.0/src/mcp_shield/cli/main.py +33 -0
  13. mcp_shield_cli-0.1.0/src/mcp_shield/cli/proxy_cmd.py +141 -0
  14. mcp_shield_cli-0.1.0/src/mcp_shield/cli/test_cmd.py +213 -0
  15. mcp_shield_cli-0.1.0/src/mcp_shield/client/__init__.py +8 -0
  16. mcp_shield_cli-0.1.0/src/mcp_shield/client/connection.py +224 -0
  17. mcp_shield_cli-0.1.0/src/mcp_shield/models/__init__.py +9 -0
  18. mcp_shield_cli-0.1.0/src/mcp_shield/models/enums.py +26 -0
  19. mcp_shield_cli-0.1.0/src/mcp_shield/models/mcp_types.py +53 -0
  20. mcp_shield_cli-0.1.0/src/mcp_shield/proxy/__init__.py +6 -0
  21. mcp_shield_cli-0.1.0/src/mcp_shield/proxy/middleware.py +104 -0
  22. mcp_shield_cli-0.1.0/src/mcp_shield/proxy/server.py +485 -0
  23. mcp_shield_cli-0.1.0/src/mcp_shield/reporting/__init__.py +4 -0
  24. mcp_shield_cli-0.1.0/src/mcp_shield/reporting/json_report.py +95 -0
  25. mcp_shield_cli-0.1.0/src/mcp_shield/reporting/recommendations.py +309 -0
  26. mcp_shield_cli-0.1.0/src/mcp_shield/reporting/score.py +86 -0
  27. mcp_shield_cli-0.1.0/src/mcp_shield/reporting/terminal.py +144 -0
  28. mcp_shield_cli-0.1.0/src/mcp_shield/security/__init__.py +17 -0
  29. mcp_shield_cli-0.1.0/src/mcp_shield/security/base.py +119 -0
  30. mcp_shield_cli-0.1.0/src/mcp_shield/security/cost_risk.py +115 -0
  31. mcp_shield_cli-0.1.0/src/mcp_shield/security/dangerous_ops.py +242 -0
  32. mcp_shield_cli-0.1.0/src/mcp_shield/security/idempotency.py +84 -0
  33. mcp_shield_cli-0.1.0/src/mcp_shield/security/injection.py +231 -0
  34. mcp_shield_cli-0.1.0/src/mcp_shield/security/ml_detector.py +318 -0
  35. mcp_shield_cli-0.1.0/src/mcp_shield/security/poisoning.py +410 -0
  36. mcp_shield_cli-0.1.0/src/mcp_shield/security/rug_pull.py +100 -0
  37. mcp_shield_cli-0.1.0/src/mcp_shield/security/scanner.py +186 -0
  38. mcp_shield_cli-0.1.0/src/mcp_shield/security/text_extractor.py +94 -0
  39. mcp_shield_cli-0.1.0/src/mcp_shield/security/write_scope.py +118 -0
  40. mcp_shield_cli-0.1.0/src/mcp_shield/storage/__init__.py +10 -0
  41. mcp_shield_cli-0.1.0/src/mcp_shield/storage/audit_db.py +327 -0
  42. mcp_shield_cli-0.1.0/src/mcp_shield/testing/__init__.py +5 -0
  43. mcp_shield_cli-0.1.0/src/mcp_shield/testing/context.py +34 -0
  44. mcp_shield_cli-0.1.0/src/mcp_shield/testing/registry.py +46 -0
  45. mcp_shield_cli-0.1.0/src/mcp_shield/testing/result.py +71 -0
  46. mcp_shield_cli-0.1.0/src/mcp_shield/testing/runner.py +162 -0
  47. mcp_shield_cli-0.1.0/src/mcp_shield/testing/suites/__init__.py +1 -0
  48. mcp_shield_cli-0.1.0/src/mcp_shield/testing/suites/advisory.py +309 -0
  49. mcp_shield_cli-0.1.0/src/mcp_shield/testing/suites/compliance.py +453 -0
  50. mcp_shield_cli-0.1.0/src/mcp_shield/testing/suites/security.py +221 -0
  51. mcp_shield_cli-0.1.0/tests/__init__.py +0 -0
  52. mcp_shield_cli-0.1.0/tests/batch/run_batch.py +332 -0
  53. mcp_shield_cli-0.1.0/tests/e2e/__init__.py +0 -0
  54. mcp_shield_cli-0.1.0/tests/e2e/conftest.py +52 -0
  55. mcp_shield_cli-0.1.0/tests/e2e/servers/__init__.py +0 -0
  56. mcp_shield_cli-0.1.0/tests/e2e/servers/basic_server.py +121 -0
  57. mcp_shield_cli-0.1.0/tests/e2e/servers/rugpull_server.py +74 -0
  58. mcp_shield_cli-0.1.0/tests/e2e/test_proxy_e2e.py +204 -0
  59. mcp_shield_cli-0.1.0/tests/e2e/test_real_everything_server.py +287 -0
  60. mcp_shield_cli-0.1.0/tests/e2e/test_real_fs_server.py +258 -0
  61. mcp_shield_cli-0.1.0/tests/e2e/test_rugpull_e2e.py +130 -0
  62. mcp_shield_cli-0.1.0/tests/fixtures/__init__.py +0 -0
  63. mcp_shield_cli-0.1.0/tests/integration/__init__.py +0 -0
  64. mcp_shield_cli-0.1.0/tests/unit/__init__.py +0 -0
  65. mcp_shield_cli-0.1.0/tests/unit/test_advisory.py +192 -0
  66. mcp_shield_cli-0.1.0/tests/unit/test_audit_db.py +263 -0
  67. mcp_shield_cli-0.1.0/tests/unit/test_cli.py +344 -0
  68. mcp_shield_cli-0.1.0/tests/unit/test_connection.py +315 -0
  69. mcp_shield_cli-0.1.0/tests/unit/test_cost_risk.py +75 -0
  70. mcp_shield_cli-0.1.0/tests/unit/test_dangerous_ops.py +233 -0
  71. mcp_shield_cli-0.1.0/tests/unit/test_idempotency.py +108 -0
  72. mcp_shield_cli-0.1.0/tests/unit/test_injection.py +486 -0
  73. mcp_shield_cli-0.1.0/tests/unit/test_json_report.py +150 -0
  74. mcp_shield_cli-0.1.0/tests/unit/test_middleware.py +237 -0
  75. mcp_shield_cli-0.1.0/tests/unit/test_ml_detector.py +350 -0
  76. mcp_shield_cli-0.1.0/tests/unit/test_poisoning.py +766 -0
  77. mcp_shield_cli-0.1.0/tests/unit/test_proxy_server.py +460 -0
  78. mcp_shield_cli-0.1.0/tests/unit/test_recommendations.py +558 -0
  79. mcp_shield_cli-0.1.0/tests/unit/test_registry.py +55 -0
  80. mcp_shield_cli-0.1.0/tests/unit/test_result.py +165 -0
  81. mcp_shield_cli-0.1.0/tests/unit/test_risk_classifier.py +287 -0
  82. mcp_shield_cli-0.1.0/tests/unit/test_rug_pull.py +275 -0
  83. mcp_shield_cli-0.1.0/tests/unit/test_scanner.py +281 -0
  84. mcp_shield_cli-0.1.0/tests/unit/test_score.py +201 -0
  85. mcp_shield_cli-0.1.0/tests/unit/test_write_scope.py +79 -0
@@ -0,0 +1,19 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ *.egg
9
+ .venv/
10
+ venv/
11
+ .mypy_cache/
12
+ .ruff_cache/
13
+ .pytest_cache/
14
+ htmlcov/
15
+ .coverage
16
+ *.db
17
+ *.sqlite
18
+ .uv/
19
+ uv.lock
@@ -0,0 +1,190 @@
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 the 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 the 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 Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 MCP Shield Contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,318 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-shield-cli
3
+ Version: 0.1.0
4
+ Summary: Security scanner, runtime proxy, and audit logger for MCP servers
5
+ Project-URL: Homepage, https://github.com/thuggeelya/mcp-shield
6
+ Project-URL: Repository, https://github.com/thuggeelya/mcp-shield
7
+ Project-URL: Issues, https://github.com/thuggeelya/mcp-shield/issues
8
+ Author-email: thuggeelya <thuggeelya@gmail.com>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: audit,mcp,model-context-protocol,proxy,security,testing
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Security
20
+ Classifier: Topic :: Software Development :: Testing
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: click>=8.1
23
+ Requires-Dist: huggingface-hub>=0.24
24
+ Requires-Dist: mcp>=1.0.0
25
+ Requires-Dist: onnxruntime>=1.18
26
+ Requires-Dist: pydantic>=2.0
27
+ Requires-Dist: pyyaml>=6.0
28
+ Requires-Dist: rich>=13.0
29
+ Requires-Dist: tokenizers>=0.20
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
32
+ Requires-Dist: pytest-timeout>=2.3; extra == 'dev'
33
+ Requires-Dist: pytest>=8.0; extra == 'dev'
34
+ Requires-Dist: ruff>=0.6; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # MCP Shield
38
+
39
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
40
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
41
+
42
+ Like [Bandit](https://github.com/PyCQA/bandit) for Python code, but for MCP servers.
43
+
44
+ Security scanner, runtime proxy, and audit logger for [Model Context Protocol](https://modelcontextprotocol.io/) servers.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install mcp-shield-cli
50
+ ```
51
+
52
+ Requires Python 3.11+ and Node.js (for npx-based MCP servers).
53
+
54
+ ## Usage
55
+
56
+ ### `mcp-shield test` — scan a server
57
+
58
+ ```bash
59
+ # Scan a local stdio server
60
+ mcp-shield test "npx -y @modelcontextprotocol/server-filesystem /tmp"
61
+
62
+ # Scan a remote HTTP server
63
+ mcp-shield test "http://localhost:8080/mcp"
64
+
65
+ # Run only specific suites (compliance, security, advisory, or all)
66
+ mcp-shield test "npx server" --suite security
67
+ mcp-shield test "npx server" --suite security --suite advisory
68
+
69
+ # Pass environment variables to the server process
70
+ mcp-shield test "npx server" --env API_KEY=sk-123 --env DB_URL=postgres://host/db
71
+
72
+ # Save JSON report to file
73
+ mcp-shield test "npx server" --output report.json
74
+
75
+ # JSON to stdout (for piping)
76
+ mcp-shield test "npx server" --format json
77
+
78
+ # Both terminal and JSON output
79
+ mcp-shield test "npx server" --format both --output report.json
80
+
81
+ # CI mode: exit code 1 if any high+ severity check fails
82
+ mcp-shield test "npx server" --fail-on high
83
+
84
+ # Enable ML-based poisoning detection (DeBERTa, slower but more accurate)
85
+ mcp-shield test "npx server" --ml
86
+
87
+ # Set connection/check timeout (default 30s)
88
+ mcp-shield test "npx server" --timeout 10
89
+ ```
90
+
91
+ Example output:
92
+
93
+ ```
94
+ Check | Result | Severity | Message
95
+ COMP-001 | PASS | critical | Handshake OK
96
+ COMP-002 | PASS | error | Server identity: filesystem-server v0.2.0
97
+ SEC-002 | WARN | high | Found 11 potential injection vector(s)
98
+ SEC-004 | FAIL | high | 2 dangerous tool(s): move_file, edit_file
99
+ SEC-005 | WARN | medium | Write scope: local filesystem
100
+ ADV-002 | WARN | info | External dependencies: filesystem access
101
+
102
+ Score: 57/100 Grade: D
103
+
104
+ ─────────────── Recommendations ───────────────
105
+
106
+ [1] Block dangerous tools (SEC-004)
107
+ Tools: move_file, edit_file
108
+ Action: Add --deny rules in proxy or require user confirmation
109
+
110
+ ┌──── Ready-to-use proxy command ────┐
111
+ │ mcp-shield proxy "npx ..." \ │
112
+ │ --deny move_file --deny edit_file│
113
+ └────────────────────────────────────┘
114
+ ```
115
+
116
+ ### `mcp-shield proxy` — runtime firewall
117
+
118
+ ```bash
119
+ # Block specific tools by name (glob patterns)
120
+ mcp-shield proxy "npx server" --deny "delete_*" --deny "exec_*"
121
+
122
+ # Allow only safe tools (everything else is blocked)
123
+ mcp-shield proxy "npx server" --allow "read_*" --allow "list_*"
124
+
125
+ # Rate-limit to 30 requests/minute per client
126
+ mcp-shield proxy "npx server" --rate-limit 30
127
+
128
+ # Custom audit database path
129
+ mcp-shield proxy "npx server" --audit-db ./my-audit.db
130
+
131
+ # Require authentication
132
+ mcp-shield proxy "npx server" --auth bearer --token admin:secret123
133
+ mcp-shield proxy "npx server" --auth bearer --token alice:tok-a --token bob:tok-b
134
+
135
+ # Combine everything: deny + rate limit + auth + env
136
+ mcp-shield proxy "npx server" \
137
+ --deny "git_push" --deny "git_reset" \
138
+ --rate-limit 30 \
139
+ --auth bearer --token ci:token123 \
140
+ --env GITHUB_TOKEN=ghp_xxx
141
+
142
+ # Proxy a remote HTTP server
143
+ mcp-shield proxy "http://upstream:9090/mcp" --deny "drop_*"
144
+ ```
145
+
146
+ The proxy sits between the LLM client and the MCP server:
147
+
148
+ ```
149
+ LLM Client ──stdio──▶ mcp-shield proxy ──stdio──▶ MCP Server
150
+
151
+ ┌─────┴─────┐
152
+ │ deny list │
153
+ │ rate limit│
154
+ │ auth check│
155
+ │ audit log │
156
+ └───────────┘
157
+ ```
158
+
159
+ Blocked calls return an error to the client and are logged with the block reason.
160
+
161
+ ### `mcp-shield audit` — query logs
162
+
163
+ ```bash
164
+ # Show last 50 events (default)
165
+ mcp-shield audit show
166
+
167
+ # Show last 100 events
168
+ mcp-shield audit show --last 100
169
+
170
+ # Filter by tool name
171
+ mcp-shield audit show --tool delete_file
172
+
173
+ # Show only blocked calls
174
+ mcp-shield audit show --blocked
175
+
176
+ # Filter by risk tier (read, write_reversible, write_external, write_sensitive)
177
+ mcp-shield audit show --risk write_sensitive
178
+
179
+ # Filter by client ID (when using --auth)
180
+ mcp-shield audit show --client admin
181
+
182
+ # Combine filters
183
+ mcp-shield audit show --blocked --risk write_sensitive --last 20
184
+ ```
185
+
186
+ ```bash
187
+ # Summary statistics (default: last 24 hours)
188
+ mcp-shield audit stats
189
+
190
+ # Stats for a time range (h=hours, d=days, w=weeks, m=months)
191
+ mcp-shield audit stats --since 1h
192
+ mcp-shield audit stats --since 7d
193
+ mcp-shield audit stats --since 4w
194
+ ```
195
+
196
+ ```bash
197
+ # Export to JSON
198
+ mcp-shield audit export -f json -o audit.json
199
+
200
+ # Export to CSV
201
+ mcp-shield audit export -f csv -o audit.csv
202
+ ```
203
+
204
+ ```bash
205
+ # Use a custom database path (applies to all subcommands)
206
+ mcp-shield audit --db /path/to/audit.db show --last 20
207
+ mcp-shield audit --db /path/to/audit.db stats --since 7d
208
+ ```
209
+
210
+ ## What it checks
211
+
212
+ 22 checks across 3 suites, ~2 seconds per scan.
213
+
214
+ ### Compliance (COMP-001..010)
215
+
216
+ | Check | What it verifies |
217
+ |-------|-----------------|
218
+ | COMP-001 | MCP handshake (JSON-RPC initialize) |
219
+ | COMP-002 | Server identity (name + version) |
220
+ | COMP-003 | Valid `inputSchema` on all tools |
221
+ | COMP-004 | Tool naming conventions |
222
+ | COMP-005 | Ping/pong support |
223
+ | COMP-006 | Tool descriptions present |
224
+ | COMP-007 | Server capabilities declared |
225
+ | COMP-008 | Schema field descriptions |
226
+ | COMP-009 | Schema constraints (`maxLength`, `pattern`) |
227
+ | COMP-010 | Resource/prompt validation |
228
+
229
+ ### Security (SEC-001..007)
230
+
231
+ | Check | What it detects | Severity |
232
+ |-------|----------------|----------|
233
+ | SEC-001 | Tool poisoning (hidden instructions in descriptions) | critical |
234
+ | SEC-002 | Injection vectors (path, URL, SQL, code fields) | high |
235
+ | SEC-003 | Aggregated security score (0-100) | -- |
236
+ | SEC-004 | Dangerous operations (`delete`, `exec`, `deploy`) | high |
237
+ | SEC-005 | Write scope (local vs cloud vs user-facing) | medium |
238
+ | SEC-006 | Idempotency risk (non-retryable operations) | medium |
239
+ | SEC-007 | Cost risk (cloud provisioning, paid APIs) | low |
240
+
241
+ ### Advisory (ADV-001..005)
242
+
243
+ Informational only — does not affect the score.
244
+
245
+ | Check | What it flags |
246
+ |-------|--------------|
247
+ | ADV-001 | Auth requirement hints (API key, OAuth) |
248
+ | ADV-002 | External service dependencies (AWS, Stripe, GitHub) |
249
+ | ADV-003 | Bulk operation warnings (unbounded arrays) |
250
+ | ADV-004 | Sensitive data exposure (PII, credentials) |
251
+ | ADV-005 | External network access (URL + fetch patterns) |
252
+
253
+ ### Scoring
254
+
255
+ Composite score: **40% compliance + 60% security**. Deductions per finding:
256
+
257
+ | Severity | Deduction |
258
+ |----------|-----------|
259
+ | critical | -25 |
260
+ | high | -15 |
261
+ | medium | -5 |
262
+ | low | -2 |
263
+
264
+ Advisory checks are informational and do not affect the score.
265
+
266
+ ### Poisoning detection
267
+
268
+ **Layer 1** — ~45 regex patterns across 11 categories:
269
+
270
+ | Category | Examples |
271
+ |----------|----------|
272
+ | Instruction override | "ignore previous instructions", "new instructions:" |
273
+ | Role hijacking | "act as", "pretend to be", "you are now" |
274
+ | Format injection | ChatML `<\|im_start\|>`, Llama `[INST]`, Handlebars `{{#system}}` |
275
+ | Data exfiltration | Markdown image exfil, "send to URL", credential reading |
276
+ | Hidden content | HTML comments, CSS `display:none`, ANSI escapes, zero-width Unicode |
277
+ | Hardcoded secrets | API keys (`sk-live-*`), GitHub PATs, Slack tokens |
278
+ | Agent injection | ReAct format injection, tool call injection |
279
+
280
+ **Layer 2** (opt-in, `--ml`) — DeBERTa-v3-base classifier for semantic detection.
281
+
282
+ ML dependencies (`onnxruntime`, `tokenizers`, `huggingface-hub`) are included in the default install. The `--ml` flag downloads the [protectai/deberta-v3-base-prompt-injection-v2](https://huggingface.co/protectai/deberta-v3-base-prompt-injection-v2) ONNX model (~740 MB, cached in `~/.cache/mcp-shield/models/`) on first use.
283
+
284
+ **Why opt-in?** The ML classifier can produce false positives on directive-like tool descriptions (e.g., "DEPRECATED: Use X instead" may be flagged as an injection). Use `--ml` when you want maximum detection sensitivity and can tolerate reviewing flagged results.
285
+
286
+ ### Risk classification
287
+
288
+ Every tool is classified into a risk tier:
289
+
290
+ | Tier | Examples |
291
+ |------|----------|
292
+ | `read` | read_file, list_directory, search |
293
+ | `write_reversible` | write_file, create_directory |
294
+ | `write_external` | send_email, deploy, webhook |
295
+ | `write_sensitive` | delete, exec, eval, drop |
296
+
297
+ ## Contributing
298
+
299
+ Contributions are welcome. Open an issue or submit a pull request.
300
+
301
+ ```bash
302
+ git clone https://github.com/thuggeelya/mcp-shield.git
303
+ cd mcp-shield
304
+ pip install -e ".[dev]"
305
+ pytest
306
+ ```
307
+
308
+ ## Author
309
+
310
+ **thuggeelya**
311
+
312
+ - LinkedIn: [thuggeelya](https://www.linkedin.com/in/thuggeelya/)
313
+ - Telegram: [@thuggeelya](https://t.me/thuggeelya)
314
+ - Email: [thuggeelya@gmail.com](mailto:thuggeelya@gmail.com)
315
+
316
+ ## License
317
+
318
+ [Apache 2.0](LICENSE)