suppa-mcp-2 1.7.1 → 1.8.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/README.md CHANGED
@@ -104,6 +104,34 @@ Then run **`suppa_login`** once per tenant to authenticate.
104
104
 
105
105
  ---
106
106
 
107
+ ## Which version is running (and is it current)
108
+
109
+ An MCP client keeps whatever build it started with — an `npx` cache or a
110
+ `node_modules` copy — for the whole session. Publishing a fix changes nothing
111
+ for that session, so "the fix isn't working" and "I'm running last week's
112
+ server" look identical from the inside. Two mechanisms keep them apart:
113
+
114
+ - **`suppa_version`** — read-only, asks the npm registry live, and reports the
115
+ running version, the published one, and the upgrade command. Ask it first
116
+ whenever a tool or behaviour you expect is missing. `suppa_health_check` also
117
+ carries `version` in every report, so a bug report names its build without
118
+ anyone remembering to ask.
119
+ - **An automatic notice.** The server checks the registry in the background
120
+ (detached, cached for 6h, 4s timeout, silent when offline — startup never
121
+ waits). If the running build is behind, the next session's instructions open
122
+ with an `OUTDATED` banner telling the agent to say so in its first reply, and
123
+ to restart the client after updating.
124
+
125
+ Upgrading: `npm i -g suppa-mcp-2@latest`, or pin `suppa-mcp-2@latest` in the
126
+ client's MCP config — then **restart the client**. Without the restart the old
127
+ process, and its old code, keep serving the session.
128
+
129
+ On the source side, the version is stated in `package.json` **only**.
130
+ `scripts/check-version-literals.mjs` runs inside `npm test` (and so inside
131
+ `prepublishOnly`) and fails the build if a version string is typed into `src/`:
132
+ the handshake once announced a hardcoded `1.6.1` for every release after it,
133
+ which made the one diagnostic question unanswerable.
134
+
107
135
  ## Agent workflow
108
136
 
109
137
  When an AI agent connects, the server provides built-in instructions describing the correct workflow. Auth first, then discover schema before reading or writing data:
@@ -176,7 +204,8 @@ work normally. Erasing data for good is an admin action in the platform's own UI
176
204
  | `suppa_list_tenants` | List known tenants + which is active / authenticated |
177
205
  | `suppa_logout` | Remove stored credentials for a tenant |
178
206
  | `suppa_diagnostics` | Validate the whole multi-tenant setup |
179
- | `suppa_health_check` | Config + upstream connectivity check |
207
+ | `suppa_health_check` | Config + upstream connectivity check (reports `version`) |
208
+ | `suppa_version` | Running build vs newest published, and how to upgrade |
180
209
 
181
210
  ### Tasks
182
211
 
package/dist/server.js CHANGED
@@ -6,9 +6,6 @@
6
6
  * server `instructions` string verbatim, and OWNS all confirm-gating (the tool
7
7
  * modules mutate unconditionally, exactly like the Python tool functions).
8
8
  */
9
- import { readFileSync } from "node:fs";
10
- import { dirname, join } from "node:path";
11
- import { fileURLToPath } from "node:url";
12
9
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
13
10
  import { z } from "zod";
14
11
  import * as tasks from "./tools/tasks.js";
@@ -22,24 +19,8 @@ import * as automation from "./tools/automation.js";
22
19
  import * as auth from "./auth.js";
23
20
  import * as tenants from "./tenants.js";
24
21
  import { confirmRequired, jsonResponse } from "./utils.js";
25
- /**
26
- * The running package's version, read from its own package.json rather than
27
- * typed in. A hand-maintained literal here reported 1.6.1 for every release
28
- * after it, which is exactly the wrong answer to "which version is my client
29
- * actually running?" — the question you ask when a fix appears not to have
30
- * landed. Handshake-only, so a failure to read it must never take the server
31
- * down.
32
- */
33
- export const PACKAGE_VERSION = (() => {
34
- try {
35
- const here = dirname(fileURLToPath(import.meta.url));
36
- // dist/server.js -> ../package.json; src/server.ts (tests) -> ../package.json
37
- return JSON.parse(readFileSync(join(here, "..", "package.json"), "utf-8")).version ?? "unknown";
38
- }
39
- catch {
40
- return "unknown";
41
- }
42
- })();
22
+ import { PACKAGE_NAME, PACKAGE_VERSION, knownLatest, isOutdated, refreshLatestVersion, refreshLatestVersionInBackground, upgradeNotice, } from "./version.js";
23
+ export { PACKAGE_VERSION };
43
24
  // ---------------------------------------------------------------------------
44
25
  // Tool-behavior hints (MCP spec): clients use these for auto-approval policies.
45
26
  // _READ touches nothing; _ADD only creates new data; _MUT changes or removes
@@ -335,7 +316,11 @@ export function buildServer() {
335
316
  // Reset so repeated buildServer() calls (e.g. in tests) do not double-count.
336
317
  TOOL_NAMES.length = 0;
337
318
  PROMPT_NAMES.length = 0;
338
- const server = new McpServer({ name: "suppa-2.0", version: PACKAGE_VERSION }, { instructions: INSTRUCTIONS });
319
+ // Detached, cached, TTL-limited: this session's instructions carry whatever
320
+ // the last check found, and this call keeps the answer fresh for the next
321
+ // one. Startup must never wait on the network.
322
+ refreshLatestVersionInBackground();
323
+ const server = new McpServer({ name: "suppa-2.0", version: PACKAGE_VERSION }, { instructions: INSTRUCTIONS + upgradeNotice() });
339
324
  const reg = (name, cfg, handler) => {
340
325
  server.registerTool(name, {
341
326
  description: cfg.description,
@@ -2182,6 +2167,40 @@ export function buildServer() {
2182
2167
  description: "List known Suppa tenants — which one is active and whether each is authenticated.",
2183
2168
  annotations: _READ,
2184
2169
  }, async () => text(tenants.listTenants()));
2170
+ reg("suppa_version", {
2171
+ description: "Which suppa-mcp-2 build this session is actually running, and whether a newer one is\n" +
2172
+ " published. Ask this FIRST whenever a fix, tool or behaviour you were told exists is\n" +
2173
+ " missing or behaves the old way: an MCP client keeps whatever version it started with\n" +
2174
+ " (npx cache / node_modules) for the whole session, so a release changes nothing until\n" +
2175
+ " the client is restarted on the new package. Reports running, latest, whether an\n" +
2176
+ " upgrade is available, and the command to run.",
2177
+ annotations: _READ,
2178
+ }, async () => {
2179
+ // Force a live lookup: this tool is the one place staleness must be
2180
+ // answered from the registry, not from a cache that may predate a release.
2181
+ const latest = await refreshLatestVersion(true);
2182
+ const outdated = isOutdated();
2183
+ return text(jsonResponse({
2184
+ package: PACKAGE_NAME,
2185
+ running: PACKAGE_VERSION,
2186
+ latest: latest ?? knownLatest(),
2187
+ up_to_date: latest ? !outdated : null,
2188
+ checked: latest !== null,
2189
+ upgrade: outdated
2190
+ ? {
2191
+ command: `npm i -g ${PACKAGE_NAME}@latest`,
2192
+ then: "RESTART the MCP client — a running server keeps its old code for the whole session.",
2193
+ note: "If the client launches this server via npx, pin @latest in its MCP config; npx " +
2194
+ "reuses a cached copy otherwise.",
2195
+ }
2196
+ : null,
2197
+ note: latest === null
2198
+ ? "The npm registry could not be reached, so 'latest' is the last value this machine cached (or null). The running version is exact."
2199
+ : outdated
2200
+ ? `Running ${PACKAGE_VERSION}; ${latest} is published. Tell the user, and treat any behaviour that contradicts newer docs as this build's behaviour.`
2201
+ : "This is the newest published build.",
2202
+ }));
2203
+ });
2185
2204
  reg("suppa_logout", {
2186
2205
  description: "Remove stored keychain credentials for a tenant (default: the active one).\n\n" +
2187
2206
  " APPROVAL GATE: without confirm=true this returns a confirmation request and\n" +
@@ -2342,6 +2361,12 @@ async function healthCheck(deep = true) {
2342
2361
  const token = ctx.getToken();
2343
2362
  const body = {
2344
2363
  service: "suppa-mcp",
2364
+ // Every health report names the build it came from: a bug report or a
2365
+ // "that fix isn't working" carries its version without anyone remembering
2366
+ // to ask. `outdated` is from the cached registry check (suppa_version
2367
+ // re-checks live).
2368
+ version: PACKAGE_VERSION,
2369
+ outdated: isOutdated() ? { latest: knownLatest(), action: "restart the client on the new package" } : false,
2345
2370
  tenant: ctx.host,
2346
2371
  base_url: ctx.baseUrl,
2347
2372
  token_configured: Boolean(token),
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Which version is running, and is it the current one.
3
+ *
4
+ * Two failures this module exists to make impossible to miss:
5
+ *
6
+ * 1. A version typed into the source. The MCP handshake announced a literal
7
+ * "1.6.1" for every release after it, so a client running the fix and a
8
+ * client running six releases behind reported the same string — the one
9
+ * question you ask when a fix appears not to have landed had a useless
10
+ * answer. PACKAGE_VERSION reads package.json; the release gate
11
+ * (scripts/check-version-literals.mjs) refuses any other spelling in src/.
12
+ *
13
+ * 2. An old version installed. A client pins whatever npx cached or
14
+ * node_modules holds; publishing a fix changes nothing until that client is
15
+ * restarted with the new package, and NOTHING in the session says so. The
16
+ * check below compares the running version against the registry and puts the
17
+ * answer where an agent cannot miss it: the server instructions, and the
18
+ * suppa_version tool.
19
+ *
20
+ * The registry lookup never blocks and never throws: it runs detached from
21
+ * startup, writes a cache, and the next session reads it. A machine with no
22
+ * network keeps working and simply never reports an upgrade.
23
+ */
24
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
25
+ import { dirname, join } from "node:path";
26
+ import { fileURLToPath } from "node:url";
27
+ import { homeDir } from "./registry.js";
28
+ /** The running package's own version, from its package.json. Never a literal. */
29
+ export const PACKAGE_VERSION = readOwnVersion();
30
+ function readOwnVersion() {
31
+ // dist/version.js -> ../package.json; src/version.ts (tests) -> ../package.json
32
+ const here = dirname(fileURLToPath(import.meta.url));
33
+ for (const candidate of [join(here, "..", "package.json"), join(here, "..", "..", "package.json")]) {
34
+ try {
35
+ const pkg = JSON.parse(readFileSync(candidate, "utf-8"));
36
+ if (pkg?.name === "suppa-mcp-2" && typeof pkg.version === "string")
37
+ return pkg.version;
38
+ }
39
+ catch {
40
+ /* try the next candidate */
41
+ }
42
+ }
43
+ return "unknown";
44
+ }
45
+ export const PACKAGE_NAME = "suppa-mcp-2";
46
+ const REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
47
+ /** How long a registry answer is trusted before it is fetched again. */
48
+ const CACHE_TTL_MS = 6 * 60 * 60 * 1000;
49
+ function cachePath() {
50
+ return join(homeDir(), "version-check.json");
51
+ }
52
+ function readCache() {
53
+ try {
54
+ const data = JSON.parse(readFileSync(cachePath(), "utf-8"));
55
+ if (typeof data?.latest === "string" && typeof data?.checked_at === "number")
56
+ return data;
57
+ }
58
+ catch {
59
+ /* absent or unreadable — treat as "never checked" */
60
+ }
61
+ return null;
62
+ }
63
+ function writeCache(cache) {
64
+ try {
65
+ mkdirSync(homeDir(), { recursive: true });
66
+ // Same write-then-rename the tenant registry uses: two servers starting at
67
+ // once must never read a half-written file.
68
+ const tmp = `${cachePath()}.${process.pid}.tmp`;
69
+ writeFileSync(tmp, `${JSON.stringify(cache, null, 2)}\n`, "utf-8");
70
+ renameSync(tmp, cachePath());
71
+ }
72
+ catch {
73
+ /* a cache that cannot be written just means the next session re-checks */
74
+ }
75
+ }
76
+ /** -1 / 0 / 1 by semver precedence; prerelease tags are ignored (we publish none). */
77
+ export function compareVersions(a, b) {
78
+ const parse = (v) => String(v)
79
+ .replace(/^v/, "")
80
+ .split("-")[0]
81
+ .split(".")
82
+ .map((n) => Number.parseInt(n, 10) || 0);
83
+ const [x, y] = [parse(a), parse(b)];
84
+ for (let i = 0; i < Math.max(x.length, y.length); i++) {
85
+ const d = (x[i] ?? 0) - (y[i] ?? 0);
86
+ if (d !== 0)
87
+ return d < 0 ? -1 : 1;
88
+ }
89
+ return 0;
90
+ }
91
+ /** The newest version this machine has ever seen, or null if it never looked. */
92
+ export function knownLatest() {
93
+ return readCache()?.latest ?? null;
94
+ }
95
+ /** Is the running build behind the newest version we know of? */
96
+ export function isOutdated() {
97
+ const latest = knownLatest();
98
+ if (!latest || PACKAGE_VERSION === "unknown")
99
+ return false;
100
+ return compareVersions(PACKAGE_VERSION, latest) < 0;
101
+ }
102
+ /**
103
+ * Ask the registry for the latest version, at most once per TTL, and cache it.
104
+ * Detached on purpose — the caller never awaits it, so a slow or blocked
105
+ * registry cannot delay a single tool call.
106
+ */
107
+ export async function refreshLatestVersion(force = false) {
108
+ const cached = readCache();
109
+ if (!force && cached && Date.now() - cached.checked_at < CACHE_TTL_MS)
110
+ return cached.latest;
111
+ try {
112
+ const controller = new AbortController();
113
+ const timer = setTimeout(() => controller.abort(), 4000);
114
+ const res = await fetch(REGISTRY_URL, {
115
+ signal: controller.signal,
116
+ headers: { accept: "application/vnd.npm.install-v1+json, application/json" },
117
+ });
118
+ clearTimeout(timer);
119
+ if (!res.ok)
120
+ return cached?.latest ?? null;
121
+ const body = (await res.json());
122
+ if (typeof body?.version !== "string")
123
+ return cached?.latest ?? null;
124
+ writeCache({ latest: body.version, checked_at: Date.now() });
125
+ return body.version;
126
+ }
127
+ catch {
128
+ // Offline, blocked, or slow. The running version is still perfectly usable.
129
+ return cached?.latest ?? null;
130
+ }
131
+ }
132
+ /** Fire the check without awaiting it, swallowing everything. */
133
+ export function refreshLatestVersionInBackground() {
134
+ void refreshLatestVersion().catch(() => undefined);
135
+ }
136
+ /**
137
+ * The line that goes into the server instructions when the running build is
138
+ * behind — empty otherwise, so a current install carries no noise.
139
+ */
140
+ export function upgradeNotice() {
141
+ if (!isOutdated())
142
+ return "";
143
+ return (`\n\nVERSION — YOU ARE RUNNING AN OUTDATED suppa-mcp-2 (${PACKAGE_VERSION}; ${knownLatest()} is published).\n` +
144
+ "Everything below describes THIS build, and fixes released since it are absent — behaviour you " +
145
+ "were told is fixed may not be. Before doing anything else, tell the user, in your first reply, " +
146
+ `that suppa-mcp-2 ${knownLatest()} is available and that the MCP client must be restarted after ` +
147
+ "updating (a running server keeps its old code for the whole session). Upgrade with " +
148
+ `\`npm i -g ${PACKAGE_NAME}@latest\` or by pinning @latest in the client's MCP config; ` +
149
+ "confirm with suppa_version.");
150
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suppa-mcp-2",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "MCP server for the Suppa platform (modern.suppa.me) — Tasks, Docs/Pages, Entities & Schema, Forms, Automations, and file attachments, with multi-tenant Google auth. Node port of PyPI suppa-mcp.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  "rebuild": "npm run clean && npm run build",
23
23
  "start": "node dist/bin.js",
24
24
  "dev": "tsc --watch",
25
- "test": "vitest run",
25
+ "test": "node scripts/check-version-literals.mjs && vitest run",
26
26
  "test:watch": "vitest",
27
27
  "prepublishOnly": "npm run build && npm test",
28
28
  "inspect": "npx @modelcontextprotocol/inspector node dist/bin.js"