@thehammer/schema-mcp-server 1.0.12 → 1.0.13
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/dist/index.js +34 -1
- package/dist/version-check.d.ts +1 -0
- package/dist/version-check.js +20 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -19,12 +19,45 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
19
19
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
20
20
|
import { z } from "zod";
|
|
21
21
|
import * as api from "./api-client.js";
|
|
22
|
+
import { assertVersionCurrent } from "./version-check.js";
|
|
22
23
|
const require = createRequire(import.meta.url);
|
|
23
24
|
const pkg = require("../package.json");
|
|
25
|
+
/**
|
|
26
|
+
* Version frozen into memory at module load. Compared against the on-disk
|
|
27
|
+
* package.json before every tool handler runs, so if the server's own
|
|
28
|
+
* installation is updated during runtime (npm publish, npm install,
|
|
29
|
+
* manual replacement) the next tool call halts the process instead of
|
|
30
|
+
* silently serving stale code.
|
|
31
|
+
*/
|
|
32
|
+
const LOADED_VERSION = pkg.version;
|
|
24
33
|
const server = new McpServer({
|
|
25
34
|
name: "schema-mcp-server",
|
|
26
|
-
version:
|
|
35
|
+
version: LOADED_VERSION,
|
|
27
36
|
});
|
|
37
|
+
/**
|
|
38
|
+
* Prepend the version check to every tool handler — ONE place, all tools.
|
|
39
|
+
*
|
|
40
|
+
* `server.tool(name, desc, schema, handler)` is called 35+ times throughout
|
|
41
|
+
* this file. Rather than editing every call site, we override `server.tool`
|
|
42
|
+
* once right after the server is constructed: the override wraps the handler
|
|
43
|
+
* (always the last argument across all SDK overloads) with assertVersionCurrent,
|
|
44
|
+
* then delegates to the original implementation. New tools added in the future
|
|
45
|
+
* are covered automatically — no per-tool bookkeeping required.
|
|
46
|
+
*
|
|
47
|
+
* The check reads package.json via fs.readFileSync + JSON.parse on every call.
|
|
48
|
+
* `require()` would cache the first read and defeat the purpose. Sync fs reads
|
|
49
|
+
* of a ~500-byte file are measured in microseconds, so no caching is needed.
|
|
50
|
+
*/
|
|
51
|
+
const __origTool = server.tool.bind(server);
|
|
52
|
+
server.tool = (...args) => {
|
|
53
|
+
const handlerIdx = args.length - 1;
|
|
54
|
+
const handler = args[handlerIdx];
|
|
55
|
+
args[handlerIdx] = async (...handlerArgs) => {
|
|
56
|
+
assertVersionCurrent(LOADED_VERSION);
|
|
57
|
+
return handler(...handlerArgs);
|
|
58
|
+
};
|
|
59
|
+
return __origTool(...args);
|
|
60
|
+
};
|
|
28
61
|
/**
|
|
29
62
|
* Role-based tool registration.
|
|
30
63
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertVersionCurrent(loadedVersion: string): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime version check: compares the MCP server's in-memory version to its
|
|
3
|
+
* on-disk package.json and halts the process on mismatch so stale-code runs
|
|
4
|
+
* fail loudly instead of serving old behavior silently.
|
|
5
|
+
*
|
|
6
|
+
* Wired in once at the top of index.ts via a `server.tool` override — every
|
|
7
|
+
* tool handler runs this check before doing any work. See the override block
|
|
8
|
+
* in index.ts for the single call site.
|
|
9
|
+
*/
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
const pkgPath = fileURLToPath(new URL("../package.json", import.meta.url));
|
|
13
|
+
export function assertVersionCurrent(loadedVersion) {
|
|
14
|
+
const diskVersion = JSON.parse(fs.readFileSync(pkgPath, "utf8"))
|
|
15
|
+
.version;
|
|
16
|
+
if (diskVersion !== loadedVersion) {
|
|
17
|
+
console.error(`[schema-mcp-server] VERSION MISMATCH: loaded v${loadedVersion} in memory, v${diskVersion} on disk. Restart required.`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thehammer/schema-mcp-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "MCP server for Schema Builder - translates Claude Code tool calls into Laravel API requests",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
-
"build": "tsc",
|
|
24
|
+
"build": "tsc && chmod +x dist/index.js",
|
|
25
25
|
"start": "node dist/index.js",
|
|
26
26
|
"dev": "tsx watch src/index.ts"
|
|
27
27
|
},
|