UNPKG

bottlenecks-mcp-server

Version:

Model Context Protocol server for Bottlenecks database - enables AI agents like Claude to interact with bottleneck data

60 lines 2.19 kB
/** * Version awareness for the bottlenecks-mcp-server npm package. * * Previously server.ts hardcoded version: '1.0.0' in two places, which had * drifted out of sync with the actually-published package (1.3.6 at time of * writing) — a connected AI agent had no way to tell it was talking to a * stale server, let alone that a newer one exists. PACKAGE_VERSION fixes the * "what am I" half; checkForUpdate() fixes the "is there something newer" * half by checking the real npm registry. */ import { createRequire } from 'module'; const require = createRequire(import.meta.url); const pkg = require('../package.json'); export const PACKAGE_NAME = pkg.name; export const PACKAGE_VERSION = pkg.version; /** * Compare against the latest version published to npm. Never throws — * a network failure (offline, registry down, corporate proxy) just reports * checkFailed: true so callers can silently skip the notice rather than * breaking server startup or a tool call over a version check. */ export async function checkForUpdate() { try { const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { signal: AbortSignal.timeout(3000) }); if (!response.ok) { return { current: PACKAGE_VERSION, latest: null, updateAvailable: false, checkFailed: true, }; } const data = (await response.json()); return { current: PACKAGE_VERSION, latest: data.version, updateAvailable: isNewer(data.version, PACKAGE_VERSION), checkFailed: false, }; } catch { return { current: PACKAGE_VERSION, latest: null, updateAvailable: false, checkFailed: true, }; } } function isNewer(latest, current) { const a = latest.split('.').map(Number); const b = current.split('.').map(Number); for (let i = 0; i < Math.max(a.length, b.length); i++) { const diff = (a[i] ?? 0) - (b[i] ?? 0); if (diff !== 0) return diff > 0; } return false; } //# sourceMappingURL=version.js.map