@cliwant/mcp-sam-gov 1.5.0 → 1.7.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/LICENSE +21 -21
- package/README.ja.md +248 -231
- package/README.ko.md +248 -231
- package/README.md +733 -714
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/feedback.d.ts +64 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +131 -0
- package/dist/feedback.js.map +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +48 -2
- package/dist/server.js.map +1 -1
- package/dist/update-check.d.ts +38 -0
- package/dist/update-check.d.ts.map +1 -0
- package/dist/update-check.js +85 -0
- package/dist/update-check.js.map +1 -0
- package/package.json +111 -111
- package/src/attachments.ts +652 -652
- package/src/bea.ts +372 -372
- package/src/bls.ts +1943 -1943
- package/src/cache.ts +73 -73
- package/src/cbp-border.ts +177 -177
- package/src/census-economic.ts +431 -431
- package/src/census.ts +735 -735
- package/src/ckan.ts +495 -495
- package/src/clinicaltrials.ts +923 -923
- package/src/cms-facility.ts +379 -379
- package/src/cms-hospital.ts +344 -344
- package/src/cms-supplier.ts +527 -527
- package/src/cms-utilization.ts +389 -389
- package/src/cms.ts +634 -634
- package/src/coerce.ts +47 -47
- package/src/courtlistener.ts +465 -465
- package/src/cpsc.ts +333 -333
- package/src/datagov-catalog.ts +312 -312
- package/src/datagov.ts +907 -907
- package/src/datagovKey.ts +68 -68
- package/src/datasource.ts +721 -721
- package/src/disclosure.ts +61 -61
- package/src/dol.ts +515 -515
- package/src/ecfr.ts +248 -248
- package/src/echo.ts +496 -496
- package/src/edgar.ts +3046 -3046
- package/src/epa-envirofacts.ts +358 -358
- package/src/errors.ts +324 -314
- package/src/fac.ts +529 -529
- package/src/far.ts +1009 -1009
- package/src/fdic.ts +2052 -2052
- package/src/federal-register.ts +725 -725
- package/src/feedback.ts +160 -0
- package/src/fema.ts +680 -680
- package/src/fpds.ts +620 -620
- package/src/fred.ts +464 -464
- package/src/gao.ts +744 -744
- package/src/gov-domains.ts +237 -237
- package/src/govinfo.ts +497 -497
- package/src/grants.ts +290 -290
- package/src/gsa-csv.ts +992 -992
- package/src/gsa-perdiem.ts +361 -361
- package/src/integrity.ts +928 -928
- package/src/keys.ts +268 -268
- package/src/lda.ts +385 -385
- package/src/meta.ts +292 -292
- package/src/nhtsa.ts +352 -352
- package/src/nih.ts +375 -375
- package/src/nist-controls.ts +219 -219
- package/src/nonprofit.ts +460 -460
- package/src/nppes.ts +834 -834
- package/src/nsf.ts +706 -706
- package/src/nvd.ts +1124 -1124
- package/src/nws-weather.ts +167 -167
- package/src/ofac.ts +1166 -1166
- package/src/openfda-device.ts +356 -356
- package/src/openfda-drugsfda.ts +313 -313
- package/src/openfda.ts +518 -518
- package/src/pricing.ts +1075 -1075
- package/src/sam-gov/client.ts +774 -774
- package/src/sam-gov/index.ts +32 -32
- package/src/sam-gov/types.ts +152 -152
- package/src/sba.ts +357 -357
- package/src/server.ts +6692 -6639
- package/src/snapshot.ts +223 -223
- package/src/socrata.ts +532 -532
- package/src/treasury.ts +582 -582
- package/src/update-check.ts +88 -0
- package/src/usaspending.ts +2852 -2852
- package/src/usitc.ts +420 -420
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* update-check.ts — a startup "an update is available" notice (OPT-OUT, no telemetry).
|
|
3
|
+
*
|
|
4
|
+
* Why this exists
|
|
5
|
+
* ----------------
|
|
6
|
+
* npm is pull-based: a user who already installed the server is never told that a
|
|
7
|
+
* newer version shipped. This closes that gap with the least intrusive mechanism
|
|
8
|
+
* possible — a single anonymous version check on startup.
|
|
9
|
+
*
|
|
10
|
+
* What it does: one GET to the PUBLIC npm registry for THIS package's `latest`
|
|
11
|
+
* version, compared to the running version. Only if a newer one exists does it print
|
|
12
|
+
* one friendly line to STDERR.
|
|
13
|
+
*
|
|
14
|
+
* This is NOT telemetry. It sends NO user data anywhere — it fetches our own
|
|
15
|
+
* package's public version metadata from registry.npmjs.org (the same registry the
|
|
16
|
+
* package was installed from). It is, by construction:
|
|
17
|
+
* • opt-out via `MCP_SAM_GOV_NO_UPDATE_CHECK=1` (or the de-facto `NO_UPDATE_NOTIFIER=1`);
|
|
18
|
+
* • non-blocking (fire-and-forget with a short timeout — never delays startup);
|
|
19
|
+
* • fail-silent (any network / parse / abort error prints nothing and never throws);
|
|
20
|
+
* • STDERR-only (the JSON-RPC stdout stream is never touched);
|
|
21
|
+
* • quiet when up-to-date (prints only when a strictly-newer version exists).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export const REGISTRY_LATEST_URL =
|
|
25
|
+
"https://registry.npmjs.org/@cliwant/mcp-sam-gov/latest";
|
|
26
|
+
const TIMEOUT_MS = 3000;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Strictly-newer compare on the numeric MAJOR.MINOR.PATCH prefix only. A prerelease
|
|
30
|
+
* or build suffix on either side is ignored (a `-rc` is never announced as "newer"
|
|
31
|
+
* than the release it precedes). Non-numeric junk coerces to 0, so a malformed
|
|
32
|
+
* registry value can never spuriously trigger a notice.
|
|
33
|
+
*/
|
|
34
|
+
export function isNewerVersion(latest: string, current: string): boolean {
|
|
35
|
+
const parse = (v: string): number[] =>
|
|
36
|
+
String(v)
|
|
37
|
+
.split("-")[0]!
|
|
38
|
+
.split(".")
|
|
39
|
+
.slice(0, 3)
|
|
40
|
+
.map((x) => {
|
|
41
|
+
const n = Number.parseInt(x, 10);
|
|
42
|
+
return Number.isFinite(n) ? n : 0;
|
|
43
|
+
});
|
|
44
|
+
const a = parse(latest);
|
|
45
|
+
const b = parse(current);
|
|
46
|
+
for (let i = 0; i < 3; i++) {
|
|
47
|
+
const ai = a[i] ?? 0;
|
|
48
|
+
const bi = b[i] ?? 0;
|
|
49
|
+
if (ai > bi) return true;
|
|
50
|
+
if (ai < bi) return false;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Perform the startup update check. `log` defaults to stderr and is injectable so the
|
|
57
|
+
* offline fault suite can assert exactly when a notice is (and is not) emitted.
|
|
58
|
+
* Resolves to the message that was logged, or null if nothing was logged — for tests;
|
|
59
|
+
* the server calls it fire-and-forget and ignores the result.
|
|
60
|
+
*/
|
|
61
|
+
export async function checkForUpdate(
|
|
62
|
+
currentVersion: string,
|
|
63
|
+
log: (msg: string) => void = (m) => console.error(m),
|
|
64
|
+
): Promise<string | null> {
|
|
65
|
+
if (process.env.MCP_SAM_GOV_NO_UPDATE_CHECK || process.env.NO_UPDATE_NOTIFIER) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const res = await fetch(REGISTRY_LATEST_URL, {
|
|
70
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
71
|
+
headers: { Accept: "application/json" },
|
|
72
|
+
});
|
|
73
|
+
if (!res.ok) return null;
|
|
74
|
+
const body = (await res.json()) as { version?: unknown };
|
|
75
|
+
const latest = typeof body.version === "string" ? body.version : null;
|
|
76
|
+
if (!latest || !isNewerVersion(latest, currentVersion)) return null;
|
|
77
|
+
const msg =
|
|
78
|
+
`[mcp-sam-gov] a newer version is available: ${currentVersion} → ${latest}. ` +
|
|
79
|
+
`Update with 'npm i -g @cliwant/mcp-sam-gov@latest' (or just restart if you run it via 'npx @cliwant/mcp-sam-gov@latest'). ` +
|
|
80
|
+
`What changed: https://github.com/cliwant/mcp-sam-gov/releases ` +
|
|
81
|
+
`(silence this with MCP_SAM_GOV_NO_UPDATE_CHECK=1)`;
|
|
82
|
+
log(msg);
|
|
83
|
+
return msg;
|
|
84
|
+
} catch {
|
|
85
|
+
// Fail silent — an update check must never affect the server's operation.
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|