nulladrift 0.3.0 → 0.3.2
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 +62 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -323,6 +323,18 @@ function sanitizeUrl(raw) {
|
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
// ../core/src/risk/untrusted.ts
|
|
327
|
+
function objectsIn(value) {
|
|
328
|
+
if (!Array.isArray(value)) return [];
|
|
329
|
+
return value.filter((member) => typeof member === "object" && member !== null);
|
|
330
|
+
}
|
|
331
|
+
function objectOr(value) {
|
|
332
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
333
|
+
}
|
|
334
|
+
function stringOr(value) {
|
|
335
|
+
return typeof value === "string" ? value : void 0;
|
|
336
|
+
}
|
|
337
|
+
|
|
326
338
|
// ../core/src/risk/capability.ts
|
|
327
339
|
var CAPABILITY_SEVERITIES = ["critical", "high", "medium", "low"];
|
|
328
340
|
var CAPABILITY_KINDS = [
|
|
@@ -398,8 +410,9 @@ function argumentNames(inputSchema, depth = 0) {
|
|
|
398
410
|
return names;
|
|
399
411
|
}
|
|
400
412
|
function toolCapabilities(tool2) {
|
|
401
|
-
const
|
|
402
|
-
const
|
|
413
|
+
const subject = objectOr(tool2);
|
|
414
|
+
const name = normalize(stringOr(subject.name) ?? "");
|
|
415
|
+
const args = argumentNames(subject.inputSchema).map((argument) => [argument, normalize(argument)]);
|
|
403
416
|
const found = /* @__PURE__ */ new Map();
|
|
404
417
|
for (const rule of RULES) {
|
|
405
418
|
if (found.has(rule.kind)) continue;
|
|
@@ -416,11 +429,12 @@ function toolCapabilities(tool2) {
|
|
|
416
429
|
}
|
|
417
430
|
function surfaceCapabilities(tools) {
|
|
418
431
|
const byKind = /* @__PURE__ */ new Map();
|
|
419
|
-
for (const tool2 of tools) {
|
|
432
|
+
for (const tool2 of objectsIn(tools)) {
|
|
433
|
+
const label = stringOr(tool2.name) ?? "?";
|
|
420
434
|
for (const capability of toolCapabilities(tool2)) {
|
|
421
435
|
const existing = byKind.get(capability.kind);
|
|
422
|
-
if (existing) existing.tools.push(
|
|
423
|
-
else byKind.set(capability.kind, { ...capability, tools: [
|
|
436
|
+
if (existing) existing.tools.push(label);
|
|
437
|
+
else byKind.set(capability.kind, { ...capability, tools: [label] });
|
|
424
438
|
}
|
|
425
439
|
}
|
|
426
440
|
return [...byKind.values()].sort(
|
|
@@ -855,11 +869,11 @@ function capabilityViolations(lock, denied) {
|
|
|
855
869
|
if (!denied || denied.length === 0) return [];
|
|
856
870
|
const forbidden = new Set(denied);
|
|
857
871
|
const found = [];
|
|
858
|
-
for (const [server2, subject] of Object.entries(lock
|
|
859
|
-
for (const tool2 of subject.tools
|
|
872
|
+
for (const [server2, subject] of Object.entries(lock?.subjects ?? {})) {
|
|
873
|
+
for (const tool2 of objectsIn(objectOr(subject).tools)) {
|
|
860
874
|
for (const capability of toolCapabilities(tool2)) {
|
|
861
875
|
if (!forbidden.has(capability.kind)) continue;
|
|
862
|
-
found.push({ server: server2, tool: tool2.name ?? "?", kind: capability.kind, severity: capability.severity, evidence: capability.evidence });
|
|
876
|
+
found.push({ server: server2, tool: stringOr(tool2.name) ?? "?", kind: capability.kind, severity: capability.severity, evidence: capability.evidence });
|
|
863
877
|
}
|
|
864
878
|
}
|
|
865
879
|
}
|
|
@@ -894,29 +908,29 @@ function surfaceText(subject) {
|
|
|
894
908
|
const push = (field, text) => {
|
|
895
909
|
if (typeof text === "string" && text.length > 0) out.push({ field, text });
|
|
896
910
|
};
|
|
897
|
-
push("instructions", subject
|
|
898
|
-
for (const tool2 of subject
|
|
899
|
-
const where = tool2.name ?? "?";
|
|
911
|
+
push("instructions", subject?.instructions);
|
|
912
|
+
for (const tool2 of objectsIn(subject?.tools)) {
|
|
913
|
+
const where = stringOr(tool2.name) ?? "?";
|
|
900
914
|
push(`${where}.title`, tool2.title);
|
|
901
915
|
push(`${where}.description`, tool2.description);
|
|
902
916
|
schemaText(tool2.inputSchema, `${where}.inputSchema`, out);
|
|
903
917
|
schemaText(tool2.outputSchema, `${where}.outputSchema`, out);
|
|
904
918
|
}
|
|
905
|
-
for (const prompt2 of subject
|
|
906
|
-
const where = prompt2.name ?? "?";
|
|
919
|
+
for (const prompt2 of objectsIn(subject?.prompts)) {
|
|
920
|
+
const where = stringOr(prompt2.name) ?? "?";
|
|
907
921
|
push(`prompt:${where}.title`, prompt2.title);
|
|
908
922
|
push(`prompt:${where}.description`, prompt2.description);
|
|
909
|
-
for (const argument of prompt2.arguments
|
|
910
|
-
push(`prompt:${where}.${argument.name ?? "?"}`, argument.description);
|
|
923
|
+
for (const argument of objectsIn(prompt2.arguments)) {
|
|
924
|
+
push(`prompt:${where}.${stringOr(argument.name) ?? "?"}`, argument.description);
|
|
911
925
|
}
|
|
912
926
|
}
|
|
913
|
-
for (const resource2 of subject
|
|
914
|
-
const where = resource2.name ?? resource2.uri ?? "?";
|
|
927
|
+
for (const resource2 of objectsIn(subject?.resources)) {
|
|
928
|
+
const where = stringOr(resource2.name) ?? stringOr(resource2.uri) ?? "?";
|
|
915
929
|
push(`resource:${where}.title`, resource2.title);
|
|
916
930
|
push(`resource:${where}.description`, resource2.description);
|
|
917
931
|
}
|
|
918
|
-
for (const template of subject
|
|
919
|
-
const where = template.name ?? template.uriTemplate ?? "?";
|
|
932
|
+
for (const template of objectsIn(subject?.resourceTemplates)) {
|
|
933
|
+
const where = stringOr(template.name) ?? stringOr(template.uriTemplate) ?? "?";
|
|
920
934
|
push(`template:${where}.title`, template.title);
|
|
921
935
|
push(`template:${where}.description`, template.description);
|
|
922
936
|
}
|
|
@@ -1431,7 +1445,7 @@ import { dirname, join as join2 } from "path";
|
|
|
1431
1445
|
import { ClientCredentialsProvider, UnauthorizedError } from "@modelcontextprotocol/client";
|
|
1432
1446
|
|
|
1433
1447
|
// src/lib/version.ts
|
|
1434
|
-
var VERSION = "0.3.
|
|
1448
|
+
var VERSION = "0.3.2";
|
|
1435
1449
|
var USER_AGENT = `nulladrift/${VERSION}`;
|
|
1436
1450
|
|
|
1437
1451
|
// src/mcp/oauth.ts
|
|
@@ -1708,11 +1722,38 @@ async function connect(server2, timeoutMs = DEFAULT_TIMEOUT_MS, options = {}) {
|
|
|
1708
1722
|
|
|
1709
1723
|
// src/mcp/capture.ts
|
|
1710
1724
|
var FRESH = { cacheMode: "bypass" };
|
|
1725
|
+
function describeValidationIssues(message) {
|
|
1726
|
+
const start = message.indexOf("[");
|
|
1727
|
+
if (start < 0) return void 0;
|
|
1728
|
+
let issues;
|
|
1729
|
+
try {
|
|
1730
|
+
issues = JSON.parse(message.slice(start));
|
|
1731
|
+
} catch {
|
|
1732
|
+
return void 0;
|
|
1733
|
+
}
|
|
1734
|
+
if (!Array.isArray(issues) || issues.length === 0) return void 0;
|
|
1735
|
+
const where = (issue) => (issue.path ?? []).map((part) => typeof part === "number" ? `[${part}]` : `.${String(part)}`).join("").replace(/^\./, "");
|
|
1736
|
+
const byMessage = /* @__PURE__ */ new Map();
|
|
1737
|
+
for (const issue of issues) {
|
|
1738
|
+
const text = issue.message ?? "did not validate";
|
|
1739
|
+
byMessage.set(text, [...byMessage.get(text) ?? [], where(issue)]);
|
|
1740
|
+
}
|
|
1741
|
+
const lines = [...byMessage].slice(0, 3).map(([text, paths]) => {
|
|
1742
|
+
const rest = paths.length > 1 ? ` (and ${paths.length - 1} more like it)` : "";
|
|
1743
|
+
return `${paths[0]}: ${text}${rest}`;
|
|
1744
|
+
});
|
|
1745
|
+
const more = byMessage.size > 3 ? ` +${byMessage.size - 3} other problem(s)` : "";
|
|
1746
|
+
return `this server's reply does not match the MCP specification, so nothing was pinned for it. ${lines.join("; ")}${more}. This is a defect in the server, not in your project; the usual cause is an old release predating a tightening of the schema.`;
|
|
1747
|
+
}
|
|
1711
1748
|
function describeListFailure(error) {
|
|
1712
1749
|
const message = error?.message ?? String(error);
|
|
1713
1750
|
if (error instanceof RangeError || /maximum call stack|stack size exceeded|too much recursion/i.test(message)) {
|
|
1714
1751
|
return "the declared surface is nested too deeply to parse. Nothing was pinned. A legitimate schema is a few levels deep; this one is deep enough to exhaust the parser, which is a property of the declaration and not of your project.";
|
|
1715
1752
|
}
|
|
1753
|
+
if (/invalid result for|invalid literal|invalid_value|invalid_type/i.test(message)) {
|
|
1754
|
+
const described = describeValidationIssues(message);
|
|
1755
|
+
if (described) return described;
|
|
1756
|
+
}
|
|
1716
1757
|
return message;
|
|
1717
1758
|
}
|
|
1718
1759
|
async function listOrEmpty(label, serverName, fetchList) {
|
|
@@ -3200,7 +3241,7 @@ function describeSurface(subject, previous) {
|
|
|
3200
3241
|
if (typeof subject !== "object" || subject === null) return [];
|
|
3201
3242
|
const entry = subject;
|
|
3202
3243
|
const lines = [];
|
|
3203
|
-
const capabilities = surfaceCapabilities(entry.tools
|
|
3244
|
+
const capabilities = surfaceCapabilities(entry.tools);
|
|
3204
3245
|
if (capabilities.length > 0) {
|
|
3205
3246
|
const worst = capabilities.some((c) => c.severity === "critical" || c.severity === "high");
|
|
3206
3247
|
const text = ` after accepting, this server can: ${capabilities.map((c) => c.kind).join(", ")}`;
|