skillscout 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +128 -2
- package/dist/cli.js +181 -0
- package/dist/fetchSkill.js +111 -0
- package/dist/index.js +287 -0
- package/dist/install.js +269 -0
- package/dist/mcpConfig.js +79 -0
- package/dist/paths.js +19 -0
- package/dist/profile.js +193 -0
- package/dist/ref.js +59 -0
- package/dist/relevance.js +121 -0
- package/dist/sanitize.js +32 -0
- package/dist/scan/llm.js +147 -0
- package/dist/scan/rules.js +243 -0
- package/dist/search.js +179 -0
- package/dist/sources/github.js +111 -0
- package/dist/sources/http.js +47 -0
- package/dist/sources/mcpRegistry.js +26 -0
- package/dist/sources/osv.js +55 -0
- package/dist/sources/packages.js +180 -0
- package/dist/sources/remoteProbe.js +59 -0
- package/dist/sources/safeFetch.js +52 -0
- package/dist/sources/skillssh.js +50 -0
- package/dist/types.js +8 -0
- package/dist/updates.js +152 -0
- package/dist/verdict.js +147 -0
- package/dist/vetCache.js +22 -0
- package/dist/vetMcp.js +297 -0
- package/dist/vetPlugin.js +221 -0
- package/dist/vetSkill.js +75 -0
- package/package.json +54 -4
- package/skills/skillscout/SKILL.md +42 -0
package/dist/verdict.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { SEVERITY_ORDER } from "./types.js";
|
|
2
|
+
const RISK_RANK = { safe: 0, low: 1, unknown: 2, medium: 2, high: 3, critical: 4 };
|
|
3
|
+
export function severityToRisk(s) {
|
|
4
|
+
if (!s || s === "info")
|
|
5
|
+
return "safe";
|
|
6
|
+
return s;
|
|
7
|
+
}
|
|
8
|
+
export function normalizePartnerRisk(a) {
|
|
9
|
+
const r = (a.risk ?? "").toLowerCase();
|
|
10
|
+
if (["safe", "low", "medium", "high", "critical"].includes(r))
|
|
11
|
+
return r;
|
|
12
|
+
const s = a.status.toLowerCase();
|
|
13
|
+
if (s === "pass")
|
|
14
|
+
return "safe";
|
|
15
|
+
if (s === "warn")
|
|
16
|
+
return "medium";
|
|
17
|
+
if (s === "fail")
|
|
18
|
+
return "high";
|
|
19
|
+
return "unknown";
|
|
20
|
+
}
|
|
21
|
+
/** Signals a model review never overrules. */
|
|
22
|
+
const NEVER_DOWNGRADE = new Set(["known-malicious-package", "hidden-unicode", "bundled-binary"]);
|
|
23
|
+
const DOC_FILE = /\.(md|mdx|markdown|txt)$/i;
|
|
24
|
+
/** Why a static block may not be downgraded, or undefined if it may. */
|
|
25
|
+
export function downgradeBlocker(input) {
|
|
26
|
+
const llm = input.llm;
|
|
27
|
+
if (!input.reviewMayDowngradeStatic)
|
|
28
|
+
return "not packaged code";
|
|
29
|
+
if (llm.status !== "ok")
|
|
30
|
+
return "no model review";
|
|
31
|
+
if (llm.risk !== "safe" && llm.risk !== "low")
|
|
32
|
+
return `model review rated it ${llm.risk}`;
|
|
33
|
+
if (llm.matchesDescription === false)
|
|
34
|
+
return "behavior does not match the description";
|
|
35
|
+
if ((llm.findings ?? []).some((f) => f.severity === "high" || f.severity === "critical"))
|
|
36
|
+
return "model review raised its own high finding";
|
|
37
|
+
const blocking = input.staticFindings.filter((f) => f.severity === "critical" || f.severity === "high");
|
|
38
|
+
const seen = new Set(llm.reviewedFiles ?? []);
|
|
39
|
+
for (const f of blocking) {
|
|
40
|
+
if (NEVER_DOWNGRADE.has(f.rule))
|
|
41
|
+
return `${f.rule} is never overruled`;
|
|
42
|
+
if (DOC_FILE.test(f.file))
|
|
43
|
+
return `finding in ${f.file}, which is documentation or a tool description`;
|
|
44
|
+
if (!seen.has(f.file))
|
|
45
|
+
return `${f.file} was not part of the model review`;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Policy:
|
|
51
|
+
* - any critical signal, or a high static finding -> block
|
|
52
|
+
* - high from the reviewer model or partners -> review (models/partners can be wrong; a human decides)
|
|
53
|
+
* - medium from anywhere -> review
|
|
54
|
+
* - no semantic review AND executable code -> review (static rules alone are not enough for code)
|
|
55
|
+
* - otherwise -> allow
|
|
56
|
+
* "allow" never means "proven safe"; it means nothing we checked raised a flag.
|
|
57
|
+
*/
|
|
58
|
+
export function decide(input) {
|
|
59
|
+
const reasons = [];
|
|
60
|
+
let risk = "safe";
|
|
61
|
+
const bump = (r) => {
|
|
62
|
+
if (RISK_RANK[r] > RISK_RANK[risk])
|
|
63
|
+
risk = r;
|
|
64
|
+
};
|
|
65
|
+
const staticMax = input.staticFindings.reduce((m, f) => (SEVERITY_ORDER[f.severity] > SEVERITY_ORDER[m] ? f.severity : m), "info");
|
|
66
|
+
bump(severityToRisk(staticMax));
|
|
67
|
+
let block = false;
|
|
68
|
+
let review = false;
|
|
69
|
+
const crit = input.staticFindings.filter((f) => f.severity === "critical");
|
|
70
|
+
const high = input.staticFindings.filter((f) => f.severity === "high");
|
|
71
|
+
if (crit.length) {
|
|
72
|
+
block = true;
|
|
73
|
+
reasons.push(`Static scan: ${crit.length} critical finding(s): ${uniq(crit.map((f) => f.rule)).join(", ")}.`);
|
|
74
|
+
}
|
|
75
|
+
if (high.length) {
|
|
76
|
+
block = true;
|
|
77
|
+
reasons.push(`Static scan: ${high.length} high finding(s): ${uniq(high.map((f) => f.rule)).join(", ")}.`);
|
|
78
|
+
}
|
|
79
|
+
const med = input.staticFindings.filter((f) => f.severity === "medium");
|
|
80
|
+
if (med.length) {
|
|
81
|
+
review = true;
|
|
82
|
+
reasons.push(`Static scan: ${med.length} medium finding(s): ${uniq(med.map((f) => f.rule)).join(", ")}.`);
|
|
83
|
+
}
|
|
84
|
+
const llm = input.llm;
|
|
85
|
+
if (llm.status === "ok" && llm.risk) {
|
|
86
|
+
bump(llm.risk);
|
|
87
|
+
if (llm.risk === "critical") {
|
|
88
|
+
block = true;
|
|
89
|
+
reasons.push("Semantic review rated it critical.");
|
|
90
|
+
}
|
|
91
|
+
else if (llm.risk === "high" || llm.risk === "medium") {
|
|
92
|
+
review = true;
|
|
93
|
+
reasons.push(`Semantic review rated it ${llm.risk}.`);
|
|
94
|
+
}
|
|
95
|
+
if (llm.matchesDescription === false) {
|
|
96
|
+
review = true;
|
|
97
|
+
reasons.push("Semantic review: behavior does not match the stated description.");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (llm.status === "refused") {
|
|
101
|
+
bump("high");
|
|
102
|
+
review = true;
|
|
103
|
+
reasons.push("Semantic reviewer refused to process the content.");
|
|
104
|
+
}
|
|
105
|
+
else if (input.hasCode) {
|
|
106
|
+
bump("unknown");
|
|
107
|
+
review = true;
|
|
108
|
+
reasons.push(`No semantic review (${llm.status}: ${llm.reason ?? "n/a"}) and it contains ${input.codeNote ?? "executable code"}.`);
|
|
109
|
+
}
|
|
110
|
+
for (const a of input.partnerAudits) {
|
|
111
|
+
const r = normalizePartnerRisk(a);
|
|
112
|
+
if (r === "critical") {
|
|
113
|
+
bump(r);
|
|
114
|
+
block = true;
|
|
115
|
+
reasons.push(`${a.provider} audit: critical.`);
|
|
116
|
+
}
|
|
117
|
+
else if (r === "high" || r === "medium") {
|
|
118
|
+
bump(r);
|
|
119
|
+
review = true;
|
|
120
|
+
reasons.push(`${a.provider} audit: ${r}.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const r of input.reviewReasons ?? []) {
|
|
124
|
+
review = true;
|
|
125
|
+
reasons.push(r);
|
|
126
|
+
}
|
|
127
|
+
if (block) {
|
|
128
|
+
const blockedByStaticOnly = !(llm.status === "ok" && llm.risk === "critical") &&
|
|
129
|
+
!input.partnerAudits.some((a) => normalizePartnerRisk(a) === "critical") &&
|
|
130
|
+
input.staticFindings.some((f) => f.severity === "critical" || f.severity === "high");
|
|
131
|
+
if (blockedByStaticOnly && downgradeBlocker(input) === undefined) {
|
|
132
|
+
block = false;
|
|
133
|
+
review = true;
|
|
134
|
+
risk = "medium";
|
|
135
|
+
reasons.push(`Lowered from block to review: the static rules matched in package code, but the separate model review read those files and rated the package ${llm.risk}. ` +
|
|
136
|
+
"This is common for security tools, whose detection patterns contain the strings they look for. Check the static findings before installing.");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const verdict = block ? "block" : review ? "review" : "allow";
|
|
140
|
+
if (verdict === "allow")
|
|
141
|
+
reasons.push("No checks raised a flag. This is not proof of safety.");
|
|
142
|
+
return { verdict, risk, reasons };
|
|
143
|
+
}
|
|
144
|
+
function uniq(xs) {
|
|
145
|
+
return [...new Set(xs)];
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=verdict.js.map
|
package/dist/vetCache.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { cacheDir } from "./paths.js";
|
|
5
|
+
function keyPath(kind, id, pin) {
|
|
6
|
+
const h = createHash("sha256").update(`${kind}\0${id}\0${pin}`).digest("hex").slice(0, 32);
|
|
7
|
+
return join(cacheDir(), "vet", `${h}.json`);
|
|
8
|
+
}
|
|
9
|
+
export async function loadVet(kind, id, pin) {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(await readFile(keyPath(kind, id, pin), "utf8"));
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export async function saveVet(v) {
|
|
18
|
+
const p = keyPath(v.kind, v.id, v.sha);
|
|
19
|
+
await mkdir(join(cacheDir(), "vet"), { recursive: true });
|
|
20
|
+
await writeFile(p, JSON.stringify(v, null, 2));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=vetCache.js.map
|
package/dist/vetMcp.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { sanitize } from "./sanitize.js";
|
|
3
|
+
import { llmReview } from "./scan/llm.js";
|
|
4
|
+
import { capFinding, scanFiles } from "./scan/rules.js";
|
|
5
|
+
import { repoProvenance } from "./sources/github.js";
|
|
6
|
+
import { getMcpServer } from "./sources/mcpRegistry.js";
|
|
7
|
+
import { npmTarballFiles, npmVersion, npmWeeklyDownloads, pypiFiles, pypiVersion, resolveNpmDeps } from "./sources/packages.js";
|
|
8
|
+
import { osvFindings } from "./sources/osv.js";
|
|
9
|
+
import { probeRemote } from "./sources/remoteProbe.js";
|
|
10
|
+
import { decide } from "./verdict.js";
|
|
11
|
+
import { saveVet } from "./vetCache.js";
|
|
12
|
+
// Lifecycle scripts that run when a *published* package is installed (prepare does not).
|
|
13
|
+
const INSTALL_SCRIPTS = ["preinstall", "install", "postinstall"];
|
|
14
|
+
const REVIEW_EXT = /\.(m?[jt]s|cjs|py|json|md|toml|cfg)$/i;
|
|
15
|
+
const SKIP_DIRS = /(^|\/)(test|tests|__tests__|examples?|docs?|\.github)\//i;
|
|
16
|
+
export async function vetMcp(name, opts = {}) {
|
|
17
|
+
const entry = await getMcpServer(name, opts.version);
|
|
18
|
+
const findings = [];
|
|
19
|
+
const reviewReasons = [];
|
|
20
|
+
const notes = [];
|
|
21
|
+
let files = [];
|
|
22
|
+
let skipped = [];
|
|
23
|
+
let hasCode = false;
|
|
24
|
+
let pin = entry.version;
|
|
25
|
+
let contentHash = "";
|
|
26
|
+
let plan;
|
|
27
|
+
if (entry.status && entry.status !== "active") {
|
|
28
|
+
findings.push({ rule: "registry-status", severity: "medium", file: "registry", message: `Registry status is "${sanitize(entry.status, 20)}"` });
|
|
29
|
+
}
|
|
30
|
+
notes.push(...namespaceNotes(entry));
|
|
31
|
+
const pkg = pickPackage(entry.packages ?? []);
|
|
32
|
+
const remote = entry.remotes?.[0];
|
|
33
|
+
const useRemote = (opts.prefer === "remote" && remote) || (!pkg && remote);
|
|
34
|
+
if (!useRemote && pkg) {
|
|
35
|
+
hasCode = true;
|
|
36
|
+
if (pkg.registryType === "npm") {
|
|
37
|
+
const { info, publishedAt } = await npmVersion(pkg.identifier, pkg.version);
|
|
38
|
+
pin = info.version;
|
|
39
|
+
contentHash = info.dist.integrity ?? "";
|
|
40
|
+
const scripts = Object.entries(info.scripts ?? {}).filter(([k]) => INSTALL_SCRIPTS.includes(k));
|
|
41
|
+
for (const [k, v] of scripts) {
|
|
42
|
+
findings.push({ rule: "install-script", severity: "high", file: "package.json", message: `Runs an npm "${k}" script on install`, excerpt: sanitize(v, 120) });
|
|
43
|
+
}
|
|
44
|
+
if (info.deprecated)
|
|
45
|
+
findings.push({ rule: "deprecated", severity: "medium", file: "package.json", message: `Package version is deprecated: ${sanitize(info.deprecated, 120)}` });
|
|
46
|
+
if (publishedAt && Date.now() - Date.parse(publishedAt) < 7 * 86_400_000)
|
|
47
|
+
notes.push(`Version ${info.version} was published less than 7 days ago.`);
|
|
48
|
+
const dl = await npmWeeklyDownloads(pkg.identifier);
|
|
49
|
+
if (dl !== undefined)
|
|
50
|
+
notes.push(`${dl} npm downloads last week.`);
|
|
51
|
+
const repoUrl = typeof info.repository === "string" ? info.repository : info.repository?.url;
|
|
52
|
+
if (entry.repository?.url && repoUrl && normalizeRepo(repoUrl) !== normalizeRepo(entry.repository.url)) {
|
|
53
|
+
findings.push({ rule: "repo-mismatch", severity: "medium", file: "package.json", message: "npm package repository differs from the registry entry's repository" });
|
|
54
|
+
}
|
|
55
|
+
// Direct dependencies: resolve, flag install scripts, and check package + deps against OSV.
|
|
56
|
+
const deps = await resolveNpmDeps(info.dependencies ?? {});
|
|
57
|
+
for (const d of deps.filter((d) => d.hasInstallScript)) {
|
|
58
|
+
findings.push({ rule: "dependency-install-script", severity: "medium", file: "package.json", message: `Dependency ${d.name}@${d.version} runs install scripts` });
|
|
59
|
+
}
|
|
60
|
+
const unresolved = deps.filter((d) => !d.version).length;
|
|
61
|
+
if (deps.length)
|
|
62
|
+
notes.push(`${deps.length} direct dependencies checked for install scripts and known vulnerabilities${unresolved ? ` (${unresolved} could not be resolved)` : ""}; transitive dependencies are not checked.`);
|
|
63
|
+
const osv = await osvFindings([
|
|
64
|
+
{ ecosystem: "npm", name: info.name, version: info.version, via: "package.json" },
|
|
65
|
+
...deps.filter((d) => d.version).map((d) => ({ ecosystem: "npm", name: d.name, version: d.version, via: `dependency ${d.name}` })),
|
|
66
|
+
]);
|
|
67
|
+
findings.push(...osv.findings);
|
|
68
|
+
if (osv.error)
|
|
69
|
+
notes.push(osv.error);
|
|
70
|
+
const tar = await npmTarballFiles(info.dist.tarball);
|
|
71
|
+
files = tar.files.filter((f) => !f.path.includes("node_modules/"));
|
|
72
|
+
skipped = tar.skipped;
|
|
73
|
+
const scanned = scanFiles(files)
|
|
74
|
+
.filter((f) => !(f.rule === "package-install-script" && f.file === "package.json")) // reported above, precisely
|
|
75
|
+
.map(adjustForPackage);
|
|
76
|
+
findings.push(...scanned);
|
|
77
|
+
plan = npmPlan(entry, pkg, info.version);
|
|
78
|
+
}
|
|
79
|
+
else if (pkg.registryType === "pypi") {
|
|
80
|
+
const info = await pypiVersion(pkg.identifier, pkg.version);
|
|
81
|
+
pin = info.version;
|
|
82
|
+
contentHash = `pypi:${pkg.identifier}==${info.version}`;
|
|
83
|
+
if (info.yanked)
|
|
84
|
+
findings.push({ rule: "yanked", severity: "medium", file: "pypi", message: "This PyPI release was yanked" });
|
|
85
|
+
if (info.publishedAt && Date.now() - Date.parse(info.publishedAt) < 7 * 86_400_000)
|
|
86
|
+
notes.push(`Version ${info.version} was published less than 7 days ago.`);
|
|
87
|
+
const osv = await osvFindings([{ ecosystem: "PyPI", name: pkg.identifier, version: info.version, via: "pypi" }]);
|
|
88
|
+
findings.push(...osv.findings);
|
|
89
|
+
if (osv.error)
|
|
90
|
+
notes.push(osv.error);
|
|
91
|
+
if (info.dist) {
|
|
92
|
+
try {
|
|
93
|
+
const unpacked = await pypiFiles(info.dist);
|
|
94
|
+
files = unpacked.files;
|
|
95
|
+
skipped = unpacked.skipped;
|
|
96
|
+
findings.push(...scanFiles(files).map(adjustForPackage));
|
|
97
|
+
notes.push(`Scanned the ${info.dist.kind}; Python dependencies are not checked.`);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
reviewReasons.push(`Could not scan the PyPI distribution: ${sanitize(e.message, 120)}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
reviewReasons.push("No PyPI distribution file to scan.");
|
|
105
|
+
}
|
|
106
|
+
plan = pypiPlan(entry, pkg, info.version);
|
|
107
|
+
}
|
|
108
|
+
else if (pkg.registryType === "oci") {
|
|
109
|
+
pin = pkg.version ?? entry.version;
|
|
110
|
+
contentHash = `oci:${pkg.identifier}:${pin}`;
|
|
111
|
+
reviewReasons.push("Container image contents are not scanned. Prefer images pinned by digest from a publisher you trust.");
|
|
112
|
+
plan = ociPlan(entry, pkg, pin);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
reviewReasons.push(`Package type "${sanitize(pkg.registryType, 20)}" is not supported for scanning.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (remote) {
|
|
119
|
+
const res = await remoteVet(entry, remote, opts.probeRemote !== false);
|
|
120
|
+
findings.push(...res.findings);
|
|
121
|
+
reviewReasons.push(...res.reviewReasons);
|
|
122
|
+
files = res.files;
|
|
123
|
+
contentHash = res.contentHash;
|
|
124
|
+
plan = res.plan;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw new Error(`Registry entry ${name} has neither packages nor remotes`);
|
|
128
|
+
}
|
|
129
|
+
const provenance = await repoProvenanceFor(entry);
|
|
130
|
+
provenance.notes.push(...notes);
|
|
131
|
+
const reviewFiles = files
|
|
132
|
+
.filter((f) => REVIEW_EXT.test(f.path) && !SKIP_DIRS.test(f.path) && !/\.min\.js$|\.map$/.test(f.path))
|
|
133
|
+
.sort((a, b) => priority(a.path) - priority(b.path));
|
|
134
|
+
const llm = files.length
|
|
135
|
+
? await llmReview({ kind: "mcp", name: entry.name, description: entry.description ?? "", files: reviewFiles })
|
|
136
|
+
: { status: "skipped", reason: "No source or tool descriptions available to review." };
|
|
137
|
+
const { verdict, risk, reasons } = decide({
|
|
138
|
+
staticFindings: findings,
|
|
139
|
+
llm,
|
|
140
|
+
partnerAudits: [],
|
|
141
|
+
hasCode,
|
|
142
|
+
reviewReasons,
|
|
143
|
+
// Package source only. Remote servers have tool descriptions (markdown), which never downgrade anyway.
|
|
144
|
+
reviewMayDowngradeStatic: true,
|
|
145
|
+
});
|
|
146
|
+
const result = {
|
|
147
|
+
kind: "mcp",
|
|
148
|
+
id: entry.name,
|
|
149
|
+
source: pkg && !useRemote ? `${pkg.registryType}:${pkg.identifier}` : `remote:${remote?.url ?? ""}`,
|
|
150
|
+
path: "",
|
|
151
|
+
sha: pin,
|
|
152
|
+
contentHash: contentHash || "sha256:" + createHash("sha256").update(JSON.stringify(entry)).digest("hex"),
|
|
153
|
+
name: sanitize(entry.name, 120),
|
|
154
|
+
description: sanitize(entry.description, 600),
|
|
155
|
+
verdict,
|
|
156
|
+
risk,
|
|
157
|
+
reasons,
|
|
158
|
+
staticFindings: [...findings, ...(llm.findings ?? [])],
|
|
159
|
+
llm: { ...llm, findings: undefined },
|
|
160
|
+
partnerAudits: [],
|
|
161
|
+
provenance,
|
|
162
|
+
files: files.slice(0, 200).map((f) => ({ path: f.path, size: f.content.length, executable: f.executable })),
|
|
163
|
+
skipped,
|
|
164
|
+
registryVersion: entry.version,
|
|
165
|
+
mcpInstall: plan,
|
|
166
|
+
vettedAt: new Date().toISOString(),
|
|
167
|
+
};
|
|
168
|
+
await saveVet(result);
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
async function remoteVet(entry, remote, probe) {
|
|
172
|
+
const findings = [];
|
|
173
|
+
const reviewReasons = ["Remote server: its behavior and tool descriptions can change after vetting without a new version."];
|
|
174
|
+
let files = [];
|
|
175
|
+
let contentHash = "";
|
|
176
|
+
if (!remote.url.startsWith("https://")) {
|
|
177
|
+
findings.push({ rule: "insecure-transport", severity: "high", file: "registry", message: "Remote server does not use https" });
|
|
178
|
+
}
|
|
179
|
+
if (probe) {
|
|
180
|
+
const res = await probeRemote(remote.url, remote.type);
|
|
181
|
+
if (res.status === "ok") {
|
|
182
|
+
// Each tool description is instruction text the agent will read: scan it like markdown.
|
|
183
|
+
files = res.tools.map((t) => ({
|
|
184
|
+
path: `tools/${t.name.replace(/[^\w.-]/g, "_")}.md`,
|
|
185
|
+
content: Buffer.from(`# ${t.name}\n\n${t.description}\n\n${JSON.stringify(t.inputSchema ?? {}, null, 1)}`),
|
|
186
|
+
executable: false,
|
|
187
|
+
}));
|
|
188
|
+
findings.push(...scanFiles(files));
|
|
189
|
+
contentHash = "sha256:" + createHash("sha256").update(JSON.stringify(res.tools)).digest("hex");
|
|
190
|
+
if (res.tools.length > 60)
|
|
191
|
+
findings.push({ rule: "many-tools", severity: "low", file: "tools", message: `Exposes ${res.tools.length} tools (context cost)` });
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
reviewReasons.push(`Tool descriptions not inspected: ${res.reason}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
reviewReasons.push("Tool descriptions not inspected (probe disabled).");
|
|
199
|
+
}
|
|
200
|
+
const headers = (remote.headers ?? []).map((h) => ({ name: sanitize(h.name, 80), secret: !!h.isSecret, description: sanitize(h.description, 200) }));
|
|
201
|
+
const envName = (h) => `${serverName(entry).toUpperCase().replace(/[^A-Z0-9]/g, "_")}_${h.toUpperCase().replace(/[^A-Z0-9]/g, "_")}`;
|
|
202
|
+
const plan = {
|
|
203
|
+
serverName: serverName(entry),
|
|
204
|
+
config: {
|
|
205
|
+
type: remote.type === "sse" ? "sse" : "http",
|
|
206
|
+
url: remote.url,
|
|
207
|
+
...(headers.length ? { headers: Object.fromEntries(headers.map((h) => [h.name, `\${${envName(h.name)}}`])) } : {}),
|
|
208
|
+
},
|
|
209
|
+
requiredEnv: headers.map((h) => ({ name: envName(h.name), secret: h.secret, description: `Value for header ${h.name}. ${h.description}` })),
|
|
210
|
+
};
|
|
211
|
+
return { findings, reviewReasons, files, contentHash, plan };
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* In an MCP *package*, markdown is human documentation that the agent never
|
|
215
|
+
* loads (unlike a skill, whose markdown is the agent's instructions), so doc
|
|
216
|
+
* findings are capped. What reaches the agent is the tool descriptions in code,
|
|
217
|
+
* which keep full severity.
|
|
218
|
+
*/
|
|
219
|
+
export function adjustForPackage(f) {
|
|
220
|
+
if (/\.(md|mdx|markdown|txt)$/i.test(f.file) || /^(tests?|__tests__|docs?|examples?)\//.test(f.file))
|
|
221
|
+
return capFinding(f, "package documentation or tests");
|
|
222
|
+
// API-wrapper servers routinely read a token and call an API; keep it visible, not blocking.
|
|
223
|
+
if (f.rule === "possible-exfiltration") {
|
|
224
|
+
return { ...f, severity: "medium", message: `${f.message} (common for API servers; check the destination)` };
|
|
225
|
+
}
|
|
226
|
+
return f;
|
|
227
|
+
}
|
|
228
|
+
function pickPackage(pkgs) {
|
|
229
|
+
return pkgs.find((p) => p.registryType === "npm") ?? pkgs.find((p) => p.registryType === "pypi") ?? pkgs.find((p) => p.registryType === "oci") ?? pkgs[0];
|
|
230
|
+
}
|
|
231
|
+
function envPlan(pkg) {
|
|
232
|
+
const req = (pkg.environmentVariables ?? []).map((e) => ({ name: sanitize(e.name, 80), secret: !!e.isSecret, description: sanitize(e.description, 200) }));
|
|
233
|
+
const env = Object.fromEntries(req.filter((e) => /^[A-Z_][A-Z0-9_]*$/i.test(e.name)).map((e) => [e.name, `\${${e.name}}`]));
|
|
234
|
+
return { req, env };
|
|
235
|
+
}
|
|
236
|
+
function npmPlan(entry, pkg, version) {
|
|
237
|
+
const { req, env } = envPlan(pkg);
|
|
238
|
+
return {
|
|
239
|
+
serverName: serverName(entry),
|
|
240
|
+
config: { command: "npx", args: ["-y", `${pkg.identifier}@${version}`], ...(Object.keys(env).length ? { env } : {}) },
|
|
241
|
+
requiredEnv: req,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function pypiPlan(entry, pkg, version) {
|
|
245
|
+
const { req, env } = envPlan(pkg);
|
|
246
|
+
return {
|
|
247
|
+
serverName: serverName(entry),
|
|
248
|
+
config: { command: "uvx", args: [`${pkg.identifier}==${version}`], ...(Object.keys(env).length ? { env } : {}) },
|
|
249
|
+
requiredEnv: req,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function ociPlan(entry, pkg, tag) {
|
|
253
|
+
const { req, env } = envPlan(pkg);
|
|
254
|
+
const image = pkg.identifier.includes(":") || pkg.identifier.includes("@") ? pkg.identifier : `${pkg.identifier}:${tag}`;
|
|
255
|
+
return {
|
|
256
|
+
serverName: serverName(entry),
|
|
257
|
+
config: {
|
|
258
|
+
command: "docker",
|
|
259
|
+
args: ["run", "-i", "--rm", ...Object.keys(env).flatMap((k) => ["-e", k]), image],
|
|
260
|
+
...(Object.keys(env).length ? { env } : {}),
|
|
261
|
+
},
|
|
262
|
+
requiredEnv: req,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
export function serverName(entry) {
|
|
266
|
+
const last = entry.name.split("/").pop() ?? entry.name;
|
|
267
|
+
return last.replace(/[^A-Za-z0-9_-]/g, "-").slice(0, 60) || "mcp-server";
|
|
268
|
+
}
|
|
269
|
+
function namespaceNotes(entry) {
|
|
270
|
+
const [ns] = entry.name.split("/");
|
|
271
|
+
if (!ns)
|
|
272
|
+
return [];
|
|
273
|
+
if (/^io\.github\./.test(ns))
|
|
274
|
+
return [`Registry namespace ${sanitize(ns, 80)} is tied to a GitHub account.`];
|
|
275
|
+
return [`Registry namespace ${sanitize(ns, 80)} is tied to a domain (reverse-DNS).`];
|
|
276
|
+
}
|
|
277
|
+
async function repoProvenanceFor(entry) {
|
|
278
|
+
const m = entry.repository?.url?.match(/github\.com\/([^/]+)\/([^/#?]+?)(\.git)?(?:[/#?]|$)/);
|
|
279
|
+
if (!m)
|
|
280
|
+
return { notes: entry.repository?.url ? [] : ["No source repository listed."] };
|
|
281
|
+
return repoProvenance(m[1], m[2]);
|
|
282
|
+
}
|
|
283
|
+
function normalizeRepo(u) {
|
|
284
|
+
return u.toLowerCase().replace(/^git\+/, "").replace(/^git:\/\//, "https://").replace(/\.git$/, "").replace(/\/$/, "").replace(/^ssh:\/\/git@/, "https://");
|
|
285
|
+
}
|
|
286
|
+
function priority(p) {
|
|
287
|
+
if (p === "package.json")
|
|
288
|
+
return 0;
|
|
289
|
+
if (/readme/i.test(p))
|
|
290
|
+
return 1;
|
|
291
|
+
if (/(^|\/)(src|lib|dist|build)\/.*(tool|index|server)/i.test(p))
|
|
292
|
+
return 2;
|
|
293
|
+
if (/\.(m?[jt]s|cjs|py)$/.test(p))
|
|
294
|
+
return 3;
|
|
295
|
+
return 4;
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=vetMcp.js.map
|