@arkheia/mcp-server 1.2.2 → 1.2.4

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/egress.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_VERIFIER_URL = exports.DEFAULT_OLLAMA_URL = exports.HOSTED_API_URL = void 0;
4
+ exports.isLoopbackOrigin = isLoopbackOrigin;
5
+ exports.displayHost = displayHost;
6
+ exports.isArkheiaHostedOrigin = isArkheiaHostedOrigin;
7
+ exports.computeEgress = computeEgress;
8
+ exports.applyEgress = applyEgress;
9
+ const tool_registry_js_1 = require("./tool-registry.js");
10
+ // The built-in hosted API address (the same one ProxyClient defaults to).
11
+ exports.HOSTED_API_URL = "https://arkheia-proxy-production.up.railway.app";
12
+ exports.DEFAULT_OLLAMA_URL = "http://localhost:11434";
13
+ exports.DEFAULT_VERIFIER_URL = "http://localhost:8098";
14
+ /** True only for http(s) addresses whose host is localhost, 127.0.0.0/8 or ::1 (any port, any case). */
15
+ function isLoopbackOrigin(value) {
16
+ if (!value)
17
+ return false;
18
+ let u;
19
+ try {
20
+ u = new URL(value);
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ if (u.protocol !== "http:" && u.protocol !== "https:")
26
+ return false;
27
+ const h = u.hostname.toLowerCase();
28
+ if (h === "localhost" || h === "[::1]")
29
+ return true;
30
+ const m = h.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
31
+ return !!m && m[1] === "127" && m.slice(2).every((o) => Number(o) <= 255);
32
+ }
33
+ /** The origin only (host and port), never userinfo, path or query. */
34
+ function displayHost(value) {
35
+ try {
36
+ return new URL(value || "").host || "an address that is not valid";
37
+ }
38
+ catch {
39
+ return "an address that is not valid";
40
+ }
41
+ }
42
+ /**
43
+ * True when the address is the Arkheia hosted service: the built-in hosted origin or the configured custom hosted
44
+ * URL (origins compared parsed: host case-insensitive, default ports normalised). An address that cannot be parsed is
45
+ * refused (returns true), so the local-only path never sends to something it cannot classify.
46
+ */
47
+ function isArkheiaHostedOrigin(value, customHostedUrl) {
48
+ let origin;
49
+ try {
50
+ origin = new URL(value || "").origin;
51
+ }
52
+ catch {
53
+ return true;
54
+ }
55
+ if (origin === "null")
56
+ return true;
57
+ const hosted = [exports.HOSTED_API_URL, customHostedUrl].filter((x) => !!x);
58
+ for (const h of hosted) {
59
+ try {
60
+ if (new URL(h).origin === origin)
61
+ return true;
62
+ }
63
+ catch { /* an unparseable hosted setting cannot match */ }
64
+ }
65
+ return false;
66
+ }
67
+ function computeEgress(env) {
68
+ const ollama = env.OLLAMA_BASE_URL || exports.DEFAULT_OLLAMA_URL;
69
+ const verifier = env.ARKHEIA_PROXY_URL || exports.DEFAULT_VERIFIER_URL;
70
+ const remote = [];
71
+ if (!isLoopbackOrigin(ollama))
72
+ remote.push(`Ollama at ${displayHost(ollama)}`);
73
+ if (!isLoopbackOrigin(verifier))
74
+ remote.push(`verifier at ${displayHost(verifier)}`);
75
+ const run_ollama = remote.length === 0
76
+ ? { network_egress: false, description: "Uses local addresses: calls the Ollama address and the verifier address configured here (both recognised local addresses). Never contacts the Arkheia hosted service. If the local verifier is unavailable the response is returned unchecked." }
77
+ : { network_egress: true, description: `Calls the Ollama address and verifier address you configured (outside the recognised local addresses: ${remote.join(" and ")}). Never contacts the Arkheia hosted service.` };
78
+ const audit = isLoopbackOrigin(verifier)
79
+ ? { network_egress: false, description: "Retrieve structured audit evidence for compliance review. Reads the audit log from the verifier address configured here (a recognised local address)." }
80
+ : { network_egress: true, description: `Retrieve structured audit evidence for compliance review. Reads the audit log from the verifier address you configured (outside the recognised local addresses: ${displayHost(verifier)}).` };
81
+ return { run_ollama, arkheia_audit_log: audit };
82
+ }
83
+ /** Sets the registry's egress flags and descriptions from the actual configuration; returns them for the tool descriptions. */
84
+ function applyEgress(env) {
85
+ const e = computeEgress(env);
86
+ for (const k of ["run_ollama", "arkheia_audit_log"]) {
87
+ tool_registry_js_1.REGISTRY[k].network_egress = e[k].network_egress;
88
+ tool_registry_js_1.REGISTRY[k].description = e[k].description;
89
+ }
90
+ return e;
91
+ }
package/dist/index.js CHANGED
@@ -42,6 +42,7 @@ const os = __importStar(require("os"));
42
42
  const fs = __importStar(require("fs"));
43
43
  const proxy_client_js_1 = require("./proxy-client.js");
44
44
  const tool_registry_js_1 = require("./tool-registry.js");
45
+ const egress_js_1 = require("./egress.js");
45
46
  const providers_js_1 = require("./providers.js");
46
47
  const memory_js_1 = require("./memory.js");
47
48
  // ---------------------------------------------------------------------------
@@ -91,7 +92,7 @@ function handleError(toolName, e) {
91
92
  // ---------------------------------------------------------------------------
92
93
  // Main
93
94
  // ---------------------------------------------------------------------------
94
- const CURRENT_VERSION = "1.2.2";
95
+ const CURRENT_VERSION = "1.2.4";
95
96
  async function checkForUpdate() {
96
97
  // Check once per day — skip if checked recently
97
98
  const markerPath = path.join(os.homedir(), '.arkheia', '.update-check');
@@ -105,6 +106,7 @@ async function checkForUpdate() {
105
106
  catch { }
106
107
  try {
107
108
  const resp = await fetch('https://registry.npmjs.org/@arkheia/mcp-server/latest', {
109
+ redirect: 'error',
108
110
  signal: AbortSignal.timeout(5000),
109
111
  });
110
112
  if (resp.ok) {
@@ -146,8 +148,9 @@ async function main() {
146
148
  "Get a free API key at https://arkheia.ai/mcp\n" +
147
149
  "Then set: export ARKHEIA_API_KEY=ak_live_...\n\n");
148
150
  }
151
+ const egress = (0, egress_js_1.applyEgress)(process.env);
149
152
  const proxy = new proxy_client_js_1.ProxyClient(ARKHEIA_PROXY_URL, 10.0, ARKHEIA_HOSTED_URL, ARKHEIA_API_KEY);
150
- const server = new mcp_js_1.McpServer({ name: "arkheia-trust", version: "1.2.2" });
153
+ const server = new mcp_js_1.McpServer({ name: "arkheia-trust", version: "1.2.4" });
151
154
  // ── Detection & audit ──────────────────────────────────────────
152
155
  server.tool("arkheia_verify", "Verify whether an AI response shows signs of fabrication. Call this on EVERY model response before acting on it. Risk guidance: HIGH = warn the user this response may be fabricated and include the detection_id, but still show them the response with the warning. MEDIUM = show with a brief confidence note. LOW = show normally. Never hide or suppress a response — always surface it to the user with the appropriate risk context.", { prompt: zod_1.z.string(), response: zod_1.z.string(), model: zod_1.z.string() }, async ({ prompt, response, model }) => {
153
156
  try {
@@ -159,7 +162,7 @@ async function main() {
159
162
  return handleError("arkheia_verify", e);
160
163
  }
161
164
  });
162
- server.tool("arkheia_audit_log", "Retrieve structured audit evidence for compliance review.", { session_id: zod_1.z.string().optional(), limit: zod_1.z.number().int().min(1).max(500).default(50) }, async ({ session_id, limit }) => {
165
+ server.tool("arkheia_audit_log", egress.arkheia_audit_log.description, { session_id: zod_1.z.string().optional(), limit: zod_1.z.number().int().min(1).max(500).default(50) }, async ({ session_id, limit }) => {
163
166
  try {
164
167
  (0, tool_registry_js_1.check)("arkheia_audit_log");
165
168
  const result = await proxy.get_audit_log(session_id, Math.min(limit, 500));
@@ -196,13 +199,19 @@ async function main() {
196
199
  return handleError("run_gemini", e);
197
200
  }
198
201
  });
199
- server.tool("run_ollama", "Call a local Ollama model and screen the response through Arkheia. No network egress.", { prompt: zod_1.z.string(), model: zod_1.z.string().default("phi4:14b") }, async ({ prompt, model }) => {
202
+ server.tool("run_ollama", egress.run_ollama.description, { prompt: zod_1.z.string(), model: zod_1.z.string().default("phi4:14b") }, async ({ prompt, model }) => {
200
203
  try {
201
204
  (0, tool_registry_js_1.check)("run_ollama");
205
+ // Never contact the Arkheia hosted service from this tool: refuse before the model request sends anything.
206
+ const ollamaUrl = process.env.OLLAMA_BASE_URL || egress_js_1.DEFAULT_OLLAMA_URL;
207
+ if ((0, egress_js_1.isArkheiaHostedOrigin)(ollamaUrl, process.env.ARKHEIA_HOSTED_URL)) {
208
+ const err = "configuration_error: OLLAMA_BASE_URL is the Arkheia hosted service (or cannot be read as an address); nothing was sent. Set it to your Ollama server.";
209
+ return wrapResult({ response: "", model, error: err, arkheia: { risk_level: "UNKNOWN", error: "not_checked_ollama_address_not_usable" } });
210
+ }
202
211
  const pr = await (0, providers_js_1.call_ollama)(prompt, model);
203
212
  if (pr.error)
204
213
  return wrapResult({ ...pr, arkheia: { risk_level: "UNKNOWN", error: pr.error } });
205
- const risk = await proxy.verify(prompt, pr.response, model);
214
+ const risk = await proxy.verify(prompt, pr.response, model, undefined, { allowHosted: false });
206
215
  return wrapResult({ ...pr, arkheia: risk });
207
216
  }
208
217
  catch (e) {
package/dist/memory.js CHANGED
@@ -44,7 +44,12 @@ const path = __importStar(require("path"));
44
44
  const fs = __importStar(require("fs"));
45
45
  const crypto = __importStar(require("crypto"));
46
46
  const os = __importStar(require("os"));
47
- const logger = console;
47
+ const logger = {
48
+ // stdout carries the MCP protocol; log lines go to stderr only.
49
+ info: (m) => { process.stderr.write(`${m}\n`); },
50
+ warn: (m) => { process.stderr.write(`${m}\n`); },
51
+ error: (m) => { process.stderr.write(`${m}\n`); },
52
+ };
48
53
  // ---------------------------------------------------------------------------
49
54
  // DB setup — sql.js (pure JS, no native module)
50
55
  // ---------------------------------------------------------------------------
package/dist/providers.js CHANGED
@@ -39,7 +39,12 @@ exports.call_together = call_together;
39
39
  exports.call_ollama = call_ollama;
40
40
  const crypto = __importStar(require("crypto"));
41
41
  // Node.js native fetch doesn't have a global logger, use console
42
- const logger = console;
42
+ const logger = {
43
+ // stdout carries the MCP protocol; log lines go to stderr only.
44
+ info: (m) => { process.stderr.write(`${m}\n`); },
45
+ warn: (m) => { process.stderr.write(`${m}\n`); },
46
+ error: (m) => { process.stderr.write(`${m}\n`); },
47
+ };
43
48
  const _DEFAULT_TIMEOUT = 60 * 1000; // 60 seconds in milliseconds
44
49
  const _OLLAMA_TIMEOUT = 120 * 1000; // 120 seconds in milliseconds
45
50
  // ---------------------------------------------------------------------------
@@ -83,6 +88,7 @@ async function call_grok(prompt, model = "grok-4-fast-non-reasoning", kwargs = {
83
88
  messages: [{ role: "user", content: prompt }],
84
89
  ...kwargs,
85
90
  }),
91
+ redirect: "error", // provider keys are never re-sent to wherever a redirect points
86
92
  signal: controller.signal,
87
93
  });
88
94
  clearTimeout(timeoutId);
@@ -151,6 +157,7 @@ async function call_gemini(prompt, model = "gemini-2.5-flash", max_output_tokens
151
157
  ...kwargs,
152
158
  },
153
159
  }),
160
+ redirect: "error", // provider keys are never re-sent to wherever a redirect points
154
161
  signal: controller.signal,
155
162
  });
156
163
  clearTimeout(timeoutId);
@@ -219,6 +226,7 @@ async function call_together(prompt, model = "moonshotai/Kimi-K2.5", max_tokens
219
226
  messages: [{ role: "user", content: prompt }],
220
227
  ...kwargs,
221
228
  }),
229
+ redirect: "error", // provider keys are never re-sent to wherever a redirect points
222
230
  signal: controller.signal,
223
231
  });
224
232
  clearTimeout(timeoutId);
@@ -282,6 +290,7 @@ async function call_ollama(prompt, model = "phi4:14b", kwargs = {}) {
282
290
  stream: false,
283
291
  ...kwargs,
284
292
  }),
293
+ redirect: "error", // provider keys are never re-sent to wherever a redirect points
285
294
  signal: controller.signal,
286
295
  });
287
296
  clearTimeout(timeoutId);
@@ -2,10 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProxyClient = void 0;
4
4
  const url_1 = require("url");
5
- // Node.js native fetch doesn't have a global logger, use console
6
- const logger = console;
7
- // Hosted API defaults
8
- const HOSTED_API_URL = "https://arkheia-proxy-production.up.railway.app";
5
+ const egress_js_1 = require("./egress.js");
6
+ // Node.js native fetch doesn't have a global logger
7
+ const logger = {
8
+ // stdout carries the MCP protocol; log lines go to stderr only.
9
+ info: (m) => { process.stderr.write(`${m}\n`); },
10
+ warn: (m) => { process.stderr.write(`${m}\n`); },
11
+ error: (m) => { process.stderr.write(`${m}\n`); },
12
+ };
9
13
  class ProxyClient {
10
14
  base_url;
11
15
  timeout; // in milliseconds
@@ -16,19 +20,33 @@ class ProxyClient {
16
20
  hosted_url, api_key) {
17
21
  this.base_url = base_url.endsWith("/") ? base_url.slice(0, -1) : base_url;
18
22
  this.timeout = timeout * 1000; // Convert to milliseconds for fetch AbortController
19
- this.hosted_url = (hosted_url || HOSTED_API_URL).endsWith("/")
20
- ? (hosted_url || HOSTED_API_URL).slice(0, -1)
21
- : (hosted_url || HOSTED_API_URL);
23
+ this.hosted_url = (hosted_url || egress_js_1.HOSTED_API_URL).endsWith("/")
24
+ ? (hosted_url || egress_js_1.HOSTED_API_URL).slice(0, -1)
25
+ : (hosted_url || egress_js_1.HOSTED_API_URL);
22
26
  this.api_key = api_key || process.env.ARKHEIA_API_KEY;
23
27
  this._local_available = true; // optimistic; flips on ConnectError
24
28
  }
25
- async verify(prompt, response, model_id, session_id) {
29
+ async verify(prompt, response, model_id, session_id, options = {}) {
26
30
  /**
27
31
  * Detect fabrication in a model response.
28
32
  *
29
- * Tries local proxy first. If unavailable, falls back to hosted API.
33
+ * Tries local proxy first. If unavailable, falls back to hosted API,
34
+ * unless allowHosted is false: then nothing is sent anywhere else.
30
35
  * Never raises -- returns UNKNOWN on any error.
31
36
  */
37
+ if (options.allowHosted === false) {
38
+ // A verifier address that is (or cannot be told apart from) the hosted origin would route this path to the hosted service: refuse.
39
+ if ((0, egress_js_1.isArkheiaHostedOrigin)(this.base_url, this.hosted_url)) {
40
+ logger.warn("The verifier address is the hosted service; this response is local-only, so nothing was sent");
41
+ return _unavailable("not_checked_local_verification_unavailable");
42
+ }
43
+ const local = await this._verify_local(prompt, response, model_id, session_id);
44
+ if (local.error === "proxy_unavailable" || local.error === "proxy_timeout") {
45
+ logger.warn("Local verification unavailable; this response is local-only, so nothing was sent to the hosted service");
46
+ return _unavailable("not_checked_local_verification_unavailable");
47
+ }
48
+ return local;
49
+ }
32
50
  // Try local proxy first (if last attempt didn't fail with ConnectError)
33
51
  if (this._local_available) {
34
52
  const result = await this._verify_local(prompt, response, model_id, session_id);
@@ -74,6 +92,7 @@ class ProxyClient {
74
92
  "Content-Type": "application/json",
75
93
  },
76
94
  body: JSON.stringify(payload),
95
+ redirect: "error", // a redirect is never followed: the request goes only to the configured address
77
96
  signal: controller.signal,
78
97
  });
79
98
  clearTimeout(timeoutId);
@@ -106,7 +125,10 @@ class ProxyClient {
106
125
  response: response,
107
126
  prompt: prompt,
108
127
  };
109
- const headers = { "X-Arkheia-Key": this.api_key || "" };
128
+ const headers = {
129
+ "Content-Type": "application/json",
130
+ "X-Arkheia-Key": this.api_key || "",
131
+ };
110
132
  const controller = new AbortController();
111
133
  const timeoutId = setTimeout(() => controller.abort(), this.timeout);
112
134
  try {
@@ -114,6 +136,7 @@ class ProxyClient {
114
136
  method: "POST",
115
137
  headers: headers,
116
138
  body: JSON.stringify(payload),
139
+ redirect: "error", // the key is never re-sent to wherever a redirect points
117
140
  signal: controller.signal,
118
141
  });
119
142
  clearTimeout(timeoutId);
@@ -174,6 +197,7 @@ class ProxyClient {
174
197
  try {
175
198
  const resp = await fetch(`${this.base_url}/audit/log?${params.toString()}`, {
176
199
  method: "GET",
200
+ redirect: "error", // a redirect is never followed: the request goes only to the configured address
177
201
  signal: controller.signal,
178
202
  });
179
203
  clearTimeout(timeoutId);
@@ -47,7 +47,7 @@ exports.REGISTRY = {
47
47
  name: "run_ollama",
48
48
  permissions: [Permission.READ, Permission.EXECUTE],
49
49
  network_egress: false,
50
- description: "Call local Ollama model and screen response through Arkheia",
50
+ description: "Call local Ollama model and screen response through the local Arkheia verifier only",
51
51
  },
52
52
  memory_store: {
53
53
  name: "memory_store",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkheia/mcp-server",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Arkheia MCP Server — Fabrication detection for AI agents. Know when your AI is making things up.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "scripts": {
10
10
  "build": "tsc",
11
+ "test": "tsc && tsc -p tsconfig.test.json && node --test .test-build/test/egress.test.js .test-build/test/http.test.js .test-build/test/static.test.js .test-build/test/stdio.test.js",
11
12
  "start": "node dist/index.js",
12
13
  "prepublishOnly": "npm run build",
13
14
  "postinstall": "node scripts/setup.js"