protect-mcp 0.3.1 → 0.3.3
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 +68 -0
- package/README.md +42 -2
- package/dist/chunk-JQDVKZBN.mjs +165 -0
- package/dist/{chunk-U7TMVD3E.mjs → chunk-WDCPUM2O.mjs} +202 -3
- package/dist/cli.js +804 -31
- package/dist/cli.mjs +414 -6
- package/dist/index.d.mts +151 -4
- package/dist/index.d.ts +151 -4
- package/dist/index.js +369 -12
- package/dist/index.mjs +13 -1
- package/dist/report-ENQ3KUI2.mjs +8 -0
- package/package.json +13 -3
- package/policies/claude-code-hooks.json +18 -0
- package/policies/clinejection.json +45 -0
- package/policies/data-exfiltration.json +52 -0
- package/policies/financial-safe.json +49 -0
- package/policies/github-mcp-hijack.json +54 -0
- package/policies/terraform-destroy.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
SPDX-License-Identifier: LicenseRef-FSL-1.1-MIT
|
|
2
|
+
|
|
3
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
4
|
+
|
|
5
|
+
## Abbreviation
|
|
6
|
+
|
|
7
|
+
FSL-1.1-MIT
|
|
8
|
+
|
|
9
|
+
## Notice
|
|
10
|
+
|
|
11
|
+
Copyright 2026 Tom Farley
|
|
12
|
+
|
|
13
|
+
## Terms and Conditions
|
|
14
|
+
|
|
15
|
+
### Licensor ("We")
|
|
16
|
+
|
|
17
|
+
The party offering the Software under these Terms and Conditions.
|
|
18
|
+
|
|
19
|
+
### The Software
|
|
20
|
+
|
|
21
|
+
The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
|
|
26
|
+
|
|
27
|
+
### Permitted Purpose
|
|
28
|
+
|
|
29
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
|
|
30
|
+
|
|
31
|
+
1. substitutes for the Software;
|
|
32
|
+
2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
|
|
33
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
34
|
+
|
|
35
|
+
Permitted Purposes specifically include using the Software:
|
|
36
|
+
|
|
37
|
+
1. for your internal use and access;
|
|
38
|
+
2. for non-commercial education;
|
|
39
|
+
3. for non-commercial research; and
|
|
40
|
+
4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
|
|
41
|
+
|
|
42
|
+
### Patents
|
|
43
|
+
|
|
44
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
|
|
45
|
+
|
|
46
|
+
### Redistribution
|
|
47
|
+
|
|
48
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of the Software. If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
|
|
49
|
+
|
|
50
|
+
### Disclaimer
|
|
51
|
+
|
|
52
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT. IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
53
|
+
|
|
54
|
+
### Trademarks
|
|
55
|
+
|
|
56
|
+
Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
|
|
57
|
+
|
|
58
|
+
## Grant of Future License
|
|
59
|
+
|
|
60
|
+
We hereby irrevocably grant you an additional license to use the Software under the MIT license that is effective on the second anniversary of the date we make the Software available.
|
|
61
|
+
|
|
62
|
+
On or after that date, you may use the Software under the MIT license, in which case the following will apply:
|
|
63
|
+
|
|
64
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
65
|
+
|
|
66
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
67
|
+
|
|
68
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -210,8 +210,48 @@ Use `createAuditBundle()` around your own collected signed receipts.
|
|
|
210
210
|
- **Keep the claims tight.** The default CLI path does not yet do everything the long-term architecture will support.
|
|
211
211
|
- **Layer on top of existing auth.** Don't rip out your stack just to add control and evidence.
|
|
212
212
|
|
|
213
|
+
## Incident-Anchored Policy Packs
|
|
214
|
+
|
|
215
|
+
Ship with protect-mcp — each prevents a real attack:
|
|
216
|
+
|
|
217
|
+
| Policy | Incident | OWASP Categories |
|
|
218
|
+
|--------|----------|-----------------|
|
|
219
|
+
| `clinejection.json` | CVE-2025-6514: MCP OAuth proxy hijack (437K environments) | A01, A03 |
|
|
220
|
+
| `terraform-destroy.json` | Autonomous Terraform agent destroys production | A05, A06 |
|
|
221
|
+
| `github-mcp-hijack.json` | Prompt injection via crafted GitHub issue | A01, A02, A03 |
|
|
222
|
+
| `data-exfiltration.json` | Agent data theft via outbound tool abuse | A02, A04 |
|
|
223
|
+
| `financial-safe.json` | Unauthorized financial transaction | A05, A06 |
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
npx protect-mcp --policy node_modules/protect-mcp/policies/clinejection.json -- node server.js
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Full OWASP Agentic Top 10 mapping: [scopeblind.com/docs/owasp](https://scopeblind.com/docs/owasp)
|
|
230
|
+
|
|
231
|
+
## BYOPE: External Policy Engines
|
|
232
|
+
|
|
233
|
+
Supports OPA, Cerbos, Cedar (AWS AgentCore), and generic HTTP endpoints:
|
|
234
|
+
|
|
235
|
+
```json
|
|
236
|
+
{
|
|
237
|
+
"policy_engine": "hybrid",
|
|
238
|
+
"external": {
|
|
239
|
+
"endpoint": "http://localhost:8181/v1/data/mcp/allow",
|
|
240
|
+
"format": "cedar",
|
|
241
|
+
"timeout_ms": 200,
|
|
242
|
+
"fallback": "deny"
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Standards & IP
|
|
248
|
+
|
|
249
|
+
- **IETF Internet-Draft**: [draft-farley-acta-signed-receipts-00](https://datatracker.ietf.org/doc/draft-farley-acta-signed-receipts/) — Signed Decision Receipts for Machine-to-Machine Access Control
|
|
250
|
+
- **Patent Status**: 4 Australian provisional patents pending (2025-2026) covering decision receipts with configurable disclosure, tool-calling gateway, agent manifests, and portable identity
|
|
251
|
+
- **Verification**: MIT-licensed — `npx @veritasacta/verify --self-test`
|
|
252
|
+
|
|
213
253
|
## License
|
|
214
254
|
|
|
215
|
-
FSL-1.1-MIT — free to use,
|
|
255
|
+
FSL-1.1-MIT — free to use, modify, and self-host. Cannot be offered as a competing hosted service. Converts to full MIT after 2 years per version.
|
|
216
256
|
|
|
217
|
-
[scopeblind.com](https://scopeblind.com) · [npm](https://www.npmjs.com/package/protect-mcp) · [GitHub](https://github.com/tomjwxf/scopeblind-gateway)
|
|
257
|
+
[scopeblind.com](https://scopeblind.com) · [npm](https://www.npmjs.com/package/protect-mcp) · [GitHub](https://github.com/tomjwxf/scopeblind-gateway) · [IETF Draft](https://datatracker.ietf.org/doc/draft-farley-acta-signed-receipts/)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// src/report.ts
|
|
2
|
+
import { readFileSync, existsSync } from "fs";
|
|
3
|
+
function generateReport(logPath, receiptPath, periodDays) {
|
|
4
|
+
const now = /* @__PURE__ */ new Date();
|
|
5
|
+
const from = new Date(now.getTime() - periodDays * 864e5);
|
|
6
|
+
const entries = [];
|
|
7
|
+
if (existsSync(logPath)) {
|
|
8
|
+
const raw = readFileSync(logPath, "utf-8");
|
|
9
|
+
for (const line of raw.split("\n")) {
|
|
10
|
+
const trimmed = line.trim();
|
|
11
|
+
if (!trimmed) continue;
|
|
12
|
+
const jsonStr = trimmed.replace(/^\[PROTECT_MCP\]\s*/, "");
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(jsonStr);
|
|
15
|
+
if (parsed.tool && parsed.decision && parsed.timestamp) {
|
|
16
|
+
const entryTime = typeof parsed.timestamp === "number" && parsed.timestamp > 1e12 ? parsed.timestamp : parsed.timestamp * 1e3;
|
|
17
|
+
if (entryTime >= from.getTime()) {
|
|
18
|
+
entries.push(parsed);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
let receiptsSigned = 0;
|
|
26
|
+
let signerKid = "";
|
|
27
|
+
let signerIssuer = "";
|
|
28
|
+
if (existsSync(receiptPath)) {
|
|
29
|
+
const raw = readFileSync(receiptPath, "utf-8");
|
|
30
|
+
for (const line of raw.split("\n")) {
|
|
31
|
+
const trimmed = line.trim();
|
|
32
|
+
if (!trimmed) continue;
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(trimmed);
|
|
35
|
+
if (parsed.signature) {
|
|
36
|
+
receiptsSigned++;
|
|
37
|
+
if (parsed.kid && !signerKid) signerKid = parsed.kid;
|
|
38
|
+
if (parsed.issuer && !signerIssuer) signerIssuer = parsed.issuer;
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const toolMap = /* @__PURE__ */ new Map();
|
|
45
|
+
const tiers = /* @__PURE__ */ new Set();
|
|
46
|
+
const policyDigests = /* @__PURE__ */ new Map();
|
|
47
|
+
let allowed = 0;
|
|
48
|
+
let blocked = 0;
|
|
49
|
+
let rateLimited = 0;
|
|
50
|
+
let approvalRequired = 0;
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
const tool = entry.tool;
|
|
53
|
+
if (!toolMap.has(tool)) {
|
|
54
|
+
toolMap.set(tool, { total: 0, allowed: 0, blocked: 0, rate_limited: 0, approval_required: 0 });
|
|
55
|
+
}
|
|
56
|
+
const tm = toolMap.get(tool);
|
|
57
|
+
tm.total++;
|
|
58
|
+
if (entry.decision === "allow") {
|
|
59
|
+
allowed++;
|
|
60
|
+
tm.allowed++;
|
|
61
|
+
} else if (entry.decision === "deny" && entry.reason_code === "rate_limit_exceeded") {
|
|
62
|
+
rateLimited++;
|
|
63
|
+
tm.rate_limited++;
|
|
64
|
+
} else if (entry.decision === "deny" && entry.reason_code === "require_approval") {
|
|
65
|
+
approvalRequired++;
|
|
66
|
+
tm.approval_required++;
|
|
67
|
+
} else {
|
|
68
|
+
blocked++;
|
|
69
|
+
tm.blocked++;
|
|
70
|
+
}
|
|
71
|
+
if (entry.tier) tiers.add(entry.tier);
|
|
72
|
+
if (entry.policy_digest && !policyDigests.has(entry.policy_digest)) {
|
|
73
|
+
policyDigests.set(entry.policy_digest, new Date(entry.timestamp).toISOString());
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const policyChanges = Array.from(policyDigests.entries()).map(([digest, at]) => ({
|
|
77
|
+
at,
|
|
78
|
+
policy_digest: digest
|
|
79
|
+
})).sort((a, b) => a.at.localeCompare(b.at));
|
|
80
|
+
return {
|
|
81
|
+
generated_at: now.toISOString(),
|
|
82
|
+
period: { from: from.toISOString(), to: now.toISOString() },
|
|
83
|
+
signing_identity: signerKid ? { kid: signerKid, issuer: signerIssuer } : null,
|
|
84
|
+
summary: {
|
|
85
|
+
total_decisions: entries.length,
|
|
86
|
+
allowed,
|
|
87
|
+
blocked,
|
|
88
|
+
rate_limited: rateLimited,
|
|
89
|
+
approval_required: approvalRequired,
|
|
90
|
+
unique_tools: toolMap.size,
|
|
91
|
+
unique_tiers: tiers.size
|
|
92
|
+
},
|
|
93
|
+
tool_breakdown: Array.from(toolMap.entries()).map(([tool, stats]) => ({ tool, ...stats })).sort((a, b) => b.total - a.total),
|
|
94
|
+
policy_changes: policyChanges,
|
|
95
|
+
verification: {
|
|
96
|
+
receipts_signed: receiptsSigned,
|
|
97
|
+
receipts_unsigned: entries.length - receiptsSigned,
|
|
98
|
+
verify_command: "npx @veritasacta/verify audit-bundle.json --bundle"
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function formatReportMarkdown(report) {
|
|
103
|
+
const lines = [];
|
|
104
|
+
lines.push("# ScopeBlind Compliance Report");
|
|
105
|
+
lines.push("");
|
|
106
|
+
lines.push(`**Generated:** ${report.generated_at}`);
|
|
107
|
+
lines.push(`**Period:** ${report.period.from.split("T")[0]} to ${report.period.to.split("T")[0]}`);
|
|
108
|
+
if (report.signing_identity) {
|
|
109
|
+
lines.push(`**Signing identity:** kid \`${report.signing_identity.kid}\`, issuer \`${report.signing_identity.issuer}\``);
|
|
110
|
+
}
|
|
111
|
+
lines.push("");
|
|
112
|
+
lines.push("## Summary");
|
|
113
|
+
lines.push("");
|
|
114
|
+
lines.push(`| Metric | Value |`);
|
|
115
|
+
lines.push(`|--------|-------|`);
|
|
116
|
+
lines.push(`| Total decisions | ${report.summary.total_decisions} |`);
|
|
117
|
+
lines.push(`| Allowed | ${report.summary.allowed} |`);
|
|
118
|
+
lines.push(`| Blocked | ${report.summary.blocked} |`);
|
|
119
|
+
lines.push(`| Rate-limited | ${report.summary.rate_limited} |`);
|
|
120
|
+
lines.push(`| Approval required | ${report.summary.approval_required} |`);
|
|
121
|
+
lines.push(`| Unique tools | ${report.summary.unique_tools} |`);
|
|
122
|
+
lines.push(`| Unique tiers | ${report.summary.unique_tiers} |`);
|
|
123
|
+
lines.push("");
|
|
124
|
+
if (report.tool_breakdown.length > 0) {
|
|
125
|
+
lines.push("## Tool Breakdown");
|
|
126
|
+
lines.push("");
|
|
127
|
+
lines.push("| Tool | Total | Allowed | Blocked | Rate-limited | Approval |");
|
|
128
|
+
lines.push("|------|-------|---------|---------|--------------|----------|");
|
|
129
|
+
for (const t of report.tool_breakdown) {
|
|
130
|
+
lines.push(`| \`${t.tool}\` | ${t.total} | ${t.allowed} | ${t.blocked} | ${t.rate_limited} | ${t.approval_required} |`);
|
|
131
|
+
}
|
|
132
|
+
lines.push("");
|
|
133
|
+
}
|
|
134
|
+
if (report.policy_changes.length > 0) {
|
|
135
|
+
lines.push("## Policy History");
|
|
136
|
+
lines.push("");
|
|
137
|
+
lines.push("| Timestamp | Policy Digest |");
|
|
138
|
+
lines.push("|-----------|--------------|");
|
|
139
|
+
for (const pc of report.policy_changes) {
|
|
140
|
+
lines.push(`| ${pc.at} | \`${pc.policy_digest}\` |`);
|
|
141
|
+
}
|
|
142
|
+
lines.push("");
|
|
143
|
+
}
|
|
144
|
+
lines.push("## Verification");
|
|
145
|
+
lines.push("");
|
|
146
|
+
lines.push(`- Receipts signed: **${report.verification.receipts_signed}**`);
|
|
147
|
+
lines.push(`- Receipts unsigned: **${report.verification.receipts_unsigned}**`);
|
|
148
|
+
lines.push("");
|
|
149
|
+
lines.push("Verify the audit bundle:");
|
|
150
|
+
lines.push("");
|
|
151
|
+
lines.push("```bash");
|
|
152
|
+
lines.push(report.verification.verify_command);
|
|
153
|
+
lines.push("```");
|
|
154
|
+
lines.push("");
|
|
155
|
+
lines.push("The verifier is MIT-licensed and works offline. No ScopeBlind account required.");
|
|
156
|
+
lines.push("");
|
|
157
|
+
lines.push("---");
|
|
158
|
+
lines.push("*Generated by protect-mcp \xB7 scopeblind.com*");
|
|
159
|
+
return lines.join("\n");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export {
|
|
163
|
+
generateReport,
|
|
164
|
+
formatReportMarkdown
|
|
165
|
+
};
|
|
@@ -317,7 +317,11 @@ async function initSigning(config) {
|
|
|
317
317
|
return warnings;
|
|
318
318
|
}
|
|
319
319
|
try {
|
|
320
|
-
|
|
320
|
+
const moduleName = "@veritasacta/artifacts";
|
|
321
|
+
artifactsModule = await import(
|
|
322
|
+
/* @vite-ignore */
|
|
323
|
+
moduleName
|
|
324
|
+
);
|
|
321
325
|
} catch {
|
|
322
326
|
warnings.push("signing: @veritasacta/artifacts not available \u2014 receipts will be unsigned");
|
|
323
327
|
return warnings;
|
|
@@ -456,6 +460,28 @@ function formatRequest(context, format) {
|
|
|
456
460
|
},
|
|
457
461
|
actions: [context.action.operation || "call"]
|
|
458
462
|
};
|
|
463
|
+
case "cedar":
|
|
464
|
+
return {
|
|
465
|
+
principal: {
|
|
466
|
+
type: "Agent",
|
|
467
|
+
id: context.actor.id || "unknown"
|
|
468
|
+
},
|
|
469
|
+
action: {
|
|
470
|
+
type: "Action",
|
|
471
|
+
id: `MCP::Tool::${context.action.operation || "call"}`
|
|
472
|
+
},
|
|
473
|
+
resource: {
|
|
474
|
+
type: "Tool",
|
|
475
|
+
id: context.action.tool
|
|
476
|
+
},
|
|
477
|
+
context: {
|
|
478
|
+
tier: context.actor.tier,
|
|
479
|
+
manifest_hash: context.actor.manifest_hash || null,
|
|
480
|
+
service: context.target.service || "default",
|
|
481
|
+
mode: context.mode,
|
|
482
|
+
credential_ref: context.credential_ref || null
|
|
483
|
+
}
|
|
484
|
+
};
|
|
459
485
|
case "generic":
|
|
460
486
|
default:
|
|
461
487
|
return context;
|
|
@@ -485,6 +511,22 @@ function parseResponse(result, format) {
|
|
|
485
511
|
}
|
|
486
512
|
}
|
|
487
513
|
return { allowed: false, reason: "unrecognized Cerbos response" };
|
|
514
|
+
case "cedar":
|
|
515
|
+
if (typeof result.decision === "string") {
|
|
516
|
+
return {
|
|
517
|
+
allowed: result.decision === "Allow",
|
|
518
|
+
reason: result.decision === "Deny" ? `cedar_deny${result.diagnostics ? ": " + JSON.stringify(result.diagnostics) : ""}` : void 0,
|
|
519
|
+
metadata: result.diagnostics
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
if (Array.isArray(result.results) && result.results.length > 0) {
|
|
523
|
+
const first = result.results[0];
|
|
524
|
+
return {
|
|
525
|
+
allowed: first.decision === "Allow",
|
|
526
|
+
reason: first.decision === "Deny" ? "cedar_deny" : void 0
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
return { allowed: false, reason: "unrecognized Cedar response" };
|
|
488
530
|
case "generic":
|
|
489
531
|
default:
|
|
490
532
|
return {
|
|
@@ -909,8 +951,31 @@ var ProtectGateway = class {
|
|
|
909
951
|
async interceptToolCall(request) {
|
|
910
952
|
const toolName = request.params?.name || "unknown";
|
|
911
953
|
const requestId = randomUUID().slice(0, 12);
|
|
912
|
-
const toolPolicy = getToolPolicy(toolName, this.config.policy);
|
|
913
954
|
const mode = this.config.enforce ? "enforce" : "shadow";
|
|
955
|
+
let resolvedAgentKid = this.admissionResult?.agent_id;
|
|
956
|
+
let effectiveToolPolicy;
|
|
957
|
+
if (this.config.multiAgent?.enabled) {
|
|
958
|
+
const paramKid = request.params?._passport_kid;
|
|
959
|
+
if (paramKid) resolvedAgentKid = paramKid;
|
|
960
|
+
const agentOverrides = resolvedAgentKid ? this.config.multiAgent.agentPolicies?.[resolvedAgentKid] : void 0;
|
|
961
|
+
if (agentOverrides && agentOverrides[toolName]) {
|
|
962
|
+
effectiveToolPolicy = { ...getToolPolicy(toolName, this.config.policy), ...agentOverrides[toolName] };
|
|
963
|
+
} else if (!resolvedAgentKid && this.config.multiAgent.unknownAgentPolicy === "deny") {
|
|
964
|
+
this.emitDecisionLog({ tool: toolName, decision: "deny", reason_code: "unknown_agent_denied", request_id: requestId, tier: this.currentTier });
|
|
965
|
+
if (this.config.enforce) {
|
|
966
|
+
return this.makeErrorResponse(request.id, -32600, `Tool "${toolName}" denied: unidentified agent`);
|
|
967
|
+
}
|
|
968
|
+
return null;
|
|
969
|
+
} else {
|
|
970
|
+
effectiveToolPolicy = getToolPolicy(toolName, this.config.policy);
|
|
971
|
+
}
|
|
972
|
+
if (this.config.verbose && resolvedAgentKid) {
|
|
973
|
+
this.log(`Multi-agent: resolved kid=${resolvedAgentKid} for tool=${toolName}`);
|
|
974
|
+
}
|
|
975
|
+
} else {
|
|
976
|
+
effectiveToolPolicy = getToolPolicy(toolName, this.config.policy);
|
|
977
|
+
}
|
|
978
|
+
const toolPolicy = effectiveToolPolicy;
|
|
914
979
|
let credentialRef;
|
|
915
980
|
if (this.config.credentials) {
|
|
916
981
|
const cred = resolveCredential(toolName, this.config.credentials);
|
|
@@ -1085,6 +1150,137 @@ var ProtectGateway = class {
|
|
|
1085
1150
|
}
|
|
1086
1151
|
};
|
|
1087
1152
|
|
|
1153
|
+
// src/simulate.ts
|
|
1154
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
1155
|
+
function parseLogFile(path) {
|
|
1156
|
+
const raw = readFileSync5(path, "utf-8");
|
|
1157
|
+
const entries = [];
|
|
1158
|
+
for (const line of raw.split("\n")) {
|
|
1159
|
+
const trimmed = line.trim();
|
|
1160
|
+
if (!trimmed) continue;
|
|
1161
|
+
const jsonStr = trimmed.replace(/^\[PROTECT_MCP\]\s*/, "");
|
|
1162
|
+
try {
|
|
1163
|
+
const parsed = JSON.parse(jsonStr);
|
|
1164
|
+
if (parsed.tool && parsed.decision) {
|
|
1165
|
+
entries.push(parsed);
|
|
1166
|
+
}
|
|
1167
|
+
} catch {
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
return entries;
|
|
1171
|
+
}
|
|
1172
|
+
function simulate(entries, policy, tier = "unknown") {
|
|
1173
|
+
const rateLimitStore = /* @__PURE__ */ new Map();
|
|
1174
|
+
const toolResults = /* @__PURE__ */ new Map();
|
|
1175
|
+
const totals = {
|
|
1176
|
+
allow: 0,
|
|
1177
|
+
block: 0,
|
|
1178
|
+
rate_limited: 0,
|
|
1179
|
+
require_approval: 0,
|
|
1180
|
+
tier_insufficient: 0
|
|
1181
|
+
};
|
|
1182
|
+
const originalTotals = { allow: 0, deny: 0 };
|
|
1183
|
+
const changes = [];
|
|
1184
|
+
for (const entry of entries) {
|
|
1185
|
+
const toolName = entry.tool;
|
|
1186
|
+
const toolPolicy = getToolPolicy(toolName, policy);
|
|
1187
|
+
if (entry.decision === "allow") {
|
|
1188
|
+
originalTotals.allow++;
|
|
1189
|
+
} else {
|
|
1190
|
+
originalTotals.deny++;
|
|
1191
|
+
}
|
|
1192
|
+
let newDecision;
|
|
1193
|
+
if (toolPolicy.block) {
|
|
1194
|
+
newDecision = "block";
|
|
1195
|
+
} else if (toolPolicy.min_tier && !meetsMinTier(tier, toolPolicy.min_tier)) {
|
|
1196
|
+
newDecision = "tier_insufficient";
|
|
1197
|
+
} else if (toolPolicy.require_approval) {
|
|
1198
|
+
newDecision = "require_approval";
|
|
1199
|
+
} else if (toolPolicy.rate_limit) {
|
|
1200
|
+
const limit = parseRateLimit(toolPolicy.rate_limit);
|
|
1201
|
+
const result = checkRateLimit(toolName, limit, rateLimitStore);
|
|
1202
|
+
newDecision = result.allowed ? "allow" : "rate_limited";
|
|
1203
|
+
} else {
|
|
1204
|
+
newDecision = "allow";
|
|
1205
|
+
}
|
|
1206
|
+
totals[newDecision]++;
|
|
1207
|
+
if (!toolResults.has(toolName)) {
|
|
1208
|
+
toolResults.set(toolName, {
|
|
1209
|
+
tool: toolName,
|
|
1210
|
+
calls: 0,
|
|
1211
|
+
results: { allow: 0, block: 0, rate_limited: 0, require_approval: 0, tier_insufficient: 0 },
|
|
1212
|
+
original: { allow: 0, deny: 0 }
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
const tr = toolResults.get(toolName);
|
|
1216
|
+
tr.calls++;
|
|
1217
|
+
tr.results[newDecision]++;
|
|
1218
|
+
if (entry.decision === "allow") {
|
|
1219
|
+
tr.original.allow++;
|
|
1220
|
+
} else {
|
|
1221
|
+
tr.original.deny++;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
for (const [tool, result] of toolResults) {
|
|
1225
|
+
const wasAllBlocked = result.original.allow === 0;
|
|
1226
|
+
const nowAllBlocked = result.results.allow === 0;
|
|
1227
|
+
const wasAllAllowed = result.original.deny === 0;
|
|
1228
|
+
if (wasAllAllowed && result.results.block > 0) {
|
|
1229
|
+
changes.push(`${tool}: ${result.results.block} calls would be blocked (was: all allowed)`);
|
|
1230
|
+
}
|
|
1231
|
+
if (wasAllAllowed && result.results.rate_limited > 0) {
|
|
1232
|
+
changes.push(`${tool}: ${result.results.rate_limited} calls would be rate-limited (was: all allowed)`);
|
|
1233
|
+
}
|
|
1234
|
+
if (wasAllAllowed && result.results.require_approval > 0) {
|
|
1235
|
+
changes.push(`${tool}: ${result.results.require_approval} calls would require approval (was: all allowed)`);
|
|
1236
|
+
}
|
|
1237
|
+
if (wasAllAllowed && result.results.tier_insufficient > 0) {
|
|
1238
|
+
changes.push(`${tool}: ${result.results.tier_insufficient} calls would fail tier check (was: all allowed)`);
|
|
1239
|
+
}
|
|
1240
|
+
if (wasAllBlocked && result.results.allow > 0 && !nowAllBlocked) {
|
|
1241
|
+
changes.push(`${tool}: ${result.results.allow} calls would now be allowed (was: all blocked)`);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return {
|
|
1245
|
+
policy_file: "",
|
|
1246
|
+
log_file: "",
|
|
1247
|
+
total_calls: entries.length,
|
|
1248
|
+
results: totals,
|
|
1249
|
+
original: originalTotals,
|
|
1250
|
+
tool_breakdown: Array.from(toolResults.values()).sort((a, b) => b.calls - a.calls),
|
|
1251
|
+
changes
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
function formatSimulation(summary) {
|
|
1255
|
+
const lines = [];
|
|
1256
|
+
lines.push(`Simulating ${summary.policy_file} against ${summary.total_calls} recorded tool calls:
|
|
1257
|
+
`);
|
|
1258
|
+
const maxToolLen = Math.max(...summary.tool_breakdown.map((t) => t.tool.length), 4);
|
|
1259
|
+
for (const tr of summary.tool_breakdown) {
|
|
1260
|
+
const parts = [];
|
|
1261
|
+
if (tr.results.allow > 0) parts.push(`${tr.results.allow} allow`);
|
|
1262
|
+
if (tr.results.block > 0) parts.push(`\x1B[31m${tr.results.block} blocked\x1B[0m`);
|
|
1263
|
+
if (tr.results.rate_limited > 0) parts.push(`\x1B[33m${tr.results.rate_limited} rate_limited\x1B[0m`);
|
|
1264
|
+
if (tr.results.require_approval > 0) parts.push(`\x1B[36m${tr.results.require_approval} require_approval\x1B[0m`);
|
|
1265
|
+
if (tr.results.tier_insufficient > 0) parts.push(`\x1B[35m${tr.results.tier_insufficient} tier_insufficient\x1B[0m`);
|
|
1266
|
+
const originalParts = [];
|
|
1267
|
+
if (tr.original.allow > 0) originalParts.push(`${tr.original.allow} allow`);
|
|
1268
|
+
if (tr.original.deny > 0) originalParts.push(`${tr.original.deny} deny`);
|
|
1269
|
+
lines.push(` ${tr.tool.padEnd(maxToolLen)} \xD7 ${String(tr.calls).padStart(3)} \u2192 ${parts.join(", ")} (was: ${originalParts.join(", ")})`);
|
|
1270
|
+
}
|
|
1271
|
+
lines.push("");
|
|
1272
|
+
lines.push(`Summary: ${summary.results.allow} allow, ${summary.results.block} blocked, ${summary.results.rate_limited} rate_limited, ${summary.results.require_approval} require_approval, ${summary.results.tier_insufficient} tier_insufficient`);
|
|
1273
|
+
lines.push(` vs original: ${summary.original.allow} allow, ${summary.original.deny} deny`);
|
|
1274
|
+
if (summary.changes.length > 0) {
|
|
1275
|
+
lines.push("");
|
|
1276
|
+
lines.push("Changes:");
|
|
1277
|
+
for (const change of summary.changes) {
|
|
1278
|
+
lines.push(` \u2022 ${change}`);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
return lines.join("\n");
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1088
1284
|
export {
|
|
1089
1285
|
loadPolicy,
|
|
1090
1286
|
getToolPolicy,
|
|
@@ -1101,5 +1297,8 @@ export {
|
|
|
1101
1297
|
isSigningEnabled,
|
|
1102
1298
|
queryExternalPDP,
|
|
1103
1299
|
buildDecisionContext,
|
|
1104
|
-
ProtectGateway
|
|
1300
|
+
ProtectGateway,
|
|
1301
|
+
parseLogFile,
|
|
1302
|
+
simulate,
|
|
1303
|
+
formatSimulation
|
|
1105
1304
|
};
|