@crawlcheck/sdk 1.2.0 → 1.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/index.js +7 -5
- package/dist/mcp.d.ts +3 -2
- package/dist/mcp.js +27 -14
- package/dist/verify.d.ts +2 -1
- package/dist/verify.js +35 -7
- package/package.json +1 -1
- package/test/fixtures/guard-acceptance.json +610 -430
- package/test/mcp.test.js +21 -1
package/test/mcp.test.js
CHANGED
|
@@ -5,7 +5,7 @@ import { withPreflight, mcpPreflight, McpPreflightRefused, transportUrl, lockFro
|
|
|
5
5
|
function cc(table) {
|
|
6
6
|
const calls = [];
|
|
7
7
|
return { calls, async guard(host, action, opts) {
|
|
8
|
-
calls.push({ host, action, template: opts.template });
|
|
8
|
+
calls.push({ host, action, template: opts.template, tool: opts.operation && opts.operation.tool, op: opts.operation });
|
|
9
9
|
const d = table[host] || "unsupported";
|
|
10
10
|
const receipt = { kind: "crawlcheck-decision", domain: host, action, decision: d, expires_at: new Date(Date.now() + 3600e3).toISOString(), steps: [{ why: "table" }], sha256: "x", signature: { kid: "k" } };
|
|
11
11
|
let proceed = d === "allow" || (d === "warn" && !!opts.allowWarn);
|
|
@@ -79,3 +79,23 @@ test("bare hooks work without a client object", async () => {
|
|
|
79
79
|
const r = await h.beforeConnect("https://good.example/mcp"); assert.equal(r.host, "good.example");
|
|
80
80
|
assert.equal((await h.beforeToolCall("search")).receipt.decision, "allow");
|
|
81
81
|
});
|
|
82
|
+
|
|
83
|
+
test("1.4.0: a write tool call gets its own receipt, scoped to the tool's definition; a read-only one reuses connect", async () => {
|
|
84
|
+
const { lockToolHash } = await import("../dist/index.js");
|
|
85
|
+
const k = cc({ "good.example": "allow" }); const c = withPreflight(mcpClient(TOOLS), k);
|
|
86
|
+
await c.connect(T("https://good.example/mcp")); await c.callTool({ name: "search" }); await c.callTool({ name: "delete_repo" });
|
|
87
|
+
const per = k.calls.filter((x) => x.tool);
|
|
88
|
+
assert.deepEqual(per.map((x) => x.tool), ["delete_repo"]);
|
|
89
|
+
assert.equal(per[0].op.tool_schema_sha256, await lockToolHash(TOOLS[1]));
|
|
90
|
+
});
|
|
91
|
+
test("1.4.0: a refused tool receipt stops tools/call; toolReceipts none skips it", async () => {
|
|
92
|
+
const k = cc({ "good.example": "allow" }); const orig = k.guard;
|
|
93
|
+
k.guard = async (h, a, o) => o.operation ? { proceed: false, receipt: null, verification: null, why: ["the receipt is for another operation"] } : orig(h, a, o);
|
|
94
|
+
const cl = mcpClient(TOOLS); const c = withPreflight(cl, k);
|
|
95
|
+
await c.connect(T("https://good.example/mcp"));
|
|
96
|
+
await assert.rejects(() => c.callTool({ name: "delete_repo" }), (e) => e.stage === "tools/call" && /another operation/.test(e.why));
|
|
97
|
+
assert.ok(!cl.sent.includes("tools/call delete_repo"));
|
|
98
|
+
const k2 = cc({ "good.example": "allow" }); const c2 = withPreflight(mcpClient(TOOLS), k2, { toolReceipts: "none" });
|
|
99
|
+
await c2.connect(T("https://good.example/mcp")); await c2.callTool({ name: "delete_repo" });
|
|
100
|
+
assert.equal(k2.calls.filter((x) => x.tool).length, 0);
|
|
101
|
+
});
|