@vorim/mcp-server 1.1.5 → 1.1.7
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.js +71 -9
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -40,11 +40,41 @@ if (!API_KEY) {
|
|
|
40
40
|
process.exit(1);
|
|
41
41
|
}
|
|
42
42
|
// ─── HTTP Client ──────────────────────────────────────────────────────────
|
|
43
|
-
// Read the package version once so the User-Agent string and the
|
|
44
|
-
// server's advertised version stay in sync with package.json.
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
|
|
43
|
+
// Read the package version once so the User-Agent string and the
|
|
44
|
+
// MCP server's advertised version stay in sync with package.json.
|
|
45
|
+
//
|
|
46
|
+
// Caveats:
|
|
47
|
+
// 1. Bundlers (esbuild / webpack) that inline the source can break
|
|
48
|
+
// the readFileSync path because import.meta.url no longer points
|
|
49
|
+
// at the npm install layout. The fallback constant below is the
|
|
50
|
+
// last-known version and MUST be bumped in lockstep with
|
|
51
|
+
// package.json — there is NO CI assertion enforcing this today.
|
|
52
|
+
// 2. If readFileSync succeeds but JSON.parse fails (corrupt file),
|
|
53
|
+
// we log a warning so operators see the silent drift rather
|
|
54
|
+
// than discovering it via a User-Agent grep weeks later.
|
|
55
|
+
import { readFileSync } from "node:fs";
|
|
56
|
+
import { fileURLToPath } from "node:url";
|
|
57
|
+
import { dirname, join } from "node:path";
|
|
58
|
+
const MCP_VERSION_FALLBACK = "1.1.7";
|
|
59
|
+
function readMcpVersion() {
|
|
60
|
+
try {
|
|
61
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
62
|
+
const pkgPath = join(here, "..", "package.json");
|
|
63
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
64
|
+
if (typeof pkg.version === "string")
|
|
65
|
+
return pkg.version;
|
|
66
|
+
// eslint-disable-next-line no-console
|
|
67
|
+
console.warn(`[vorim-mcp-server] package.json missing version field — using fallback ${MCP_VERSION_FALLBACK}`);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
// eslint-disable-next-line no-console
|
|
71
|
+
console.warn(`[vorim-mcp-server] could not read package.json (${err.message ?? err}) — ` +
|
|
72
|
+
`using fallback ${MCP_VERSION_FALLBACK}. If this is a bundled build, bump ` +
|
|
73
|
+
`MCP_VERSION_FALLBACK in lockstep with the published package.`);
|
|
74
|
+
}
|
|
75
|
+
return MCP_VERSION_FALLBACK;
|
|
76
|
+
}
|
|
77
|
+
const MCP_VERSION = readMcpVersion();
|
|
48
78
|
/**
|
|
49
79
|
* URL-encode a user-supplied path segment. Agent ids, scopes, and
|
|
50
80
|
* chain ids all reach the API via path interpolation; raw slashes or
|
|
@@ -80,7 +110,19 @@ async function vorimRequest(method, path, body) {
|
|
|
80
110
|
}
|
|
81
111
|
throw new Error(err?.message || "Vorim API rejected with 403");
|
|
82
112
|
}
|
|
83
|
-
|
|
113
|
+
// Be defensive about non-JSON 5xx bodies (nginx 502, gateway HTML).
|
|
114
|
+
// Without this, response.json() throws "Unexpected token <" and the
|
|
115
|
+
// user sees an unhelpful parser error.
|
|
116
|
+
let json;
|
|
117
|
+
try {
|
|
118
|
+
json = await response.json();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
throw new Error(`Vorim API returned HTTP ${response.status} (non-JSON response — check upstream gateway)`);
|
|
123
|
+
}
|
|
124
|
+
throw new Error("Vorim API returned a non-JSON success response");
|
|
125
|
+
}
|
|
84
126
|
if (!response.ok) {
|
|
85
127
|
const err = json.error;
|
|
86
128
|
throw new Error(err?.message || `HTTP ${response.status}`);
|
|
@@ -117,8 +159,16 @@ server.registerTool("vorim_ping", {
|
|
|
117
159
|
const response = await fetch(`${BASE_URL}/health`, {
|
|
118
160
|
headers: { "User-Agent": `vorim-mcp-server/${MCP_VERSION}` },
|
|
119
161
|
});
|
|
120
|
-
|
|
121
|
-
|
|
162
|
+
if (!response.ok) {
|
|
163
|
+
throw new Error(`Vorim API health endpoint returned HTTP ${response.status}`);
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const data = await response.json();
|
|
167
|
+
return text(data);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
throw new Error(`Vorim API returned a non-JSON health response (status ${response.status}); check upstream gateway`);
|
|
171
|
+
}
|
|
122
172
|
});
|
|
123
173
|
// ─── Agent Identity ───────────────────────────────────────────────────────
|
|
124
174
|
server.registerTool("vorim_register_agent", {
|
|
@@ -284,7 +334,19 @@ server.registerTool("vorim_verify_trust", {
|
|
|
284
334
|
const response = await fetch(`${BASE_URL}/v1/trust/verify/${encId(agent_id)}`, {
|
|
285
335
|
headers: { "User-Agent": `vorim-mcp-server/${MCP_VERSION}` },
|
|
286
336
|
});
|
|
287
|
-
|
|
337
|
+
if (!response.ok) {
|
|
338
|
+
if (response.status === 404) {
|
|
339
|
+
throw new Error(`Agent ${agent_id} is not registered with Vorim`);
|
|
340
|
+
}
|
|
341
|
+
throw new Error(`Vorim trust endpoint returned HTTP ${response.status}`);
|
|
342
|
+
}
|
|
343
|
+
let json;
|
|
344
|
+
try {
|
|
345
|
+
json = await response.json();
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
throw new Error(`Vorim trust endpoint returned a non-JSON response (status ${response.status})`);
|
|
349
|
+
}
|
|
288
350
|
return text(json.data || json);
|
|
289
351
|
});
|
|
290
352
|
// ─── Ephemeral Agents ────────────────────────────────────────────────────
|
package/package.json
CHANGED