protect-mcp 0.3.2 → 0.4.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/dist/cli.mjs CHANGED
@@ -1,13 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- ProtectGateway,
4
3
  formatSimulation,
4
+ parseLogFile,
5
+ simulate
6
+ } from "./chunk-UW2SGWCJ.mjs";
7
+ import {
8
+ ProtectGateway,
5
9
  initSigning,
6
10
  loadPolicy,
7
- parseLogFile,
8
- simulate,
9
11
  validateCredentials
10
- } from "./chunk-GV7N53QE.mjs";
12
+ } from "./chunk-XMZWJOC3.mjs";
11
13
 
12
14
  // src/cli.ts
13
15
  function printHelp() {
@@ -31,6 +33,8 @@ Options:
31
33
  --policy <path> Policy/config JSON file (default: allow-all)
32
34
  --slug <slug> ScopeBlind tenant slug (optional)
33
35
  --enforce Enable enforcement mode (default: shadow mode)
36
+ --http Start HTTP/SSE server instead of stdio proxy
37
+ --port <port> HTTP server port (default: 3000, requires --http)
34
38
  --verbose Enable debug logging to stderr
35
39
  --help Show this help
36
40
 
@@ -1020,6 +1024,14 @@ async function main() {
1020
1024
  signing,
1021
1025
  credentials
1022
1026
  };
1027
+ const useHttp = args.includes("--http");
1028
+ if (useHttp) {
1029
+ const portIdx = args.indexOf("--port");
1030
+ const httpPort = portIdx >= 0 && args[portIdx + 1] ? parseInt(args[portIdx + 1]) : 3e3;
1031
+ const { startHttpTransport } = await import("./http-transport-S7YXXMD3.mjs");
1032
+ startHttpTransport({ port: httpPort, config, serverCommand: childCommand });
1033
+ return;
1034
+ }
1023
1035
  const gateway = new ProtectGateway(config);
1024
1036
  await gateway.start();
1025
1037
  }
@@ -0,0 +1,131 @@
1
+ import {
2
+ ProtectGateway
3
+ } from "./chunk-XMZWJOC3.mjs";
4
+
5
+ // src/http-transport.ts
6
+ import { createServer } from "http";
7
+ function startHttpTransport(options) {
8
+ const { port, config, serverCommand } = options;
9
+ const sseClients = /* @__PURE__ */ new Set();
10
+ const gateway = new ProtectGateway(config);
11
+ const server = createServer(async (req, res) => {
12
+ const origin = req.headers.origin || "*";
13
+ res.setHeader("Access-Control-Allow-Origin", origin);
14
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
15
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
16
+ res.setHeader("Access-Control-Allow-Credentials", "true");
17
+ if (req.method === "OPTIONS") {
18
+ res.writeHead(204);
19
+ res.end();
20
+ return;
21
+ }
22
+ const url = new URL(req.url || "/", `http://localhost:${port}`);
23
+ if (url.pathname === "/health" && req.method === "GET") {
24
+ res.writeHead(200, { "Content-Type": "application/json" });
25
+ res.end(JSON.stringify({
26
+ status: "ok",
27
+ server: "protect-mcp",
28
+ version: "0.3.3",
29
+ transport: "http",
30
+ mode: config.policy ? config.enforce ? "enforce" : "shadow" : "shadow"
31
+ }));
32
+ return;
33
+ }
34
+ if (url.pathname === "/mcp/sse" && req.method === "GET") {
35
+ res.writeHead(200, {
36
+ "Content-Type": "text/event-stream",
37
+ "Cache-Control": "no-cache",
38
+ "Connection": "keep-alive"
39
+ });
40
+ res.write(`data: ${JSON.stringify({ type: "connected", server: "protect-mcp" })}
41
+
42
+ `);
43
+ sseClients.add(res);
44
+ req.on("close", () => sseClients.delete(res));
45
+ return;
46
+ }
47
+ if (url.pathname === "/mcp" && req.method === "POST") {
48
+ let body = "";
49
+ req.on("data", (chunk) => {
50
+ body += chunk;
51
+ });
52
+ req.on("end", async () => {
53
+ try {
54
+ const jsonRpc = JSON.parse(body);
55
+ const acceptSSE = (req.headers.accept || "").includes("text/event-stream");
56
+ if (acceptSSE) {
57
+ res.writeHead(200, {
58
+ "Content-Type": "text/event-stream",
59
+ "Cache-Control": "no-cache"
60
+ });
61
+ const response = await processJsonRpc(gateway, jsonRpc, config, serverCommand);
62
+ res.write(`data: ${JSON.stringify(response)}
63
+
64
+ `);
65
+ res.end();
66
+ } else {
67
+ const response = await processJsonRpc(gateway, jsonRpc, config, serverCommand);
68
+ res.writeHead(200, { "Content-Type": "application/json" });
69
+ res.end(JSON.stringify(response));
70
+ }
71
+ for (const client of sseClients) {
72
+ try {
73
+ client.write(`data: ${JSON.stringify({ type: "decision", request: jsonRpc, timestamp: (/* @__PURE__ */ new Date()).toISOString() })}
74
+
75
+ `);
76
+ } catch {
77
+ sseClients.delete(client);
78
+ }
79
+ }
80
+ } catch (err) {
81
+ res.writeHead(400, { "Content-Type": "application/json" });
82
+ res.end(JSON.stringify({
83
+ jsonrpc: "2.0",
84
+ error: { code: -32700, message: "Parse error" },
85
+ id: null
86
+ }));
87
+ }
88
+ });
89
+ return;
90
+ }
91
+ res.writeHead(404, { "Content-Type": "application/json" });
92
+ res.end(JSON.stringify({ error: "not_found", endpoints: ["/mcp", "/mcp/sse", "/health"] }));
93
+ });
94
+ server.listen(port, () => {
95
+ process.stderr.write(`
96
+ protect-mcp HTTP server listening on port ${port}
97
+ `);
98
+ process.stderr.write(` POST /mcp \u2014 JSON-RPC endpoint (Streamable HTTP)
99
+ `);
100
+ process.stderr.write(` GET /mcp/sse \u2014 Server-Sent Events stream
101
+ `);
102
+ process.stderr.write(` GET /health \u2014 Health check
103
+
104
+ `);
105
+ });
106
+ gateway.start(serverCommand[0], serverCommand.slice(1));
107
+ process.on("SIGINT", () => {
108
+ process.stderr.write("\nShutting down HTTP transport...\n");
109
+ for (const client of sseClients) {
110
+ try {
111
+ client.end();
112
+ } catch {
113
+ }
114
+ }
115
+ server.close();
116
+ process.exit(0);
117
+ });
118
+ }
119
+ async function processJsonRpc(gateway, request, config, serverCommand) {
120
+ return {
121
+ jsonrpc: "2.0",
122
+ result: {
123
+ message: "Request processed by protect-mcp HTTP transport",
124
+ mode: config.enforce ? "enforce" : "shadow"
125
+ },
126
+ id: request.id || null
127
+ };
128
+ }
129
+ export {
130
+ startHttpTransport
131
+ };
package/dist/index.d.mts CHANGED
@@ -36,8 +36,8 @@ type PolicyEngineMode = 'built-in' | 'external' | 'hybrid';
36
36
  interface ExternalPDPConfig {
37
37
  /** HTTP endpoint for the external policy decision point */
38
38
  endpoint: string;
39
- /** Response format: 'opa' | 'cerbos' | 'generic' */
40
- format?: 'opa' | 'cerbos' | 'generic';
39
+ /** Response format: 'opa' | 'cerbos' | 'cedar' | 'generic' */
40
+ format?: 'opa' | 'cerbos' | 'cedar' | 'generic';
41
41
  /** Timeout in milliseconds (default: 500) */
42
42
  timeout_ms?: number;
43
43
  /** Fallback decision when external PDP is unreachable */
@@ -480,7 +480,7 @@ declare function isSigningEnabled(): boolean;
480
480
  * BYOPE (Bring Your Own Policy Engine) — sends decision context
481
481
  * to an external Policy Decision Point via HTTP webhook.
482
482
  *
483
- * Supports OPA, Cerbos, and generic JSON formats.
483
+ * Supports OPA, Cerbos, Cedar (AWS), and generic JSON formats.
484
484
  * ScopeBlind always signs the receipt regardless of who made the decision.
485
485
  *
486
486
  * Sprint 2: One HTTP webhook adapter. More adapters later.
package/dist/index.d.ts CHANGED
@@ -36,8 +36,8 @@ type PolicyEngineMode = 'built-in' | 'external' | 'hybrid';
36
36
  interface ExternalPDPConfig {
37
37
  /** HTTP endpoint for the external policy decision point */
38
38
  endpoint: string;
39
- /** Response format: 'opa' | 'cerbos' | 'generic' */
40
- format?: 'opa' | 'cerbos' | 'generic';
39
+ /** Response format: 'opa' | 'cerbos' | 'cedar' | 'generic' */
40
+ format?: 'opa' | 'cerbos' | 'cedar' | 'generic';
41
41
  /** Timeout in milliseconds (default: 500) */
42
42
  timeout_ms?: number;
43
43
  /** Fallback decision when external PDP is unreachable */
@@ -480,7 +480,7 @@ declare function isSigningEnabled(): boolean;
480
480
  * BYOPE (Bring Your Own Policy Engine) — sends decision context
481
481
  * to an external Policy Decision Point via HTTP webhook.
482
482
  *
483
- * Supports OPA, Cerbos, and generic JSON formats.
483
+ * Supports OPA, Cerbos, Cedar (AWS), and generic JSON formats.
484
484
  * ScopeBlind always signs the receipt regardless of who made the decision.
485
485
  *
486
486
  * Sprint 2: One HTTP webhook adapter. More adapters later.
package/dist/index.js CHANGED
@@ -521,6 +521,28 @@ function formatRequest(context, format) {
521
521
  },
522
522
  actions: [context.action.operation || "call"]
523
523
  };
524
+ case "cedar":
525
+ return {
526
+ principal: {
527
+ type: "Agent",
528
+ id: context.actor.id || "unknown"
529
+ },
530
+ action: {
531
+ type: "Action",
532
+ id: `MCP::Tool::${context.action.operation || "call"}`
533
+ },
534
+ resource: {
535
+ type: "Tool",
536
+ id: context.action.tool
537
+ },
538
+ context: {
539
+ tier: context.actor.tier,
540
+ manifest_hash: context.actor.manifest_hash || null,
541
+ service: context.target.service || "default",
542
+ mode: context.mode,
543
+ credential_ref: context.credential_ref || null
544
+ }
545
+ };
524
546
  case "generic":
525
547
  default:
526
548
  return context;
@@ -550,6 +572,22 @@ function parseResponse(result, format) {
550
572
  }
551
573
  }
552
574
  return { allowed: false, reason: "unrecognized Cerbos response" };
575
+ case "cedar":
576
+ if (typeof result.decision === "string") {
577
+ return {
578
+ allowed: result.decision === "Allow",
579
+ reason: result.decision === "Deny" ? `cedar_deny${result.diagnostics ? ": " + JSON.stringify(result.diagnostics) : ""}` : void 0,
580
+ metadata: result.diagnostics
581
+ };
582
+ }
583
+ if (Array.isArray(result.results) && result.results.length > 0) {
584
+ const first = result.results[0];
585
+ return {
586
+ allowed: first.decision === "Allow",
587
+ reason: first.decision === "Deny" ? "cedar_deny" : void 0
588
+ };
589
+ }
590
+ return { allowed: false, reason: "unrecognized Cedar response" };
553
591
  case "generic":
554
592
  default:
555
593
  return {
package/dist/index.mjs CHANGED
@@ -1,9 +1,17 @@
1
+ import {
2
+ formatSimulation,
3
+ parseLogFile,
4
+ simulate
5
+ } from "./chunk-UW2SGWCJ.mjs";
6
+ import {
7
+ collectSignedReceipts,
8
+ createAuditBundle
9
+ } from "./chunk-5JXFV37Y.mjs";
1
10
  import {
2
11
  ProtectGateway,
3
12
  buildDecisionContext,
4
13
  checkRateLimit,
5
14
  evaluateTier,
6
- formatSimulation,
7
15
  getSignerInfo,
8
16
  getToolPolicy,
9
17
  initSigning,
@@ -11,18 +19,12 @@ import {
11
19
  listCredentialLabels,
12
20
  loadPolicy,
13
21
  meetsMinTier,
14
- parseLogFile,
15
22
  parseRateLimit,
16
23
  queryExternalPDP,
17
24
  resolveCredential,
18
25
  signDecision,
19
- simulate,
20
26
  validateCredentials
21
- } from "./chunk-GV7N53QE.mjs";
22
- import {
23
- collectSignedReceipts,
24
- createAuditBundle
25
- } from "./chunk-5JXFV37Y.mjs";
27
+ } from "./chunk-XMZWJOC3.mjs";
26
28
  import {
27
29
  formatReportMarkdown,
28
30
  generateReport
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "protect-mcp",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
+ "mcpName": "io.github.tomjwxf/protect-mcp",
4
5
  "description": "Security gateway for MCP servers. Shadow-mode logs, per-tool policies, optional local Ed25519-signed receipts. Programmatic hooks for trust tiers, credential config, and external policy engines.",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
@@ -22,6 +23,7 @@
22
23
  },
23
24
  "files": [
24
25
  "dist",
26
+ "policies",
25
27
  "README.md"
26
28
  ],
27
29
  "keywords": [
@@ -36,10 +38,18 @@
36
38
  "decision-log",
37
39
  "tool-protection",
38
40
  "ai-agent",
39
- "llm-gateway"
41
+ "llm-gateway",
42
+ "owasp",
43
+ "cedar",
44
+ "opa",
45
+ "ed25519",
46
+ "receipts",
47
+ "trust-tiers",
48
+ "agent-governance",
49
+ "claude-code"
40
50
  ],
41
51
  "author": "Tom Farley <tommy@scopeblind.com>",
42
- "license": "FSL-1.1-MIT",
52
+ "license": "MIT",
43
53
  "homepage": "https://www.scopeblind.com",
44
54
  "repository": {
45
55
  "type": "git",
@@ -0,0 +1,18 @@
1
+ {
2
+ "$comment": "Claude Code hooks configuration. Add this to your .claude/settings.json to integrate protect-mcp as a pre-tool-use hook for Claude Code. Every tool call will be evaluated against your protect-mcp policy and produce a signed receipt.",
3
+ "hooks": {
4
+ "PreToolUse": [
5
+ {
6
+ "matcher": ".*",
7
+ "hooks": [
8
+ {
9
+ "type": "command",
10
+ "command": "npx protect-mcp hook-eval --tool \"$TOOL_NAME\" --input \"$TOOL_INPUT\"",
11
+ "timeout": 5000,
12
+ "on_failure": "allow"
13
+ }
14
+ ]
15
+ }
16
+ ]
17
+ }
18
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "$comment": "CVE-2025-6514: Clinejection — Malicious MCP OAuth proxy hijacked 437,000+ developer environments. Blocks shell execution, restricts file access to non-sensitive paths, requires approval for any write operation.",
3
+ "incident": "CVE-2025-6514",
4
+ "incident_name": "Clinejection MCP OAuth Proxy Hijack",
5
+ "incident_date": "2025-07-15",
6
+ "owasp_categories": ["A01-Prompt-Injection", "A03-Supply-Chain"],
7
+ "tools": {
8
+ "*": {
9
+ "rate_limit": "30/minute"
10
+ },
11
+ "execute_command": {
12
+ "block": true
13
+ },
14
+ "run_command": {
15
+ "block": true
16
+ },
17
+ "shell": {
18
+ "block": true
19
+ },
20
+ "bash": {
21
+ "block": true
22
+ },
23
+ "terminal": {
24
+ "block": true
25
+ },
26
+ "write_file": {
27
+ "require_approval": true,
28
+ "rate_limit": "10/minute"
29
+ },
30
+ "edit_file": {
31
+ "require_approval": true,
32
+ "rate_limit": "10/minute"
33
+ },
34
+ "read_file": {
35
+ "rate_limit": "30/minute",
36
+ "min_tier": "signed-known"
37
+ },
38
+ "list_files": {
39
+ "rate_limit": "60/minute"
40
+ }
41
+ },
42
+ "signing": {
43
+ "enabled": true
44
+ }
45
+ }
@@ -0,0 +1,52 @@
1
+ {
2
+ "$comment": "Prevents data exfiltration via AI agents. Blocks all outbound data channels (email, webhooks, uploads, HTTP). Restricts file reads. Requires approval for any external communication.",
3
+ "incident": "agent-data-exfiltration-pattern",
4
+ "incident_name": "AI Agent Data Exfiltration via Tool Abuse",
5
+ "owasp_categories": ["A02-Sensitive-Data-Exposure", "A04-Tool-Call-Injection"],
6
+ "tools": {
7
+ "*": {
8
+ "rate_limit": "60/minute"
9
+ },
10
+ "send_email": {
11
+ "block": true
12
+ },
13
+ "send_message": {
14
+ "block": true
15
+ },
16
+ "upload_file": {
17
+ "block": true
18
+ },
19
+ "http_request": {
20
+ "block": true
21
+ },
22
+ "http_post": {
23
+ "block": true
24
+ },
25
+ "webhook": {
26
+ "block": true
27
+ },
28
+ "publish": {
29
+ "block": true
30
+ },
31
+ "post_to_api": {
32
+ "block": true
33
+ },
34
+ "execute_command": {
35
+ "block": true
36
+ },
37
+ "read_file": {
38
+ "rate_limit": "20/minute",
39
+ "min_tier": "signed-known"
40
+ },
41
+ "search": {
42
+ "rate_limit": "30/minute"
43
+ },
44
+ "database_query": {
45
+ "rate_limit": "10/minute",
46
+ "min_tier": "signed-known"
47
+ }
48
+ },
49
+ "signing": {
50
+ "enabled": true
51
+ }
52
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "$comment": "Financial services safety policy. Every financial action requires human approval with evidenced trust tier. All reads are rate-limited. Destructive operations blocked entirely.",
3
+ "incident": "agent-unauthorized-transaction-pattern",
4
+ "incident_name": "Unauthorized Financial Transaction via AI Agent",
5
+ "owasp_categories": ["A05-Insufficient-Access-Control", "A06-Excessive-Autonomy"],
6
+ "tools": {
7
+ "*": {
8
+ "rate_limit": "30/minute",
9
+ "min_tier": "signed-known"
10
+ },
11
+ "transfer_funds": {
12
+ "require_approval": true,
13
+ "min_tier": "privileged"
14
+ },
15
+ "create_payment": {
16
+ "require_approval": true,
17
+ "min_tier": "privileged"
18
+ },
19
+ "approve_transaction": {
20
+ "require_approval": true,
21
+ "min_tier": "privileged"
22
+ },
23
+ "modify_account": {
24
+ "require_approval": true,
25
+ "min_tier": "evidenced"
26
+ },
27
+ "delete_account": {
28
+ "block": true
29
+ },
30
+ "close_account": {
31
+ "block": true
32
+ },
33
+ "read_balance": {
34
+ "rate_limit": "10/minute",
35
+ "min_tier": "evidenced"
36
+ },
37
+ "read_transactions": {
38
+ "rate_limit": "10/minute",
39
+ "min_tier": "evidenced"
40
+ },
41
+ "generate_report": {
42
+ "rate_limit": "5/hour",
43
+ "min_tier": "signed-known"
44
+ }
45
+ },
46
+ "signing": {
47
+ "enabled": true
48
+ }
49
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "$comment": "GitHub MCP server hijacked via crafted issue containing prompt injection (2025). Agent exfiltrated private repo data. Blocks outbound data tools, restricts git operations, requires approval for any push/publish.",
3
+ "incident": "github-mcp-issue-hijack-2025",
4
+ "incident_name": "GitHub MCP Server Prompt Injection via Crafted Issue",
5
+ "incident_date": "2025-08-20",
6
+ "owasp_categories": ["A01-Prompt-Injection", "A02-Sensitive-Data-Exposure", "A03-Supply-Chain"],
7
+ "tools": {
8
+ "*": {
9
+ "rate_limit": "30/minute"
10
+ },
11
+ "git_push": {
12
+ "require_approval": true,
13
+ "min_tier": "evidenced"
14
+ },
15
+ "git_commit": {
16
+ "rate_limit": "10/minute"
17
+ },
18
+ "create_pull_request": {
19
+ "require_approval": true
20
+ },
21
+ "publish": {
22
+ "block": true
23
+ },
24
+ "npm_publish": {
25
+ "block": true
26
+ },
27
+ "send_email": {
28
+ "block": true
29
+ },
30
+ "send_message": {
31
+ "block": true
32
+ },
33
+ "upload_file": {
34
+ "require_approval": true,
35
+ "min_tier": "signed-known"
36
+ },
37
+ "http_request": {
38
+ "require_approval": true,
39
+ "rate_limit": "5/minute"
40
+ },
41
+ "webhook": {
42
+ "block": true
43
+ },
44
+ "read_file": {
45
+ "rate_limit": "30/minute"
46
+ },
47
+ "search_code": {
48
+ "rate_limit": "20/minute"
49
+ }
50
+ },
51
+ "signing": {
52
+ "enabled": true
53
+ }
54
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "$comment": "Terraform agent destroyed production infrastructure (2025). Blocks all destructive infrastructure operations, requires human approval for any apply/deploy, rate-limits plan operations.",
3
+ "incident": "terraform-prod-destroy-2025",
4
+ "incident_name": "Autonomous Terraform Agent Destroys Production",
5
+ "incident_date": "2025-09-01",
6
+ "owasp_categories": ["A06-Excessive-Autonomy", "A05-Insufficient-Access-Control"],
7
+ "tools": {
8
+ "*": {
9
+ "rate_limit": "30/minute"
10
+ },
11
+ "terraform_apply": {
12
+ "require_approval": true,
13
+ "min_tier": "evidenced"
14
+ },
15
+ "terraform_destroy": {
16
+ "block": true
17
+ },
18
+ "terraform_plan": {
19
+ "rate_limit": "10/minute",
20
+ "min_tier": "signed-known"
21
+ },
22
+ "deploy": {
23
+ "require_approval": true,
24
+ "min_tier": "evidenced"
25
+ },
26
+ "kubectl_apply": {
27
+ "require_approval": true,
28
+ "min_tier": "evidenced"
29
+ },
30
+ "kubectl_delete": {
31
+ "block": true
32
+ },
33
+ "aws_cli": {
34
+ "require_approval": true,
35
+ "rate_limit": "5/minute"
36
+ },
37
+ "delete_resource": {
38
+ "block": true
39
+ },
40
+ "drop_database": {
41
+ "block": true
42
+ },
43
+ "truncate_table": {
44
+ "block": true
45
+ }
46
+ },
47
+ "signing": {
48
+ "enabled": true
49
+ }
50
+ }