@omnidim-ai/mcp-server 0.5.1 → 0.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/build/index.d.ts +2 -2
- package/build/index.js +16 -11
- package/build/index.js.map +1 -1
- package/build/procedures.d.ts +13 -0
- package/build/procedures.js +184 -0
- package/build/procedures.js.map +1 -0
- package/build/tool-annotations.d.ts +10 -0
- package/build/tool-annotations.js +77 -0
- package/build/tool-annotations.js.map +1 -0
- package/build/update_notifier.d.ts +7 -0
- package/build/update_notifier.js +97 -0
- package/build/update_notifier.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +17 -11
- package/src/procedures.ts +206 -0
- package/src/tool-annotations.ts +86 -0
- package/src/update_notifier.ts +85 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Update notifier. This server is run by an MCP client via `npx`, so it cannot
|
|
3
|
+
* relaunch itself; an unpinned `npx` install already picks up the newest
|
|
4
|
+
* published version the next time the client restarts the server. This module
|
|
5
|
+
* just makes that visible: a one-line notice (stderr only, never stdout, which
|
|
6
|
+
* is the JSON-RPC channel) when the running version changed since last time, or
|
|
7
|
+
* when a newer version exists on npm. Everything here is best-effort and
|
|
8
|
+
* fail-silent: a notice must never delay startup or crash the server.
|
|
9
|
+
*/
|
|
10
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
|
|
14
|
+
const PACKAGE = "@omnidim-ai/mcp-server";
|
|
15
|
+
const RELEASES = "https://github.com/Omnidim/omnidim-mcp-server/releases";
|
|
16
|
+
const CONFIG_DIR = join(homedir(), ".config", "omnidim");
|
|
17
|
+
const LAST_VERSION_FILE = join(CONFIG_DIR, "last-version");
|
|
18
|
+
const LAST_CHECK_FILE = join(CONFIG_DIR, "last-update-check");
|
|
19
|
+
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // throttle the npm check to once a day
|
|
20
|
+
const FETCH_TIMEOUT_MS = 2500;
|
|
21
|
+
|
|
22
|
+
export function releaseTagUrl(version: string): string {
|
|
23
|
+
return `${RELEASES}/tag/v${version}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** True when `a` is a strictly newer semver than `b` (pre-release suffix ignored). */
|
|
27
|
+
export function isNewer(a: string, b: string): boolean {
|
|
28
|
+
const parse = (v: string) => v.split("-")[0].split(".").map((n) => parseInt(n, 10) || 0);
|
|
29
|
+
const [a1, a2, a3] = parse(a);
|
|
30
|
+
const [b1, b2, b3] = parse(b);
|
|
31
|
+
if (a1 !== b1) return a1 > b1;
|
|
32
|
+
if (a2 !== b2) return a2 > b2;
|
|
33
|
+
return a3 > b3;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function updatedNotice(version: string): string {
|
|
37
|
+
return `${PACKAGE} updated to v${version}. What's new: ${releaseTagUrl(version)}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function availableNotice(current: string, latest: string): string {
|
|
41
|
+
return `A newer ${PACKAGE} is available: v${latest} (you have v${current}). `
|
|
42
|
+
+ `Release notes: ${releaseTagUrl(latest)}. It updates automatically the next time your MCP client restarts.`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function readFileSafe(path: string): string | null {
|
|
46
|
+
try { return readFileSync(path, "utf8").trim() || null; } catch { return null; }
|
|
47
|
+
}
|
|
48
|
+
function writeFileSafe(path: string, value: string): void {
|
|
49
|
+
try { mkdirSync(CONFIG_DIR, { recursive: true }); writeFileSync(path, value); } catch { /* best-effort */ }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Print "just updated to vX" when the stored version differs from the running one. */
|
|
53
|
+
function notifyVersionChanged(current: string): void {
|
|
54
|
+
const stored = readFileSafe(LAST_VERSION_FILE);
|
|
55
|
+
if (stored && stored !== current && isNewer(current, stored)) {
|
|
56
|
+
console.error(updatedNotice(current));
|
|
57
|
+
}
|
|
58
|
+
if (stored !== current) writeFileSafe(LAST_VERSION_FILE, current);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Best-effort npm check (throttled, timeout-bounded, opt-out via env). */
|
|
62
|
+
async function notifyNewerAvailable(current: string): Promise<void> {
|
|
63
|
+
if (process.env.OMNIDIM_NO_UPDATE_CHECK) return;
|
|
64
|
+
if (typeof fetch !== "function") return;
|
|
65
|
+
const last = readFileSafe(LAST_CHECK_FILE);
|
|
66
|
+
if (last && Date.now() - Number(last) < CHECK_INTERVAL_MS) return;
|
|
67
|
+
writeFileSafe(LAST_CHECK_FILE, String(Date.now()));
|
|
68
|
+
try {
|
|
69
|
+
const ctrl = new AbortController();
|
|
70
|
+
const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS);
|
|
71
|
+
const res = await fetch(`https://registry.npmjs.org/${PACKAGE}/latest`, { signal: ctrl.signal });
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
if (!res.ok) return;
|
|
74
|
+
const latest = (await res.json())?.version;
|
|
75
|
+
if (typeof latest === "string" && isNewer(latest, current)) {
|
|
76
|
+
console.error(availableNotice(current, latest));
|
|
77
|
+
}
|
|
78
|
+
} catch { /* offline / timeout / parse error: stay silent */ }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Fire-and-forget. Synchronous local notice, async npm check that never blocks. */
|
|
82
|
+
export function notifyUpdates(currentVersion: string): void {
|
|
83
|
+
try { notifyVersionChanged(currentVersion); } catch { /* never block startup */ }
|
|
84
|
+
void notifyNewerAvailable(currentVersion);
|
|
85
|
+
}
|