foster-oss 0.0.0-stage → 0.2.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.
@@ -0,0 +1,274 @@
1
+ import { readdirSync } from "node:fs";
2
+ import { basename, dirname, join, relative, resolve } from "node:path";
3
+ import { readSbom } from "./sbom.js";
4
+ import { maxSeverity, toOrphanRecord } from "./classify.js";
5
+ import { findPatch, indexByName, indexKey, loadOrphanIndex, loadRegistry } from "./data.js";
6
+ import { getPackage } from "./ecosystems.js";
7
+ import { mapLimit } from "./http.js";
8
+ import { detectLockfiles, readDependencies } from "./lockfile.js";
9
+ import { describeForDependency, getVulns, lowestFixAbove, newerReleaseEscapes, queryBatch } from "./osv.js";
10
+ import { compareVersions, rangeIncludes } from "./versions.js";
11
+ import { alternativesFor } from "./replacements.js";
12
+ const KIND_ORDER = ["patch-available", "orphaned-vulnerable", "unpatched-vulnerable", "upgrade-available", "orphaned"];
13
+ const SEVERITY_ORDER = ["CRITICAL", "HIGH", "MODERATE", "LOW", "UNKNOWN"];
14
+ /** Folders never worth descending into when looking for lockfiles. */
15
+ const SKIP_DIRS = new Set(["node_modules", ".git", "vendor", "target", "dist", "build", ".venv", "venv", "__pycache__", ".next", ".nuxt", ".cache", "coverage", ".tox", "bower_components"]);
16
+ /** Directories under `root` (including root) that contain at least one supported lockfile. */
17
+ export function findProjectDirs(root, maxDepth = 6) {
18
+ const out = [];
19
+ const walk = (dir, depth) => {
20
+ if (detectLockfiles(dir).length)
21
+ out.push(dir);
22
+ if (depth >= maxDepth)
23
+ return;
24
+ let entries;
25
+ try {
26
+ entries = readdirSync(dir, { withFileTypes: true });
27
+ }
28
+ catch {
29
+ return;
30
+ }
31
+ for (const e of entries) {
32
+ if (!e.isDirectory() || SKIP_DIRS.has(e.name) || (e.name.startsWith(".") && e.name !== "."))
33
+ continue;
34
+ walk(join(dir, e.name), depth + 1);
35
+ }
36
+ };
37
+ walk(root, 0);
38
+ return out;
39
+ }
40
+ export async function scanProject(dirInput, opts = {}) {
41
+ const dir = resolve(dirInput);
42
+ const warnings = [];
43
+ const projectDirs = opts.recursive ? findProjectDirs(dir) : [dir];
44
+ const lockfiles = [];
45
+ const all = [];
46
+ for (const pd of projectDirs) {
47
+ for (const lock of detectLockfiles(pd)) {
48
+ const prefix = relative(dir, pd).replace(/\\/g, "/");
49
+ const source = prefix ? `${prefix}/${lock.file}` : lock.file;
50
+ lockfiles.push(source);
51
+ for (const d of readDependencies(pd, lock))
52
+ all.push({ ...d, source });
53
+ }
54
+ }
55
+ if (lockfiles.length === 0) {
56
+ warnings.push(`no supported lockfile found${opts.recursive ? " in this folder or its subfolders" : " (use --recursive for monorepos)"}: package-lock.json, pnpm-lock.yaml, yarn.lock, uv.lock, poetry.lock, Pipfile.lock, requirements.txt, Cargo.lock, go.mod, Gemfile.lock, composer.lock`);
57
+ }
58
+ // The same package version used by several sub-projects is reported once (first lockfile wins).
59
+ const merged = new Map();
60
+ for (const d of all) {
61
+ const key = `${d.ecosystem}:${d.name}@${d.version}`;
62
+ const prev = merged.get(key);
63
+ if (!prev)
64
+ merged.set(key, { ...d });
65
+ else if (d.direct)
66
+ prev.direct = true; // direct in any sub-project counts
67
+ }
68
+ const deps = [...merged.values()];
69
+ const findings = await analyzeDependencies(deps, opts, warnings);
70
+ return {
71
+ dir,
72
+ scannedAt: new Date().toISOString(),
73
+ lockfiles,
74
+ dependencyCount: deps.length,
75
+ findings,
76
+ warnings,
77
+ };
78
+ }
79
+ /** Scan an SBOM (CycloneDX or SPDX JSON) instead of lockfiles. */
80
+ export async function scanSbom(file, opts = {}) {
81
+ const path = resolve(file);
82
+ const warnings = [];
83
+ const sbom = readSbom(path);
84
+ const skipped = Object.entries(sbom.skipped);
85
+ if (skipped.length)
86
+ warnings.push(`not covered yet: ${skipped.map(([t, n]) => `${n} ${t}`).join(", ")} package(s)`);
87
+ if (sbom.dependencies.length === 0)
88
+ warnings.push(`no supported packages with versions found in this ${sbom.format} SBOM`);
89
+ const findings = await analyzeDependencies(sbom.dependencies, opts, warnings);
90
+ return {
91
+ dir: dirname(path),
92
+ scannedAt: new Date().toISOString(),
93
+ lockfiles: [basename(path)],
94
+ dependencyCount: sbom.dependencies.length,
95
+ findings,
96
+ warnings,
97
+ };
98
+ }
99
+ export async function analyzeDependencies(deps, opts = {}, warnings = []) {
100
+ const loadOpts = { offline: opts.offline };
101
+ const [registry, indexFile] = await Promise.all([
102
+ loadRegistry({ ...loadOpts, file: opts.registryFile }, warnings),
103
+ loadOrphanIndex({ ...loadOpts, file: opts.indexFile }, warnings),
104
+ ]);
105
+ const index = indexByName(indexFile);
106
+ for (const [key, record] of opts.records ?? [])
107
+ index.set(key, record);
108
+ // 1. Live vulnerability data from OSV (skipped offline).
109
+ let vulnIds = deps.map(() => []);
110
+ if (!opts.offline && deps.length > 0) {
111
+ try {
112
+ vulnIds = await queryBatch(deps);
113
+ }
114
+ catch (err) {
115
+ warnings.push(`OSV vulnerability lookup failed, results use bundled data only: ${err.message}`);
116
+ }
117
+ }
118
+ let vulnDetails = new Map();
119
+ try {
120
+ vulnDetails = await getVulns(vulnIds.flat());
121
+ }
122
+ catch (err) {
123
+ warnings.push(`could not fetch vulnerability details: ${err.message}`);
124
+ }
125
+ const pending = deps.map((dep, i) => {
126
+ const vulns = [];
127
+ for (const id of vulnIds[i] ?? []) {
128
+ const v = vulnDetails.get(id);
129
+ if (!v || v.withdrawn)
130
+ continue;
131
+ const d = describeForDependency(v, dep);
132
+ if (d.isMalware)
133
+ continue; // hijacked releases need removal, not a patch; npm audit / OSV scanners report them
134
+ vulns.push(d);
135
+ }
136
+ const record = index.get(indexKey(dep.ecosystem, dep.name));
137
+ // Offline, fall back to the index's own list of unpatched advisories for this package.
138
+ if (opts.offline && record) {
139
+ for (const a of record.unpatchedAdvisories) {
140
+ if (!a.range || rangeIncludes(a.range, dep.version))
141
+ vulns.push({ advisory: a, fixedVersions: [], lastAffected: [], isMalware: false });
142
+ }
143
+ }
144
+ return { dep, vulns, record };
145
+ });
146
+ // 3. Live maintenance lookups for vulnerable packages the index does not cover.
147
+ if (!opts.offline && opts.deep !== false) {
148
+ const needLookup = pending.filter((p) => p.vulns.some((v) => v.fixedVersions.length === 0) && !p.record);
149
+ const unique = [...new Map(needLookup.map((p) => [indexKey(p.dep.ecosystem, p.dep.name), p.dep])).values()].slice(0, opts.deepLimit ?? 50);
150
+ const looked = new Map();
151
+ await mapLimit(unique, 4, async (dep) => {
152
+ try {
153
+ const raw = await getPackage(dep.ecosystem, dep.name);
154
+ looked.set(indexKey(dep.ecosystem, dep.name), toOrphanRecord(raw, dep.ecosystem));
155
+ }
156
+ catch {
157
+ // unknown status is fine; reported as such
158
+ }
159
+ });
160
+ for (const p of needLookup)
161
+ p.record = looked.get(indexKey(p.dep.ecosystem, p.dep.name));
162
+ }
163
+ // 4. Split into "fixed somewhere upstream" and "no fix anywhere", then turn into findings.
164
+ const findings = [];
165
+ for (const p of pending) {
166
+ const unpatched = [];
167
+ const fixable = [];
168
+ const fixes = [];
169
+ for (const v of p.vulns) {
170
+ if (v.fixedVersions.length > 0) {
171
+ fixable.push(v.advisory);
172
+ const f = lowestFixAbove(p.dep, v.fixedVersions);
173
+ if (f)
174
+ fixes.push(f);
175
+ }
176
+ else if (newerReleaseEscapes(v, p.record?.latestVersion)) {
177
+ fixable.push(v.advisory);
178
+ fixes.push(p.record.latestVersion);
179
+ }
180
+ else {
181
+ unpatched.push(v.advisory);
182
+ }
183
+ }
184
+ const f = toFinding(p.dep, dedupeAdvisories(unpatched), dedupeAdvisories(fixable), highestVersion(fixes), p.record, registry, opts.includeStaged ?? false);
185
+ if (f) {
186
+ // Where to go next: a maintained replacement, for anything that is not a plain upgrade.
187
+ if (f.kind !== "upgrade-available")
188
+ f.alternatives = alternativesFor(f.dependency.ecosystem, f.dependency.name);
189
+ findings.push(f);
190
+ }
191
+ }
192
+ return sortFindings(findings);
193
+ }
194
+ function dedupeAdvisories(list) {
195
+ return [...new Map(list.map((a) => [a.id, a])).values()];
196
+ }
197
+ function toFinding(dep, unpatched, fixable, fixedIn, record, registry, includeStaged) {
198
+ const status = record?.status ?? "unknown";
199
+ const patch = findPatch(registry, dep, includeStaged);
200
+ const label = `${dep.name}@${dep.version}`;
201
+ if (patch) {
202
+ const advisories = unpatched.length ? unpatched : patch.advisories.map((id) => ({ id, url: id.startsWith("GHSA-") ? `https://github.com/advisories/${id}` : `https://osv.dev/vulnerability/${id}`, severity: "UNKNOWN", title: id }));
203
+ return {
204
+ kind: "patch-available",
205
+ dependency: dep,
206
+ status,
207
+ severity: maxSeverity(advisories),
208
+ advisories,
209
+ patch,
210
+ message: `${label}: drop-in patch ${patch.replacement.name}@${patch.replacement.version} by ${patch.provider?.name ?? "Foster"}${patch.status === "staged" ? " (staged, not yet released)" : ""} fixes ${patch.advisories.join(", ")}. Run \`foster-oss fix\`.`,
211
+ };
212
+ }
213
+ if (unpatched.length > 0) {
214
+ const orphaned = status === "dead" || status === "dormant";
215
+ return {
216
+ kind: orphaned ? "orphaned-vulnerable" : "unpatched-vulnerable",
217
+ dependency: dep,
218
+ status,
219
+ severity: maxSeverity(unpatched),
220
+ advisories: unpatched,
221
+ message: orphaned
222
+ ? `${label}: ${unpatched.length} advisory(ies) with no fix anywhere, and the package looks ${status}. A good candidate for Foster adoption.`
223
+ : `${label}: ${unpatched.length} advisory(ies) with no released fix yet (maintenance: ${status}).`,
224
+ };
225
+ }
226
+ if (fixable.length > 0) {
227
+ return {
228
+ kind: "upgrade-available",
229
+ dependency: dep,
230
+ status,
231
+ severity: maxSeverity(fixable),
232
+ advisories: fixable,
233
+ fixedIn,
234
+ message: `${label}: fixed upstream${fixedIn ? ` in ${fixedIn}` : ""}. Upgrade normally; no patch needed.`,
235
+ };
236
+ }
237
+ if (record && (record.status === "dead" || record.status === "dormant")) {
238
+ return {
239
+ kind: "orphaned",
240
+ dependency: dep,
241
+ status: record.status,
242
+ severity: "UNKNOWN",
243
+ advisories: [],
244
+ message: `${label}: widely used but ${record.status} (${record.reasons.join("; ")}). No known vulnerability today.`,
245
+ };
246
+ }
247
+ return null;
248
+ }
249
+ /** Highest of several fix versions: upgrading to it fixes every listed advisory. */
250
+ function highestVersion(versions) {
251
+ if (versions.length === 0)
252
+ return undefined;
253
+ return [...versions].sort(compareVersions).at(-1);
254
+ }
255
+ export function sortFindings(findings) {
256
+ return findings.sort((a, b) => KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind) ||
257
+ SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity) ||
258
+ a.dependency.name.localeCompare(b.dependency.name));
259
+ }
260
+ /** Whether the scan should fail CI, given the --fail-on threshold. */
261
+ export function shouldFail(findings, failOn) {
262
+ switch (failOn) {
263
+ case "none":
264
+ return false;
265
+ case "patch-available":
266
+ return findings.some((f) => f.kind === "patch-available");
267
+ case "orphaned-vulnerable":
268
+ return findings.some((f) => f.kind === "patch-available" || f.kind === "orphaned-vulnerable");
269
+ case "unpatched":
270
+ return findings.some((f) => ["patch-available", "orphaned-vulnerable", "unpatched-vulnerable"].includes(f.kind));
271
+ case "any":
272
+ return findings.length > 0;
273
+ }
274
+ }
@@ -0,0 +1,101 @@
1
+ import type { AlternativeSet } from "./replacements.js";
2
+ export type Ecosystem = "npm" | "pypi" | "cargo" | "go" | "rubygems" | "packagist";
3
+ export declare const ECOSYSTEMS: readonly Ecosystem[];
4
+ /** Human-readable names, used in reports and the site. */
5
+ export declare const ECOSYSTEM_LABEL: Record<Ecosystem, string>;
6
+ /** A resolved package found in a project's lockfile. */
7
+ export interface Dependency {
8
+ ecosystem: Ecosystem;
9
+ name: string;
10
+ version: string;
11
+ /** True when the package is listed directly in the project manifest. */
12
+ direct: boolean;
13
+ /** Lockfile the dependency was read from (relative to the scanned dir). */
14
+ source: string;
15
+ }
16
+ export type MaintenanceStatus = "active" | "dormant" | "dead" | "unknown";
17
+ export type Severity = "CRITICAL" | "HIGH" | "MODERATE" | "LOW" | "UNKNOWN";
18
+ export interface AdvisorySummary {
19
+ id: string;
20
+ url: string;
21
+ severity: Severity;
22
+ title: string;
23
+ /** Vulnerable version range as published by the advisory source. */
24
+ range?: string;
25
+ }
26
+ /** One row of the Orphan Index. */
27
+ export interface OrphanRecord {
28
+ ecosystem: Ecosystem;
29
+ name: string;
30
+ status: MaintenanceStatus;
31
+ reasons: string[];
32
+ downloadsLastMonth: number | null;
33
+ dependentRepos: number | null;
34
+ dependentPackages: number | null;
35
+ latestVersion: string | null;
36
+ latestReleaseAt: string | null;
37
+ repoUrl: string | null;
38
+ archived: boolean;
39
+ lastPushAt: string | null;
40
+ /** Number of accounts able to publish to the registry, when known. */
41
+ publishers: number | null;
42
+ unpatchedAdvisories: AdvisorySummary[];
43
+ /** Priority score: higher means more people are exposed to an unmaintained, vulnerable package. */
44
+ priority: number;
45
+ }
46
+ export type PatchStatus = "staged" | "released" | "retired";
47
+ /** An entry in Foster's patch registry (registry/patches.json). */
48
+ export interface PatchEntry {
49
+ ecosystem: Ecosystem;
50
+ /** Original package name. */
51
+ name: string;
52
+ /** semver range of original versions this patch replaces. */
53
+ affected: string;
54
+ replacement: {
55
+ name: string;
56
+ version: string;
57
+ };
58
+ advisories: string[];
59
+ status: PatchStatus;
60
+ /** Who publishes and maintains the patched package. Absent means Foster itself. */
61
+ provider?: {
62
+ name: string;
63
+ url: string;
64
+ };
65
+ /** Path of the patch folder inside the Foster repo (Foster patches only), e.g. patches/npm/ip. */
66
+ patchDir?: string;
67
+ summary: string;
68
+ }
69
+ export type FindingKind =
70
+ /** A published drop-in security patch (from Foster or another provider) exists for this exact version. */
71
+ "patch-available"
72
+ /** Known vulnerability with no upstream fix, and the package is dead or dormant. */
73
+ | "orphaned-vulnerable"
74
+ /** Known vulnerability with no upstream fix; maintenance status active or unknown. */
75
+ | "unpatched-vulnerable"
76
+ /** Known vulnerability that is fixed in a newer upstream version: just upgrade. */
77
+ | "upgrade-available"
78
+ /** Critical package that is dead or dormant, no known vulnerability (yet). */
79
+ | "orphaned";
80
+ export interface Finding {
81
+ kind: FindingKind;
82
+ dependency: Dependency;
83
+ status: MaintenanceStatus;
84
+ severity: Severity;
85
+ advisories: AdvisorySummary[];
86
+ patch?: PatchEntry;
87
+ /** For upgrade-available: the lowest version that fixes all listed advisories, if known. */
88
+ fixedIn?: string;
89
+ /** Maintained replacements worth moving to (npm only, from e18e module-replacements). */
90
+ alternatives?: AlternativeSet;
91
+ message: string;
92
+ }
93
+ export interface ScanResult {
94
+ dir: string;
95
+ scannedAt: string;
96
+ lockfiles: string[];
97
+ dependencyCount: number;
98
+ findings: Finding[];
99
+ /** Data sources that could not be reached; results may be incomplete. */
100
+ warnings: string[];
101
+ }
@@ -0,0 +1,10 @@
1
+ export const ECOSYSTEMS = ["npm", "pypi", "cargo", "go", "rubygems", "packagist"];
2
+ /** Human-readable names, used in reports and the site. */
3
+ export const ECOSYSTEM_LABEL = {
4
+ npm: "npm",
5
+ pypi: "PyPI",
6
+ cargo: "Cargo",
7
+ go: "Go",
8
+ rubygems: "RubyGems",
9
+ packagist: "Packagist",
10
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Compare two versions. Uses semver when both parse; otherwise understands release numbers and
3
+ * pre/post-release tags (PEP 440 "2.0.0rc1" < "2.0.0" < "2.0.0.post1", RubyGems "7.1.0.rc1" < "7.1.0").
4
+ */
5
+ export declare function compareVersions(a: string, b: string): number;
6
+ /**
7
+ * Does a GitHub-advisory style range (e.g. "<= 2.0.1", ">= 2.0.0, <= 3.0.0", "= 1.2.9")
8
+ * include this version? Returns true when the range cannot be parsed, so callers err on the side of caution.
9
+ */
10
+ export declare function rangeIncludes(range: string | undefined, version: string): boolean;
@@ -0,0 +1,81 @@
1
+ import semver from "semver";
2
+ const PHASE = { dev: -4, alpha: -3, a: -3, beta: -2, b: -2, rc: -1, c: -1, pre: -1, preview: -1, post: 1, rev: 1, r: 1 };
3
+ /** Parse PEP 440 / RubyGems / Go style versions: release numbers plus an optional pre/post/dev tag. */
4
+ function parse(version) {
5
+ const s = version.trim().toLowerCase().replace(/^v(?=\d)/, "").replace(/\+.*$/, "");
6
+ const m = s.match(/^(\d+(?:\.\d+)*)(.*)$/);
7
+ if (!m?.[1])
8
+ return null;
9
+ const release = m[1].split(".").map(Number);
10
+ const rest = (m[2] ?? "").replace(/^[.\-_]/, "");
11
+ if (!rest)
12
+ return { release, phase: 0, phaseNumber: 0 };
13
+ // The leading tag decides ("1.0rc1.post2" sorts as an rc).
14
+ const t = rest.match(/^(preview|alpha|beta|post|pre|rev|dev|rc|a|b|c|r)[.\-_]?(\d*)(?![a-z])/);
15
+ if (t?.[1])
16
+ return { release, phase: PHASE[t[1]] ?? 0, phaseNumber: Number(t[2] || 0) };
17
+ // Unknown suffix (platform, build tag): treat as the final release.
18
+ return { release, phase: 0, phaseNumber: 0 };
19
+ }
20
+ /**
21
+ * Compare two versions. Uses semver when both parse; otherwise understands release numbers and
22
+ * pre/post-release tags (PEP 440 "2.0.0rc1" < "2.0.0" < "2.0.0.post1", RubyGems "7.1.0.rc1" < "7.1.0").
23
+ */
24
+ export function compareVersions(a, b) {
25
+ if (semver.valid(a) && semver.valid(b))
26
+ return semver.compare(a, b);
27
+ const pa = parse(a);
28
+ const pb = parse(b);
29
+ if (!pa || !pb) {
30
+ // Fall back to digit groups for anything unparsable.
31
+ const da = a.split(/[^0-9]+/).filter(Boolean).map(Number);
32
+ const db = b.split(/[^0-9]+/).filter(Boolean).map(Number);
33
+ return compareArrays(da, db);
34
+ }
35
+ return compareArrays(pa.release, pb.release) || Math.sign(pa.phase - pb.phase) || Math.sign(pa.phaseNumber - pb.phaseNumber);
36
+ }
37
+ function compareArrays(a, b) {
38
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
39
+ const d = (a[i] ?? 0) - (b[i] ?? 0);
40
+ if (d !== 0)
41
+ return d < 0 ? -1 : 1;
42
+ }
43
+ return 0;
44
+ }
45
+ /**
46
+ * Does a GitHub-advisory style range (e.g. "<= 2.0.1", ">= 2.0.0, <= 3.0.0", "= 1.2.9")
47
+ * include this version? Returns true when the range cannot be parsed, so callers err on the side of caution.
48
+ */
49
+ export function rangeIncludes(range, version) {
50
+ if (!range)
51
+ return true;
52
+ const parts = range.split(",").map((s) => s.trim()).filter(Boolean);
53
+ for (const part of parts) {
54
+ const m = part.match(/^(<=|>=|<|>|=|==)?\s*v?([0-9][^\s]*)$/);
55
+ if (!m?.[2])
56
+ return true;
57
+ const cmp = compareVersions(version, m[2]);
58
+ switch (m[1] ?? "=") {
59
+ case "<=":
60
+ if (!(cmp <= 0))
61
+ return false;
62
+ break;
63
+ case ">=":
64
+ if (!(cmp >= 0))
65
+ return false;
66
+ break;
67
+ case "<":
68
+ if (!(cmp < 0))
69
+ return false;
70
+ break;
71
+ case ">":
72
+ if (!(cmp > 0))
73
+ return false;
74
+ break;
75
+ default:
76
+ if (cmp !== 0)
77
+ return false;
78
+ }
79
+ }
80
+ return true;
81
+ }
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export declare function createMcpServer(): McpServer;
3
+ export declare function startMcpServer(): Promise<void>;
package/dist/mcp.js ADDED
@@ -0,0 +1,74 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { z } from "zod";
4
+ import { checkPackage } from "./lib/check.js";
5
+ import { loadRegistry } from "./lib/data.js";
6
+ import { fosterVersion } from "./lib/http.js";
7
+ import { formatMarkdown, formatRecord } from "./lib/report.js";
8
+ import { scanProject } from "./lib/scan.js";
9
+ import { describeAlternatives } from "./lib/replacements.js";
10
+ function text(s) {
11
+ return { content: [{ type: "text", text: s }] };
12
+ }
13
+ export function createMcpServer() {
14
+ const server = new McpServer({ name: "foster-oss", version: fosterVersion() });
15
+ server.registerTool("foster_check_package", {
16
+ title: "Check a package before depending on it",
17
+ description: "Check whether a package (npm, PyPI, Cargo, Go, RubyGems or Packagist) is still maintained, whether it has vulnerabilities with no fix, " +
18
+ "and whether a published drop-in security patch exists (from Foster or providers like Keep LTS). Call this before adding a new dependency.",
19
+ inputSchema: {
20
+ name: z.string().describe("Package name, e.g. 'ip' or '@scope/name'"),
21
+ version: z.string().optional().describe("Exact version to check, e.g. '2.0.1'"),
22
+ ecosystem: z.enum(["npm", "pypi", "cargo", "go", "rubygems", "packagist"]).default("npm"),
23
+ },
24
+ annotations: { readOnlyHint: true, openWorldHint: true },
25
+ }, async ({ name, version, ecosystem }) => {
26
+ const r = await checkPackage(ecosystem, name, version);
27
+ if (r.notFound)
28
+ return text(`${name} was not found on ${ecosystem}. Check the spelling: it may be a hallucinated or typosquatted name.`);
29
+ const parts = [];
30
+ if (r.record)
31
+ parts.push(formatRecord(r.record));
32
+ for (const f of r.findings)
33
+ parts.push(f.message);
34
+ if (version && r.findings.length === 0)
35
+ parts.push(`${name}@${version}: no known vulnerabilities.`);
36
+ if (r.alternatives)
37
+ parts.push(`Maintained alternatives: ${describeAlternatives(r.alternatives)}`);
38
+ if (r.record && (r.record.status === "dead" || r.record.status === "dormant"))
39
+ parts.push("Advice: prefer a maintained alternative for new code; if you must use it, pin the version and watch for advisories.");
40
+ return text(parts.join("\n\n"));
41
+ });
42
+ server.registerTool("foster_scan_project", {
43
+ title: "Scan a project for orphaned dependencies",
44
+ description: "Scan the lockfiles in a directory (npm, pnpm, yarn, uv, poetry, pipenv, requirements.txt, Cargo.lock, go.mod, Gemfile.lock, composer.lock) " +
45
+ "and report dependencies that are unmaintained, vulnerable with no fix, or have a drop-in security patch.",
46
+ inputSchema: {
47
+ path: z.string().describe("Absolute path of the project directory"),
48
+ recursive: z.boolean().default(false).describe("Also scan lockfiles in subfolders (monorepos)"),
49
+ },
50
+ annotations: { readOnlyHint: true, openWorldHint: true },
51
+ }, async ({ path, recursive }) => {
52
+ const result = await scanProject(path, { recursive });
53
+ return text(formatMarkdown(result));
54
+ });
55
+ server.registerTool("foster_list_patches", {
56
+ title: "List known drop-in patches",
57
+ description: "List known drop-in security patches for abandoned packages (Foster and other providers), with the versions they replace and the advisories they fix.",
58
+ inputSchema: {},
59
+ annotations: { readOnlyHint: true },
60
+ }, async () => {
61
+ const reg = await loadRegistry();
62
+ if (reg.patches.length === 0)
63
+ return text("No patches in the registry yet.");
64
+ return text(reg.patches
65
+ .filter((p) => p.status !== "retired")
66
+ .map((p) => `- ${p.ecosystem}:${p.name}@${p.affected} → ${p.replacement.name}@${p.replacement.version} by ${p.provider?.name ?? "Foster"} [${p.status}] fixes ${p.advisories.join(", ")}. ${p.summary}`)
67
+ .join("\n"));
68
+ });
69
+ return server;
70
+ }
71
+ export async function startMcpServer() {
72
+ const server = createMcpServer();
73
+ await server.connect(new StdioServerTransport());
74
+ }
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "foster-oss",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.1",
4
+ "mcpName": "io.github.foster-oss/foster",
5
+ "description": "Find dependencies nobody maintains anymore (npm, PyPI, Cargo, Go, RubyGems, Packagist), and switch to published drop-in security patches without changing your imports.",
6
+ "keywords": [
7
+ "security",
8
+ "supply-chain",
9
+ "abandoned",
10
+ "unmaintained",
11
+ "orphaned-packages",
12
+ "vulnerability",
13
+ "overrides",
14
+ "mcp",
15
+ "ai-agents",
16
+ "rust",
17
+ "golang",
18
+ "ruby",
19
+ "php",
20
+ "python",
21
+ "sarif",
22
+ "code-scanning"
23
+ ],
24
+ "license": "Apache-2.0",
25
+ "type": "module",
26
+ "bin": {
27
+ "foster-oss": "dist/cli.js"
28
+ },
29
+ "main": "dist/index.js",
30
+ "types": "dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "data/orphans.min.json",
40
+ "registry/patches.json",
41
+ "skills",
42
+ "registry/alternatives.json"
43
+ ],
44
+ "engines": {
45
+ "node": ">=20"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/foster-oss/foster.git"
50
+ },
51
+ "homepage": "https://github.com/foster-oss/foster#readme",
52
+ "bugs": {
53
+ "url": "https://github.com/foster-oss/foster/issues"
54
+ },
55
+ "scripts": {
56
+ "build": "tsc -p tsconfig.json",
57
+ "typecheck": "tsc -p tsconfig.json --noEmit",
58
+ "test": "vitest run",
59
+ "index:build": "npm run build && node index/build.mjs",
60
+ "prepublishOnly": "npm run build && npm test"
61
+ },
62
+ "dependencies": {
63
+ "@modelcontextprotocol/sdk": "^1.32.2",
64
+ "module-replacements": "^3.4.0",
65
+ "semver": "^7.8.6",
66
+ "yaml": "^2.9.1",
67
+ "zod": "^4.6.7"
68
+ },
69
+ "devDependencies": {
70
+ "@types/node": "^24.19.4",
71
+ "@types/semver": "^7.8.0",
72
+ "typescript": "^7.0.2",
73
+ "vitest": "^5.1.2"
74
+ }
75
+ }