@jacobmolz/mcpguard 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jacob Molz
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.
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # MCP-Guard
2
+
3
+ [![CI](https://github.com/jmolz/mcp-guard/actions/workflows/ci.yml/badge.svg)](https://github.com/jmolz/mcp-guard/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/mcp-guard)](https://www.npmjs.com/package/mcp-guard)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ Security proxy daemon for MCP servers — adds authentication, rate limiting, PII detection, permission scoping, and audit logging without modifying upstream servers.
8
+
9
+ ## What is this?
10
+
11
+ MCP (Model Context Protocol) servers give AI coding tools access to files, databases, APIs, and more. But they have no built-in authentication, no audit trail, and no way to restrict which tools an agent can call.
12
+
13
+ MCP-Guard sits between your MCP client (Cursor, Claude Desktop, Claude Code, VS Code) and your MCP servers. It terminates the client connection, inspects every message through a security pipeline, then re-originates the request to the upstream server. Nothing passes through uninspected.
14
+
15
+ ## Key Features
16
+
17
+ - **Authentication** — OS-level peer credentials, API keys, or OAuth 2.1 with PKCE
18
+ - **Rate limiting** — Per-server, per-user, per-tool limits with SQLite persistence
19
+ - **Permission scoping** — Allow/deny lists for tools and resources, with capability filtering
20
+ - **PII detection** — Regex-based scanning with Luhn validation, bidirectional (request + response)
21
+ - **Audit logging** — Every MCP interaction logged to queryable SQLite with optional encryption
22
+ - **Role-based policies** — OAuth claims mapped to roles with floor-based policy merge
23
+ - **Config composability** — Base configs via `extends` with SHA-256 pinning; personal configs can only restrict
24
+ - **Transport support** — stdio, SSE, and Streamable HTTP upstream connections
25
+ - **Zero-config start** — Daemon auto-starts on first bridge connection
26
+
27
+ ## Quick Start
28
+
29
+ ```bash
30
+ npm install -g mcp-guard
31
+ ```
32
+
33
+ ### Option A: Auto-discover existing configs
34
+
35
+ ```bash
36
+ mcp-guard init
37
+ ```
38
+
39
+ This scans your Claude Desktop, Cursor, VS Code, and Claude Code configs, discovers MCP servers, and generates `mcp-guard.yaml`.
40
+
41
+ ### Option B: Manual config
42
+
43
+ Create `mcp-guard.yaml`:
44
+
45
+ ```yaml
46
+ servers:
47
+ filesystem:
48
+ transport: stdio
49
+ command: npx
50
+ args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
51
+ ```
52
+
53
+ ### Update your MCP client
54
+
55
+ Point your client at MCP-Guard instead of the upstream server:
56
+
57
+ ```json
58
+ {
59
+ "mcpServers": {
60
+ "filesystem": {
61
+ "command": "mcp-guard",
62
+ "args": ["connect", "--server", "filesystem"]
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ The daemon auto-starts on first connection.
69
+
70
+ ## Architecture
71
+
72
+ ```
73
+ Client -> Bridge (stdio) -> Daemon (Unix socket) -> Upstream MCP Server
74
+ |
75
+ Interceptor Pipeline
76
+ Auth -> Rate Limit -> Permissions
77
+ -> Sampling Guard -> PII Detect
78
+ |
79
+ Audit Tap
80
+ ```
81
+
82
+ - **Daemon** — Long-running process. Manages upstream connections, runs the interceptor pipeline, owns the SQLite database, serves the health dashboard.
83
+ - **Bridge** — Thin stdio relay (~50 lines). Zero policy logic. Structurally fail-closed.
84
+ - **CLI** — Stateless commands for management and configuration.
85
+
86
+ ### Security Model
87
+
88
+ MCP-Guard uses **terminate, inspect, re-originate** — it fully owns both the client and upstream connections. The interceptor pipeline is fail-closed: any error blocks the request. The audit tap is structural (wired outside the pipeline) and cannot be bypassed.
89
+
90
+ Config merge uses **floor-based semantics**: personal configs can restrict but never relax base policies. `allowed_tools` are intersected, `denied_tools` are unioned, rate limits take the stricter value.
91
+
92
+ ## Benchmark Results
93
+
94
+ The benchmark suite tests against 4,500+ attack scenarios across 10 categories and 10,000+ legitimate requests.
95
+
96
+ | Metric | Result | Target | Status |
97
+ |--------|--------|--------|--------|
98
+ | Detection rate | 92.5% | >95% | In progress |
99
+ | False positive rate | 0.000% | <0.1% | Pass |
100
+ | p50 latency overhead | 0.19ms | <5ms | Pass |
101
+ | p99 latency overhead | 1.22ms | — | — |
102
+ | Throughput | 7,042 req/s | — | — |
103
+
104
+ ### Per-Category Detection
105
+
106
+ | Category | Rate | Status |
107
+ |----------|------|--------|
108
+ | Permission bypass | 100% | Pass |
109
+ | PII response leak | 100% | Pass |
110
+ | Sampling injection | 100% | Pass |
111
+ | Config override | 100% | Pass |
112
+ | Capability probe | 96% | Pass |
113
+ | Resource traversal | 94% | In progress |
114
+ | Rate limit evasion | 92% | In progress |
115
+ | PII request leak | 84% | In progress |
116
+ | PII evasion | 82% | In progress |
117
+ | Auth bypass | 80% | In progress |
118
+
119
+ > Results from quick-mode stratified sample (1,004 scenarios). Full suite numbers may differ. Run `pnpm benchmark` for full results or see [latest report](benchmarks/results/REPORT.md) for charts.
120
+
121
+ ## CLI Reference
122
+
123
+ | Command | Description |
124
+ |---------|-------------|
125
+ | `mcp-guard start` | Start daemon (foreground, or `-d` for background) |
126
+ | `mcp-guard stop` | Stop running daemon |
127
+ | `mcp-guard connect -s <name>` | Start bridge for a server |
128
+ | `mcp-guard init` | Generate config from existing MCP client configs |
129
+ | `mcp-guard status` | Show daemon status |
130
+ | `mcp-guard health` | Liveness check (exit code 0/1) |
131
+ | `mcp-guard validate` | Validate config file |
132
+ | `mcp-guard logs` | Query audit logs |
133
+ | `mcp-guard auth login` | OAuth 2.1 authentication |
134
+ | `mcp-guard auth status` | Show token status |
135
+ | `mcp-guard auth logout` | Remove stored tokens |
136
+ | `mcp-guard dashboard-token` | Display dashboard auth token |
137
+
138
+ ## Configuration
139
+
140
+ See [`mcp-guard.example.yaml`](mcp-guard.example.yaml) for a complete example.
141
+
142
+ Key config sections:
143
+ - `servers` — Upstream MCP server definitions (command, args, env, transport, policy)
144
+ - `daemon` — Socket path, home directory, log level, dashboard port, encryption
145
+ - `auth` — Authentication mode (os, api_key, oauth) and role definitions
146
+ - `pii` — PII detection settings, custom types, per-type actions
147
+ - `audit` — Logging and retention settings
148
+
149
+ ## Docker
150
+
151
+ ```bash
152
+ docker build -f docker/Dockerfile -t mcp-guard .
153
+ docker run --rm mcp-guard --help
154
+ ```
155
+
156
+ Or with docker-compose:
157
+
158
+ ```bash
159
+ docker compose -f docker/docker-compose.yml up
160
+ ```
161
+
162
+ ## Development
163
+
164
+ ```bash
165
+ pnpm install
166
+ pnpm dev # Start in dev mode
167
+ pnpm test # Run tests (360+ across 38 files)
168
+ pnpm lint # Lint
169
+ pnpm typecheck # Type check
170
+ pnpm build # Production build
171
+ pnpm benchmark:quick # Quick benchmark suite (~30s)
172
+ ```
173
+
174
+ ## Contributing
175
+
176
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
177
+
178
+ ## License
179
+
180
+ MIT