mcpwall 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Dom Behrens and mcpwall contributors
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # mcpwall
2
+
3
+ Deterministic security proxy for [MCP](https://modelcontextprotocol.io) tool calls. Sits between your AI coding tool (Claude Code, Cursor, Windsurf) and MCP servers, intercepting every JSON-RPC message and enforcing YAML-defined policies — no LLM, no cloud, pure rule-based.
4
+
5
+ Think **iptables**, but for MCP tool calls.
6
+
7
+ ## Why
8
+
9
+ MCP servers have full access to your filesystem, shell, databases, and APIs. When an AI agent calls `tools/call`, the server executes whatever the agent asks — reading SSH keys, running `rm -rf`, exfiltrating secrets. There's no built-in policy layer.
10
+
11
+ mcpwall adds one. It's a transparent stdio proxy that:
12
+
13
+ - **Blocks sensitive file access** — `.ssh/`, `.env`, credentials, browser data
14
+ - **Blocks dangerous commands** — `rm -rf`, pipe-to-shell, reverse shells
15
+ - **Scans for secret leakage** — API keys, tokens, private keys (regex + entropy)
16
+ - **Logs everything** — JSON Lines audit trail of every tool call
17
+ - **Uses zero AI** — deterministic rules, no LLM decisions, no cloud calls
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install -g mcpwall
23
+ ```
24
+
25
+ Or use directly with npx:
26
+
27
+ ```bash
28
+ npx mcpwall -- npx -y @modelcontextprotocol/server-filesystem /path/to/dir
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ### Option 1: Interactive setup
34
+
35
+ ```bash
36
+ npx mcpwall init
37
+ ```
38
+
39
+ This finds your existing MCP servers in `~/.claude.json` or `.mcp.json` and wraps them.
40
+
41
+ ### Option 2: Manual wrapping
42
+
43
+ Change your MCP config from:
44
+
45
+ ```json
46
+ {
47
+ "mcpServers": {
48
+ "filesystem": {
49
+ "command": "npx",
50
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects"]
51
+ }
52
+ }
53
+ }
54
+ ```
55
+
56
+ To:
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "filesystem": {
62
+ "command": "npx",
63
+ "args": [
64
+ "-y", "mcpwall", "--",
65
+ "npx", "-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects"
66
+ ]
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ ### Option 3: Wrap a specific server
73
+
74
+ ```bash
75
+ npx mcpwall wrap filesystem
76
+ ```
77
+
78
+ ## How It Works
79
+
80
+ ```
81
+ ┌──────────────┐ stdio ┌──────────────┐ stdio ┌──────────────┐
82
+ │ Claude Code │ ──────────▶ │ MCP Firewall │ ──────────▶ │ Real MCP │
83
+ │ (MCP Host) │ ◀────────── │ (proxy) │ ◀────────── │ Server │
84
+ └──────────────┘ └──────────────┘ └──────────────┘
85
+ ```
86
+
87
+ 1. Intercepts every JSON-RPC message on stdin/stdout
88
+ 2. Parses `tools/call` requests — extracts tool name and arguments
89
+ 3. Walks rules top-to-bottom, first match wins
90
+ 4. **Allow**: forward to real server
91
+ 5. **Deny**: return JSON-RPC error to host, log, do not forward
92
+ 6. Responses from server are forwarded back transparently
93
+
94
+ ## Configuration
95
+
96
+ Config is YAML. mcpwall looks for:
97
+
98
+ 1. `~/.mcpwall/config.yml` (global)
99
+ 2. `.mcpwall.yml` (project, overrides global)
100
+
101
+ If neither exists, built-in default rules apply.
102
+
103
+ ### Example config
104
+
105
+ ```yaml
106
+ version: 1
107
+
108
+ settings:
109
+ log_dir: ~/.mcpwall/logs
110
+ log_level: info # debug | info | warn | error
111
+ default_action: allow # allow | deny | ask
112
+
113
+ rules:
114
+ # Block reading SSH keys
115
+ - name: block-ssh-keys
116
+ match:
117
+ method: tools/call
118
+ tool: "*"
119
+ arguments:
120
+ _any_value:
121
+ regex: "(\\.ssh/|id_rsa|id_ed25519)"
122
+ action: deny
123
+ message: "Blocked: access to SSH keys"
124
+
125
+ # Block dangerous shell commands
126
+ - name: block-dangerous-commands
127
+ match:
128
+ method: tools/call
129
+ tool: "*"
130
+ arguments:
131
+ _any_value:
132
+ regex: "(rm\\s+-rf|curl.*\\|.*bash)"
133
+ action: deny
134
+ message: "Blocked: dangerous command"
135
+
136
+ # Block writes outside project directory
137
+ - name: block-external-writes
138
+ match:
139
+ method: tools/call
140
+ tool: write_file
141
+ arguments:
142
+ path:
143
+ not_under: "${PROJECT_DIR}"
144
+ action: deny
145
+
146
+ # Scan all tool calls for leaked secrets
147
+ - name: block-secret-leakage
148
+ match:
149
+ method: tools/call
150
+ tool: "*"
151
+ arguments:
152
+ _any_value:
153
+ secrets: true
154
+ action: deny
155
+ message: "Blocked: detected secret in arguments"
156
+
157
+ secrets:
158
+ patterns:
159
+ - name: aws-access-key
160
+ regex: "AKIA[0-9A-Z]{16}"
161
+ - name: github-token
162
+ regex: "(gh[ps]_[A-Za-z0-9_]{36,}|github_pat_[A-Za-z0-9_]{22,})"
163
+ - name: private-key
164
+ regex: "-----BEGIN (RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----"
165
+ - name: generic-high-entropy
166
+ regex: "[A-Za-z0-9/+=]{40}"
167
+ entropy_threshold: 4.5
168
+ ```
169
+
170
+ ### Rule matchers
171
+
172
+ | Matcher | Description |
173
+ |---------|-------------|
174
+ | `regex` | Regular expression test on the value |
175
+ | `pattern` | Glob pattern (uses [minimatch](https://github.com/isaacs/minimatch)) |
176
+ | `not_under` | Matches if path is NOT under the given directory. Supports `${HOME}`, `${PROJECT_DIR}` |
177
+ | `secrets` | When `true`, runs the secret scanner on the value |
178
+
179
+ The special key `_any_value` applies the matcher to ALL argument values.
180
+
181
+ ### Built-in rule packs
182
+
183
+ - `rules/default.yml` — sensible defaults (blocks SSH, .env, credentials, dangerous commands, secrets)
184
+ - `rules/strict.yml` — deny-by-default paranoid mode (whitelist only project reads/writes)
185
+
186
+ Use strict mode:
187
+
188
+ ```bash
189
+ mcpwall -c /path/to/strict.yml -- npx -y @some/server
190
+ ```
191
+
192
+ ## CLI
193
+
194
+ ```
195
+ mcpwall [options] -- <command> [args...] # Proxy mode
196
+ mcpwall init # Interactive setup
197
+ mcpwall wrap <server-name> # Wrap specific server
198
+ ```
199
+
200
+ Options:
201
+ - `-c, --config <path>` — path to config file
202
+ - `--log-level <level>` — override log level (debug/info/warn/error)
203
+
204
+ ## Audit Logs
205
+
206
+ Logs are written as JSON Lines to `~/.mcpwall/logs/YYYY-MM-DD.jsonl`:
207
+
208
+ ```json
209
+ {"ts":"2026-02-16T14:30:00Z","method":"tools/call","tool":"read_file","action":"allow","rule":null}
210
+ {"ts":"2026-02-16T14:30:05Z","method":"tools/call","tool":"read_file","action":"deny","rule":"block-ssh-keys","message":"Blocked: access to SSH keys"}
211
+ ```
212
+
213
+ Denied entries have args redacted to prevent secrets from leaking into logs.
214
+
215
+ ## Security Design
216
+
217
+ - **Fail closed on invalid config**: Bad regex in a rule crashes at startup, never silently passes traffic
218
+ - **Args redacted on deny**: Blocked tool call arguments are never written to logs
219
+ - **Path traversal defense**: `not_under` matcher uses `path.resolve()` to prevent `../` bypass
220
+ - **Pre-compiled regexes**: All patterns compiled once at startup for consistent performance
221
+ - **No network**: Zero cloud calls, zero telemetry, runs entirely local
222
+ - **Deterministic**: Same input + same rules = same output, every time
223
+
224
+ ## License
225
+
226
+ [FSL-1.1-ALv2](./LICENSE) — source-available, converts to Apache 2.0 after 2 years.
227
+
228
+ ---
229
+
230
+ mcpwall is not affiliated with or endorsed by Anthropic or the Model Context Protocol project. MCP is an open protocol maintained by the Agentic AI Foundation under the Linux Foundation.