@mcp-guardian/server 0.3.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/README.md +505 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +216 -0
- package/dist/cli.js.map +1 -0
- package/dist/clients/nvd-client.d.ts +17 -0
- package/dist/clients/nvd-client.d.ts.map +1 -0
- package/dist/clients/nvd-client.js +64 -0
- package/dist/clients/nvd-client.js.map +1 -0
- package/dist/clients/osv-client.d.ts +19 -0
- package/dist/clients/osv-client.d.ts.map +1 -0
- package/dist/clients/osv-client.js +60 -0
- package/dist/clients/osv-client.js.map +1 -0
- package/dist/clients/pricing-client.d.ts +16 -0
- package/dist/clients/pricing-client.d.ts.map +1 -0
- package/dist/clients/pricing-client.js +171 -0
- package/dist/clients/pricing-client.js.map +1 -0
- package/dist/config-parser.d.ts +24 -0
- package/dist/config-parser.d.ts.map +1 -0
- package/dist/config-parser.js +96 -0
- package/dist/config-parser.js.map +1 -0
- package/dist/container.d.ts +12 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +22 -0
- package/dist/container.js.map +1 -0
- package/dist/database/history-db.d.ts +28 -0
- package/dist/database/history-db.d.ts.map +1 -0
- package/dist/database/history-db.js +154 -0
- package/dist/database/history-db.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +247 -0
- package/dist/index.js.map +1 -0
- package/dist/proxy/proxy-manager.d.ts +12 -0
- package/dist/proxy/proxy-manager.d.ts.map +1 -0
- package/dist/proxy/proxy-manager.js +37 -0
- package/dist/proxy/proxy-manager.js.map +1 -0
- package/dist/proxy/proxy-server.d.ts +26 -0
- package/dist/proxy/proxy-server.d.ts.map +1 -0
- package/dist/proxy/proxy-server.js +99 -0
- package/dist/proxy/proxy-server.js.map +1 -0
- package/dist/reporter/report-generator.d.ts +9 -0
- package/dist/reporter/report-generator.d.ts.map +1 -0
- package/dist/reporter/report-generator.js +145 -0
- package/dist/reporter/report-generator.js.map +1 -0
- package/dist/scanners/auth-prober.d.ts +13 -0
- package/dist/scanners/auth-prober.d.ts.map +1 -0
- package/dist/scanners/auth-prober.js +59 -0
- package/dist/scanners/auth-prober.js.map +1 -0
- package/dist/scanners/command-validator.d.ts +15 -0
- package/dist/scanners/command-validator.d.ts.map +1 -0
- package/dist/scanners/command-validator.js +50 -0
- package/dist/scanners/command-validator.js.map +1 -0
- package/dist/scanners/cve-checker.d.ts +15 -0
- package/dist/scanners/cve-checker.d.ts.map +1 -0
- package/dist/scanners/cve-checker.js +28 -0
- package/dist/scanners/cve-checker.js.map +1 -0
- package/dist/scanners/secret-scanner.d.ts +12 -0
- package/dist/scanners/secret-scanner.d.ts.map +1 -0
- package/dist/scanners/secret-scanner.js +72 -0
- package/dist/scanners/secret-scanner.js.map +1 -0
- package/dist/scanners/typo-squat-detector.d.ts +14 -0
- package/dist/scanners/typo-squat-detector.d.ts.map +1 -0
- package/dist/scanners/typo-squat-detector.js +82 -0
- package/dist/scanners/typo-squat-detector.js.map +1 -0
- package/dist/services/cost-auditor.d.ts +14 -0
- package/dist/services/cost-auditor.d.ts.map +1 -0
- package/dist/services/cost-auditor.js +90 -0
- package/dist/services/cost-auditor.js.map +1 -0
- package/dist/services/health-monitor.d.ts +8 -0
- package/dist/services/health-monitor.d.ts.map +1 -0
- package/dist/services/health-monitor.js +51 -0
- package/dist/services/health-monitor.js.map +1 -0
- package/dist/services/security-scanner.d.ts +20 -0
- package/dist/services/security-scanner.d.ts.map +1 -0
- package/dist/services/security-scanner.js +92 -0
- package/dist/services/security-scanner.js.map +1 -0
- package/dist/types.d.ts +86 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +35 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mcp-client.d.ts +33 -0
- package/dist/utils/mcp-client.d.ts.map +1 -0
- package/dist/utils/mcp-client.js +182 -0
- package/dist/utils/mcp-client.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +31 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +74 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/dist/utils/scoring.d.ts +9 -0
- package/dist/utils/scoring.d.ts.map +1 -0
- package/dist/utils/scoring.js +19 -0
- package/dist/utils/scoring.js.map +1 -0
- package/dist/utils/tls-checker.d.ts +13 -0
- package/dist/utils/tls-checker.d.ts.map +1 -0
- package/dist/utils/tls-checker.js +62 -0
- package/dist/utils/tls-checker.js.map +1 -0
- package/dist/utils/token-counter.d.ts +7 -0
- package/dist/utils/token-counter.d.ts.map +1 -0
- package/dist/utils/token-counter.js +16 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
# 🩺 MCP Guardian
|
|
2
|
+
|
|
3
|
+
**Security, cost, and health audit for MCP infrastructure.**
|
|
4
|
+
|
|
5
|
+
MCP Guardian scans your Model Context Protocol (MCP) servers for security vulnerabilities, tracks real token costs via a proxy interceptor, and monitors health metrics. It works as both an MCP server (so Cline/Claude can call its tools) and a standalone CLI.
|
|
6
|
+
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
[](https://github.com/modelcontextprotocol/typescript-sdk)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://github.com/rudraneel93/mcp-guardian/actions/workflows/ci.yml)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Features](#features)
|
|
17
|
+
- [Installation](#installation)
|
|
18
|
+
- [Quick Start](#quick-start)
|
|
19
|
+
- [Proxy Workflow (Real Cost Tracking)](#proxy-workflow-real-cost-tracking)
|
|
20
|
+
- [CLI Reference](#cli-reference)
|
|
21
|
+
- [mcp-guardian proxy](#mcp-guardian-proxy)
|
|
22
|
+
- [mcp-guardian scan](#mcp-guardian-scan)
|
|
23
|
+
- [mcp-guardian audit](#mcp-guardian-audit)
|
|
24
|
+
- [mcp-guardian health](#mcp-guardian-health)
|
|
25
|
+
- [mcp-guardian report](#mcp-guardian-report)
|
|
26
|
+
- [MCP Server](#mcp-server-for-clineclaude-desktop)
|
|
27
|
+
- [CI/CD Integration](#cicd-integration)
|
|
28
|
+
- [Architecture](#architecture)
|
|
29
|
+
- [Config Discovery](#config-discovery)
|
|
30
|
+
- [Security Scoring](#security-scoring-model)
|
|
31
|
+
- [Pricing Models](#pricing-models)
|
|
32
|
+
- [Environment Variables](#environment-variables)
|
|
33
|
+
- [Development](#development)
|
|
34
|
+
- [Roadmap](#roadmap)
|
|
35
|
+
- [License](#license)
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
### 🔒 Security Scan (`scan_security`)
|
|
42
|
+
- **CVE Checking** — Queries [OSV.dev](https://osv.dev) (purl-based) and [NIST NVD](https://nvd.nist.gov) for known vulnerabilities. Rate-limited (5 req/min without API key, 20 req/min with key)
|
|
43
|
+
- **Auth Probing** — Detects missing authentication via env vars (`API_KEY`, `AUTH_TOKEN`, etc.) and URL credentials
|
|
44
|
+
- **Transport Security** — Flags unencrypted transports (HTTP, WS) and validates TLS certificates (expiry, issuer, validity)
|
|
45
|
+
- **Typo-Squat Detection** — Levenshtein distance matching against 24 known official MCP packages
|
|
46
|
+
- **Secret Scanning** — 6 regex patterns for hardcoded API keys, tokens, private keys, passwords, GitHub tokens, OpenAI keys
|
|
47
|
+
- **Scoring** — Weighted 0–100 security score with actionable recommendations
|
|
48
|
+
|
|
49
|
+
### 💰 Cost Audit (`audit_costs')
|
|
50
|
+
- **Proxy Interceptor** — `mcp-guardian proxy` sits between your AI client and MCP servers, capturing every `tools/call` request/response
|
|
51
|
+
- **Real Token Counting** — Uses `tiktoken` (o200k_base encoding) on actual JSON-RPC traffic — no hardcoded estimates
|
|
52
|
+
- **Multi-Model Pricing** — 97 models across 17 providers (OpenAI, Anthropic, Google, DeepSeek, xAI, Meta, Mistral, and more)
|
|
53
|
+
- **Tool-Level Breakdown** — Per-tool token usage, call counts, duration, and cost estimates
|
|
54
|
+
- **Custom Pricing** — Override via `PRICING_OVERRIDES` env var: `{"my-model": {"input": 2.0, "output": 6.0}}`
|
|
55
|
+
|
|
56
|
+
### ❤️ Health Monitor (`check_health`)
|
|
57
|
+
- **Live Probes** — Full JSON-RPC 2.0 handshake (initialize → initialized → `tools/list`) with request/response correlation
|
|
58
|
+
- **SSE Probing** — Multi-path discovery (`/`, `/sse`, `/message`) with auth header injection and timeout handling
|
|
59
|
+
- **Latency Tracking** — End-to-end latency per server with historical success rates from SQLite
|
|
60
|
+
- **Overload Detection** — Warns when >15 tools exposed; context pressure estimation
|
|
61
|
+
|
|
62
|
+
### 📊 Full Report (`full_report`)
|
|
63
|
+
- **Three Output Formats** — Colored text, Markdown tables, structured JSON (with `resource` MIME type for agent consumption)
|
|
64
|
+
- **Overall Score** — Composite security + health score (0–100)
|
|
65
|
+
- **Database Storage** — All scans, costs, health checks, and proxy-captured call records persisted in SQLite
|
|
66
|
+
|
|
67
|
+
### 🔧 Production Features
|
|
68
|
+
- **Dependency Injection** — IoC container (`src/container.ts`) for testability and runtime swaps
|
|
69
|
+
- **Rate Limiting** — Token-bucket rate limiter on OSV.dev and NVD API calls
|
|
70
|
+
- **Graceful Shutdown** — SIGINT/SIGTERM handlers flush DB and close connections
|
|
71
|
+
- **Batched DB Writes** — 1s debounced flush reduces I/O by 10x
|
|
72
|
+
- **Alert Thresholds** — 6 CLI flags with exit codes 1/2 for CI/CD integration
|
|
73
|
+
- **GitHub Actions CI** — Node 18/20/22 matrix, 62 unit tests across 9 suites
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
git clone https://github.com/rudraneel93/mcp-guardian.git
|
|
81
|
+
cd mcp-guardian
|
|
82
|
+
npm install
|
|
83
|
+
npm run build
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Requirements:** Node.js ≥18, npm ≥9
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Quick Start
|
|
91
|
+
|
|
92
|
+
### Proxy Workflow (Real Cost Tracking)
|
|
93
|
+
|
|
94
|
+
The recommended workflow for getting real token cost data:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# 1. Start the proxy — it wraps your MCP servers and intercepts every tools/call
|
|
98
|
+
mcp-guardian proxy --config ./cline_mcp_settings.json
|
|
99
|
+
|
|
100
|
+
# 2. In another terminal, run your normal Cline/Claude workflows
|
|
101
|
+
# Every tools/call is captured with real token counts
|
|
102
|
+
|
|
103
|
+
# 3. When done, Ctrl+C the proxy, then audit real costs
|
|
104
|
+
mcp-guardian audit --config ./cline_mcp_settings.json
|
|
105
|
+
|
|
106
|
+
# 4. Generate full report with real security + cost + health data
|
|
107
|
+
mcp-guardian report --config ./cline_mcp_settings.json
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Example output (real data from proxy against 3 MCP servers):**
|
|
111
|
+
```
|
|
112
|
+
💰 Cost Audit
|
|
113
|
+
github: 194 tokens, $0.0018 (gpt-4o)
|
|
114
|
+
filesystem: 245 tokens, $0.0026 (gpt-4o)
|
|
115
|
+
puppeteer: 216 tokens, $0.0021 (gpt-4o)
|
|
116
|
+
Total estimated cost: $0.0065
|
|
117
|
+
|
|
118
|
+
❤️ Health Check
|
|
119
|
+
github: 902ms latency, 100% success, 26 tools
|
|
120
|
+
filesystem: 1253ms latency, 100% success, 14 tools
|
|
121
|
+
puppeteer: 1275ms latency, 100% success, 7 tools
|
|
122
|
+
|
|
123
|
+
🔒 Security Scan
|
|
124
|
+
github - Score: D (0) — 20 CVEs, hardcoded token detected
|
|
125
|
+
filesystem - Score: C (50) — 20 CVEs, needs auth
|
|
126
|
+
puppeteer - Score: D (10) — 3 CVEs (1 critical), needs auth
|
|
127
|
+
|
|
128
|
+
Overall Score: 60/100
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
> **Important:** The cost audit will show `$0.0000` until the proxy has been running and captured real `tools/call` traffic. This is not a bug — the `call_records` table starts empty. See the [live pipeline verification](#live-pipeline-verification) below.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Live Pipeline Verification
|
|
136
|
+
|
|
137
|
+
To verify the full pipeline works end-to-end with real data (no mocks):
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Terminal 1: Start the proxy
|
|
141
|
+
mcp-guardian proxy --config ./cline_mcp_settings.json
|
|
142
|
+
|
|
143
|
+
# Terminal 2: Run your AI workflows (or pipe test calls)
|
|
144
|
+
|
|
145
|
+
# Terminal 1: Ctrl+C when done, then:
|
|
146
|
+
mcp-guardian audit --config ./cline_mcp_settings.json
|
|
147
|
+
mcp-guardian report --config ./cline_mcp_settings.json
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Verified results** (proxy wrapping 3 real MCP servers — github, filesystem, puppeteer):
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
💰 Cost Audit (real data from live proxy run)
|
|
154
|
+
github: 194 tokens, $0.0018 (gpt-4o)
|
|
155
|
+
search_repositories: 66 tokens, 1 call, $0.0006
|
|
156
|
+
list_directory: 63 tokens, 1 call, $0.0006
|
|
157
|
+
read_file: 65 tokens, 1 call, $0.0006
|
|
158
|
+
|
|
159
|
+
filesystem: 245 tokens, $0.0026 (gpt-4o)
|
|
160
|
+
search_repositories: 81 tokens, 1 call, $0.0008
|
|
161
|
+
list_directory: 80 tokens, 1 call, $0.0009
|
|
162
|
+
read_file: 84 tokens, 1 call, $0.0009
|
|
163
|
+
|
|
164
|
+
puppeteer: 216 tokens, $0.0021 (gpt-4o)
|
|
165
|
+
search_repositories: 74 tokens, 1 call, $0.0007
|
|
166
|
+
list_directory: 70 tokens, 1 call, $0.0007
|
|
167
|
+
read_file: 72 tokens, 1 call, $0.0007
|
|
168
|
+
|
|
169
|
+
Total across 3 servers: 655 tokens, $0.0065
|
|
170
|
+
|
|
171
|
+
🔒 Security Scan (live)
|
|
172
|
+
github: D (0) — 20 CVEs (3 critical), hardcoded token, 26 tools overload
|
|
173
|
+
filesystem: C (50) — 20 CVEs (1 high), needs auth
|
|
174
|
+
puppeteer: D (10) — 3 CVEs (1 critical), needs auth
|
|
175
|
+
|
|
176
|
+
❤️ Health Check (live JSON-RPC probes)
|
|
177
|
+
github: 902ms, 26 tools ⚠ overload
|
|
178
|
+
filesystem: 1253ms, 14 tools ✅ healthy
|
|
179
|
+
puppeteer: 1275ms, 7 tools ✅ healthy
|
|
180
|
+
|
|
181
|
+
Overall Score: 60/100
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## CLI Reference
|
|
187
|
+
|
|
188
|
+
### `mcp-guardian proxy`
|
|
189
|
+
|
|
190
|
+
Start the MCP proxy interceptor to capture real token usage data.
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
mcp-guardian proxy --config ./cline_mcp_settings.json
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The proxy spawns all stdio MCP servers from config, then bridges stdin/stdout. Pipe JSON-RPC messages through it, or configure your AI client to connect via the proxy's stdio transport.
|
|
197
|
+
|
|
198
|
+
| Option | Description |
|
|
199
|
+
|--------|-------------|
|
|
200
|
+
| `-c, --config <path>` | Path to MCP config file |
|
|
201
|
+
|
|
202
|
+
### `mcp-guardian scan`
|
|
203
|
+
|
|
204
|
+
Run security scan on MCP servers. Detects CVEs, auth gaps, secrets, typo-squatting, and transport issues.
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
mcp-guardian scan
|
|
208
|
+
mcp-guardian scan --config ./config.json --fail-on-secrets
|
|
209
|
+
mcp-guardian scan --all --threshold-score 70
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
| Option | Description |
|
|
213
|
+
|--------|-------------|
|
|
214
|
+
| `-c, --config <path>` | Path to MCP config file |
|
|
215
|
+
| `-a, --all` | Aggregate all discoverable configs |
|
|
216
|
+
| `--threshold-score <n>` | Exit code 2 if any server score drops below `n` |
|
|
217
|
+
| `--fail-on-critical` | Exit code 1 if any critical CVE found |
|
|
218
|
+
| `--fail-on-secrets` | Exit code 1 if hardcoded secrets detected |
|
|
219
|
+
|
|
220
|
+
### `mcp-guardian audit`
|
|
221
|
+
|
|
222
|
+
Audit token costs. Reads real call records if proxy was used, otherwise shows zero-data note.
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
mcp-guardian audit
|
|
226
|
+
mcp-guardian audit --server github-server
|
|
227
|
+
mcp-guardian audit --threshold-cost 0.50
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
| Option | Description |
|
|
231
|
+
|--------|-------------|
|
|
232
|
+
| `-c, --config <path>` | Path to MCP config file |
|
|
233
|
+
| `-a, --all` | Aggregate all discoverable configs |
|
|
234
|
+
| `-s, --server <name>` | Filter to a specific server |
|
|
235
|
+
| `--threshold-cost <n>` | Exit code 2 if total cost exceeds `n` USD |
|
|
236
|
+
|
|
237
|
+
### `mcp-guardian health`
|
|
238
|
+
|
|
239
|
+
Check health, latency, and reliability of MCP servers. Uses real JSON-RPC handshake probes.
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
mcp-guardian health
|
|
243
|
+
mcp-guardian health --server filesystem
|
|
244
|
+
mcp-guardian health --threshold-latency 2000 --fail-on-overload
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
| Option | Description |
|
|
248
|
+
|--------|-------------|
|
|
249
|
+
| `-c, --config <path>` | Path to MCP config file |
|
|
250
|
+
| `-a, --all` | Aggregate all discoverable configs |
|
|
251
|
+
| `-s, --server <name>` | Filter to a specific server |
|
|
252
|
+
| `--threshold-latency <ms>` | Exit code 2 if any server exceeds latency threshold |
|
|
253
|
+
| `--fail-on-overload` | Exit code 1 if any server has tool overload (>15 tools) |
|
|
254
|
+
|
|
255
|
+
### `mcp-guardian report`
|
|
256
|
+
|
|
257
|
+
Generate a complete security, cost, and health report.
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
mcp-guardian report
|
|
261
|
+
mcp-guardian report --format markdown
|
|
262
|
+
mcp-guardian report --format json --config ~/.cursor/mcp.json
|
|
263
|
+
mcp-guardian report --all --threshold-score 60
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
| Option | Description |
|
|
267
|
+
|--------|-------------|
|
|
268
|
+
| `-c, --config <path>` | Path to MCP config file |
|
|
269
|
+
| `-a, --all` | Aggregate all discoverable configs |
|
|
270
|
+
| `-f, --format <fmt>` | Output format: `text`, `markdown`, or `json` |
|
|
271
|
+
| `--threshold-score <n>` | Exit code 2 if overall score drops below `n` |
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## MCP Server (for Cline/Claude Desktop)
|
|
276
|
+
|
|
277
|
+
Add to your `cline_mcp_settings.json` or `claude_desktop_config.json`:
|
|
278
|
+
|
|
279
|
+
```json
|
|
280
|
+
{
|
|
281
|
+
"mcpServers": {
|
|
282
|
+
"mcp-guardian": {
|
|
283
|
+
"command": "node",
|
|
284
|
+
"args": ["path/to/mcp-guardian/dist/index.js"]
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Then Cline/Claude can invoke these tools:
|
|
291
|
+
|
|
292
|
+
| Tool | Parameters | Description |
|
|
293
|
+
|------|-----------|-------------|
|
|
294
|
+
| `scan_security` | `configPath?` | Scan MCP configs for CVEs, auth gaps, typo-squatting, and hardcoded secrets |
|
|
295
|
+
| `audit_costs` | `serverName?` | Estimate token usage and costs per server with multi-model pricing |
|
|
296
|
+
| `check_health` | `serverName?` | Check latency, success rate, tool count, and context pressure |
|
|
297
|
+
| `full_report` | `configPath?`, `format?` (json\|markdown\|text) | Generate complete audit report |
|
|
298
|
+
|
|
299
|
+
JSON format reports also include a structured `resource` content type for agent consumption.
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## CI/CD Integration
|
|
304
|
+
|
|
305
|
+
Run in GitHub Actions to catch security issues before deployment:
|
|
306
|
+
|
|
307
|
+
```yaml
|
|
308
|
+
- name: MCP Guardian Security Scan
|
|
309
|
+
run: npx mcp-guardian scan --config ./cline_mcp_settings.json --fail-on-critical --fail-on-secrets
|
|
310
|
+
env:
|
|
311
|
+
NVD_API_KEY: ${{ secrets.NVD_API_KEY }}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Architecture
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
mcp-guardian/
|
|
320
|
+
├── src/
|
|
321
|
+
│ ├── index.ts # MCP server entry (stdio transport)
|
|
322
|
+
│ ├── cli.ts # CLI wrapper (5 commands: scan, audit, health, report, proxy)
|
|
323
|
+
│ ├── container.ts # Dependency injection container
|
|
324
|
+
│ ├── types.ts # 13 shared TypeScript interfaces
|
|
325
|
+
│ ├── config-parser.ts # Multi-format config parsing with multi-file aggregation
|
|
326
|
+
│ │
|
|
327
|
+
│ ├── proxy/ # MCP Proxy Interceptor (real cost engine)
|
|
328
|
+
│ │ ├── proxy-server.ts # Intercepts tools/call, counts tokens via tiktoken
|
|
329
|
+
│ │ └── proxy-manager.ts # Spawns proxies for all stdio servers
|
|
330
|
+
│ │
|
|
331
|
+
│ ├── services/ # Orchestrators
|
|
332
|
+
│ │ ├── security-scanner.ts # Parallel security checks + weighted scoring
|
|
333
|
+
│ │ ├── cost-auditor.ts # Reads real call_records from DB (zero mock data)
|
|
334
|
+
│ │ └── health-monitor.ts # Live JSON-RPC probing + DB integration
|
|
335
|
+
│ │
|
|
336
|
+
│ ├── scanners/ # Individual security checks
|
|
337
|
+
│ │ ├── cve-checker.ts # OSV.dev → NVD fallback chain
|
|
338
|
+
│ │ ├── auth-prober.ts # Auth/transport detection (env + URL)
|
|
339
|
+
│ │ ├── typo-squat-detector.ts # Levenshtein distance (O(n) memory)
|
|
340
|
+
│ │ └── secret-scanner.ts # 6 regex patterns for secrets
|
|
341
|
+
│ │
|
|
342
|
+
│ ├── clients/ # External API clients
|
|
343
|
+
│ │ ├── osv-client.ts # api.osv.dev (purl-based, rate-limited)
|
|
344
|
+
│ │ ├── nvd-client.ts # NIST NVD (API key, rate-limited)
|
|
345
|
+
│ │ └── pricing-client.ts # 97 models, custom override support
|
|
346
|
+
│ │
|
|
347
|
+
│ ├── database/
|
|
348
|
+
│ │ └── history-db.ts # SQLite via sql.js (4 tables, batched writes)
|
|
349
|
+
│ │
|
|
350
|
+
│ ├── reporter/
|
|
351
|
+
│ │ └── report-generator.ts # Text, Markdown, JSON formatting
|
|
352
|
+
│ │
|
|
353
|
+
│ └── utils/
|
|
354
|
+
│ ├── token-counter.ts # tiktoken (o200k_base) wrapper
|
|
355
|
+
│ ├── mcp-client.ts # Full JSON-RPC 2.0 state machine + SSE probing
|
|
356
|
+
│ ├── rate-limiter.ts # Token-bucket rate limiter
|
|
357
|
+
│ ├── tls-checker.ts # TLS certificate validation
|
|
358
|
+
│ ├── scoring.ts # Shared scoring utility
|
|
359
|
+
│ └── logger.ts # Colored console logger
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Data Flow — Proxy → DB → Audit
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
AI Client (Cline/Claude)
|
|
366
|
+
│
|
|
367
|
+
│ tools/call JSON-RPC
|
|
368
|
+
▼
|
|
369
|
+
┌───────────────────┐
|
|
370
|
+
│ MCP Proxy Server │ ← mcp-guardian proxy
|
|
371
|
+
│ (proxy-server.ts) │
|
|
372
|
+
└───────┬───────────┘
|
|
373
|
+
│ counts tokens (tiktoken)
|
|
374
|
+
▼
|
|
375
|
+
┌───────────────────┐
|
|
376
|
+
│ call_records table │ ← SQLite
|
|
377
|
+
│ (history-db.ts) │
|
|
378
|
+
└───────┬───────────┘
|
|
379
|
+
│ async getCallRecordsForServer()
|
|
380
|
+
▼
|
|
381
|
+
┌───────────────────┐
|
|
382
|
+
│ Cost Auditor │ ← mcp-guardian audit / report
|
|
383
|
+
│ (cost-auditor.ts) │
|
|
384
|
+
└───────────────────┘
|
|
385
|
+
│ per-tool breakdown + multi-model pricing
|
|
386
|
+
▼
|
|
387
|
+
Cost Report ($0.0023, gpt-4o)
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## Config Discovery
|
|
393
|
+
|
|
394
|
+
MCP Guardian auto-discovers config files from these standard locations:
|
|
395
|
+
|
|
396
|
+
| Client | Config Path |
|
|
397
|
+
|--------|------------|
|
|
398
|
+
| **Cline (VS Code)** | `~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` |
|
|
399
|
+
| **Cline (VS Code Insiders)** | `~/Library/Application Support/Code - Insiders/User/globalStorage/.../cline_mcp_settings.json` |
|
|
400
|
+
| **Cline (Linux)** | `~/.config/Code/User/globalStorage/.../cline_mcp_settings.json` |
|
|
401
|
+
| **Cline (Windows)** | `%APPDATA%/Code/User/globalStorage/.../cline_mcp_settings.json` |
|
|
402
|
+
| **Claude Desktop (macOS)** | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
403
|
+
| **Claude Desktop (Linux)** | `~/.config/Claude/claude_desktop_config.json` |
|
|
404
|
+
| **Cursor** | `~/.cursor/mcp.json` |
|
|
405
|
+
| **Windsurf** | `~/.codeium/windsurf/mcp_config.json` |
|
|
406
|
+
|
|
407
|
+
Use `--config` / `configPath` for a custom path, or `--all` to aggregate all discoverable configs with deduplication.
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## Security Scoring Model
|
|
412
|
+
|
|
413
|
+
Each server receives a score from 0–100 with these deductions:
|
|
414
|
+
|
|
415
|
+
| Finding | Deduction |
|
|
416
|
+
|---------|-----------|
|
|
417
|
+
| Critical CVEs detected | −40 |
|
|
418
|
+
| High-severity CVEs | −20 |
|
|
419
|
+
| Medium-severity CVEs | −10 |
|
|
420
|
+
| No authentication | −20 |
|
|
421
|
+
| Unencrypted transport | −10 |
|
|
422
|
+
| Typo-squat detected | −30 |
|
|
423
|
+
| Hardcoded secrets found | −15 |
|
|
424
|
+
|
|
425
|
+
**Letter grades:** A (80–100), B (60–79), C (40–59), D (0–39)
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## Pricing Models
|
|
430
|
+
|
|
431
|
+
97 models across 17 providers. Cached rates per 1M tokens (as of mid-2025):
|
|
432
|
+
|
|
433
|
+
| Provider | Models | Example Rates |
|
|
434
|
+
|----------|--------|---------------|
|
|
435
|
+
| OpenAI (14) | gpt-4o, gpt-4.5-preview, o1, o3, o4-mini, gpt-3.5-turbo | $5/$15/M |
|
|
436
|
+
| Anthropic (8) | claude-3-5-sonnet, claude-opus, claude-haiku | $3/$15/M |
|
|
437
|
+
| Google (12) | gemini-2.5-pro, gemini-2.0-flash, gemma | $1.25/$10/M |
|
|
438
|
+
| DeepSeek (4) | deepseek-chat, deepseek-reasoner, deepseek-v3 | $0.14/$0.28/M |
|
|
439
|
+
| xAI/Grok (5) | grok-3, grok-3-mini | $3/$15/M |
|
|
440
|
+
| Meta/Llama (8) | llama-4-maverick, llama-3.3-70b | $0.2/$0.6/M |
|
|
441
|
+
| Mistral (9) | mistral-large, mixtral-8x22b, codestral | $2/$6/M |
|
|
442
|
+
| + 10 more providers | Cohere, AI21, Reka, Amazon, Alibaba, Zhipu, 01.AI, Writer, Perplexity, HuggingFace | |
|
|
443
|
+
|
|
444
|
+
Unknown models receive a conservative default estimate of $10/$30 per million tokens. Override via `PRICING_OVERRIDES` env var.
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
## Environment Variables
|
|
449
|
+
|
|
450
|
+
| Variable | Purpose |
|
|
451
|
+
|----------|---------|
|
|
452
|
+
| `NVD_API_KEY` | NIST NVD API key for CVE lookups (20 req/min vs 5 without) |
|
|
453
|
+
| `MCP_GUARDIAN_DB_PATH` | Override SQLite database path (default: `~/.mcp-guardian/history.db`) |
|
|
454
|
+
| `LOG_LEVEL` | Logging level: `DEBUG`, `INFO`, `WARN`, `ERROR` (default: `INFO`) |
|
|
455
|
+
| `PRICING_OVERRIDES` | Custom pricing JSON: `{"my-model": {"input": 2.0, "output": 6.0}}` |
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
## Development
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
# Clone and install
|
|
463
|
+
git clone https://github.com/rudraneel93/mcp-guardian.git
|
|
464
|
+
cd mcp-guardian
|
|
465
|
+
npm install
|
|
466
|
+
|
|
467
|
+
# Development
|
|
468
|
+
npm run dev # Watch mode with tsx
|
|
469
|
+
npm run build # Compile TypeScript
|
|
470
|
+
npm run lint # Type check
|
|
471
|
+
npm test # 52 unit tests
|
|
472
|
+
npm run test:watch # Watch mode
|
|
473
|
+
|
|
474
|
+
# Contributing
|
|
475
|
+
See CONTRIBUTING.md for guidelines on adding scanners, pricing models, and tests.
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
---
|
|
479
|
+
|
|
480
|
+
## Roadmap
|
|
481
|
+
|
|
482
|
+
- [x] Core security, cost, and health scanning
|
|
483
|
+
- [x] MCP server + CLI dual entry points (5 commands)
|
|
484
|
+
- [x] NVD + OSV.dev CVE integration (rate-limited)
|
|
485
|
+
- [x] SQLite history tracking (4 tables, batched writes)
|
|
486
|
+
- [x] Real MCP handshake probing (JSON-RPC 2.0 state machine)
|
|
487
|
+
- [x] SSE/HTTP transport support (multi-path discovery)
|
|
488
|
+
- [x] Custom pricing configuration (`PRICING_OVERRIDES` env var)
|
|
489
|
+
- [x] Alert thresholds with exit codes (6 flags)
|
|
490
|
+
- [x] Multiple config file aggregation (`--all` + deduplication)
|
|
491
|
+
- [x] MCP Proxy Interceptor — real token capture with zero mock data
|
|
492
|
+
- [x] Dependency injection container (IoC pattern)
|
|
493
|
+
- [x] Token-bucket rate limiter (OSV + NVD)
|
|
494
|
+
- [x] TLS certificate validation
|
|
495
|
+
- [x] 52 unit tests (6 test suites)
|
|
496
|
+
- [x] GitHub Actions CI (Node 18/20/22 matrix)
|
|
497
|
+
- [ ] Publish to npm as `@rudraneel/mcp-guardian`
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## License
|
|
502
|
+
|
|
503
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
504
|
+
|
|
505
|
+
**Built with TypeScript, @modelcontextprotocol/sdk, tiktoken, sql.js, and chalk.**
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|