@arkheia/mcp-server 1.2.1 → 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.
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProxyClient = void 0;
4
+ const url_1 = require("url");
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
+ };
13
+ class ProxyClient {
14
+ base_url;
15
+ timeout; // in milliseconds
16
+ hosted_url;
17
+ api_key;
18
+ _local_available; // optimistic; flips on network errors
19
+ constructor(base_url, timeout = 10.0, // in seconds
20
+ hosted_url, api_key) {
21
+ this.base_url = base_url.endsWith("/") ? base_url.slice(0, -1) : base_url;
22
+ this.timeout = timeout * 1000; // Convert to milliseconds for fetch AbortController
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);
26
+ this.api_key = api_key || process.env.ARKHEIA_API_KEY;
27
+ this._local_available = true; // optimistic; flips on ConnectError
28
+ }
29
+ async verify(prompt, response, model_id, session_id, options = {}) {
30
+ /**
31
+ * Detect fabrication in a model response.
32
+ *
33
+ * Tries local proxy first. If unavailable, falls back to hosted API,
34
+ * unless allowHosted is false: then nothing is sent anywhere else.
35
+ * Never raises -- returns UNKNOWN on any error.
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
+ }
50
+ // Try local proxy first (if last attempt didn't fail with ConnectError)
51
+ if (this._local_available) {
52
+ const result = await this._verify_local(prompt, response, model_id, session_id);
53
+ if (result.error !== "proxy_unavailable" && result.error !== "proxy_timeout") {
54
+ return result;
55
+ }
56
+ // Local proxy down -- fall through to hosted
57
+ this._local_available = false;
58
+ logger.info(`Local proxy unavailable, falling back to hosted API at ${this.hosted_url}`);
59
+ }
60
+ // Fallback: hosted API
61
+ if (this.api_key) {
62
+ const result = await this._verify_hosted(prompt, response, model_id);
63
+ if (result.error !== "hosted_unavailable") {
64
+ return result;
65
+ }
66
+ // Hosted also failed -- try local once more in case it came back
67
+ this._local_available = true; // Reset local availability for next call
68
+ }
69
+ // No hosted API key and local is down
70
+ if (!this.api_key) {
71
+ logger.warn("Local proxy unavailable and no ARKHEIA_API_KEY set for hosted fallback");
72
+ return _unavailable("no_detection_available");
73
+ }
74
+ return _unavailable("all_detection_paths_failed");
75
+ }
76
+ async _verify_local(prompt, response, model_id, session_id) {
77
+ /** POST /detect/verify on local Enterprise Proxy. */
78
+ const payload = {
79
+ prompt: prompt,
80
+ response: response,
81
+ model_id: model_id,
82
+ };
83
+ if (session_id) {
84
+ payload["session_id"] = session_id;
85
+ }
86
+ const controller = new AbortController();
87
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
88
+ try {
89
+ const resp = await fetch(`${this.base_url}/detect/verify`, {
90
+ method: "POST",
91
+ headers: {
92
+ "Content-Type": "application/json",
93
+ },
94
+ body: JSON.stringify(payload),
95
+ redirect: "error", // a redirect is never followed: the request goes only to the configured address
96
+ signal: controller.signal,
97
+ });
98
+ clearTimeout(timeoutId);
99
+ if (!resp.ok) {
100
+ logger.error(`ProxyClient: /detect/verify HTTP error: ${resp.status} ${resp.statusText}`);
101
+ return _unavailable(`proxy_http_error_${resp.status}`);
102
+ }
103
+ return await resp.json();
104
+ }
105
+ catch (e) {
106
+ clearTimeout(timeoutId);
107
+ if (e.name === 'AbortError') {
108
+ logger.warn(`ProxyClient: /detect/verify timed out for model=${model_id}`);
109
+ return _unavailable("proxy_timeout");
110
+ }
111
+ else if (e.name === 'TypeError' && e.message.includes('fetch failed')) { // Common for network errors like connection refused
112
+ logger.warn(`ProxyClient: cannot connect to proxy at ${this.base_url}`);
113
+ return _unavailable("proxy_unavailable");
114
+ }
115
+ else {
116
+ logger.error(`ProxyClient: /detect/verify unexpected error: ${e.message}`);
117
+ return _unavailable("proxy_error");
118
+ }
119
+ }
120
+ }
121
+ async _verify_hosted(prompt, response, model_id) {
122
+ /** POST /v1/detect on hosted Arkheia API (arkheia-proxy-production.up.railway.app). */
123
+ const payload = {
124
+ model: model_id,
125
+ response: response,
126
+ prompt: prompt,
127
+ };
128
+ const headers = {
129
+ "Content-Type": "application/json",
130
+ "X-Arkheia-Key": this.api_key || "",
131
+ };
132
+ const controller = new AbortController();
133
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
134
+ try {
135
+ const resp = await fetch(`${this.hosted_url}/v1/detect`, {
136
+ method: "POST",
137
+ headers: headers,
138
+ body: JSON.stringify(payload),
139
+ redirect: "error", // the key is never re-sent to wherever a redirect points
140
+ signal: controller.signal,
141
+ });
142
+ clearTimeout(timeoutId);
143
+ if (!resp.ok) {
144
+ const status = resp.status;
145
+ if (status === 401) {
146
+ logger.error("ProxyClient: hosted API rejected API key (401)");
147
+ return _unavailable("hosted_auth_failed");
148
+ }
149
+ if (status === 429) {
150
+ logger.warn("ProxyClient: hosted API rate/quota limit (429)");
151
+ return _unavailable("hosted_quota_exceeded");
152
+ }
153
+ logger.error(`ProxyClient: hosted /v1/detect HTTP error: ${status} ${resp.statusText}`);
154
+ return _unavailable(`hosted_http_error_${status}`);
155
+ }
156
+ const data = await resp.json();
157
+ // Map hosted response format to local format
158
+ return {
159
+ risk_level: data.risk || "UNKNOWN",
160
+ confidence: data.confidence || 0.0,
161
+ features_triggered: data.features_triggered || [],
162
+ detection_id: data.detection_id,
163
+ detection_method: data.detection_method,
164
+ evidence_depth_limited: data.evidence_depth_limited ?? true,
165
+ source: "hosted",
166
+ };
167
+ }
168
+ catch (e) {
169
+ clearTimeout(timeoutId);
170
+ if (e.name === 'AbortError') {
171
+ logger.warn(`ProxyClient: hosted /v1/detect timed out for model=${model_id}`);
172
+ return _unavailable("hosted_timeout");
173
+ }
174
+ else if (e.name === 'TypeError' && e.message.includes('fetch failed')) {
175
+ logger.warn(`ProxyClient: cannot connect to hosted API at ${this.hosted_url}`);
176
+ return _unavailable("hosted_unavailable");
177
+ }
178
+ else {
179
+ logger.error(`ProxyClient: hosted /v1/detect unexpected error: ${e.message}`);
180
+ return _unavailable("hosted_error");
181
+ }
182
+ }
183
+ }
184
+ async get_audit_log(session_id, limit = 50) {
185
+ /**
186
+ * GET /audit/log
187
+ *
188
+ * Returns audit log dict. Never raises -- returns empty log on any error.
189
+ * Note: audit log is only available from local proxy, not hosted API.
190
+ */
191
+ const params = new url_1.URLSearchParams({ limit: String(Math.min(limit, 500)) });
192
+ if (session_id) {
193
+ params.append("session_id", session_id);
194
+ }
195
+ const controller = new AbortController();
196
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
197
+ try {
198
+ const resp = await fetch(`${this.base_url}/audit/log?${params.toString()}`, {
199
+ method: "GET",
200
+ redirect: "error", // a redirect is never followed: the request goes only to the configured address
201
+ signal: controller.signal,
202
+ });
203
+ clearTimeout(timeoutId);
204
+ if (!resp.ok) {
205
+ logger.error(`ProxyClient: /audit/log HTTP error: ${resp.status} ${resp.statusText}`);
206
+ return _empty_log(`proxy_http_error_${resp.status}`);
207
+ }
208
+ return await resp.json();
209
+ }
210
+ catch (e) {
211
+ clearTimeout(timeoutId);
212
+ if (e.name === 'AbortError') {
213
+ logger.warn("ProxyClient: /audit/log timed out");
214
+ return _empty_log("proxy_timeout");
215
+ }
216
+ else if (e.name === 'TypeError' && e.message.includes('fetch failed')) {
217
+ logger.warn(`ProxyClient: cannot connect to proxy at ${this.base_url}`);
218
+ return _empty_log("proxy_unavailable");
219
+ }
220
+ else {
221
+ logger.error(`ProxyClient: /audit/log unexpected error: ${e.message}`);
222
+ return _empty_log("proxy_error");
223
+ }
224
+ }
225
+ }
226
+ }
227
+ exports.ProxyClient = ProxyClient;
228
+ function _unavailable(error) {
229
+ /** Standard UNKNOWN response when detection is unreachable. */
230
+ return {
231
+ risk_level: "UNKNOWN",
232
+ confidence: 0.0,
233
+ features_triggered: [],
234
+ error: error,
235
+ };
236
+ }
237
+ function _empty_log(error) {
238
+ return {
239
+ events: [],
240
+ summary: { LOW: 0, MEDIUM: 0, HIGH: 0, UNKNOWN: 0 },
241
+ error: error,
242
+ };
243
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolicyViolation = exports.REGISTRY = exports.Permission = void 0;
4
+ exports.check = check;
5
+ var Permission;
6
+ (function (Permission) {
7
+ Permission["READ"] = "read";
8
+ Permission["EXECUTE"] = "execute";
9
+ Permission["WRITE"] = "write";
10
+ Permission["DEPLOY"] = "deploy";
11
+ })(Permission || (exports.Permission = Permission = {}));
12
+ // ---------------------------------------------------------------------------
13
+ // The allowlist
14
+ // ---------------------------------------------------------------------------
15
+ exports.REGISTRY = {
16
+ arkheia_verify: {
17
+ name: "arkheia_verify",
18
+ permissions: [Permission.READ],
19
+ network_egress: true,
20
+ description: "Screen an AI response for fabrication risk",
21
+ },
22
+ arkheia_audit_log: {
23
+ name: "arkheia_audit_log",
24
+ permissions: [Permission.READ],
25
+ network_egress: false,
26
+ description: "Retrieve structured audit evidence",
27
+ },
28
+ run_grok: {
29
+ name: "run_grok",
30
+ permissions: [Permission.READ, Permission.EXECUTE],
31
+ network_egress: true,
32
+ description: "Call xAI Grok API and screen response through Arkheia",
33
+ },
34
+ run_gemini: {
35
+ name: "run_gemini",
36
+ permissions: [Permission.READ, Permission.EXECUTE],
37
+ network_egress: true,
38
+ description: "Call Google Gemini API and screen response through Arkheia",
39
+ },
40
+ run_together: {
41
+ name: "run_together",
42
+ permissions: [Permission.READ, Permission.EXECUTE],
43
+ network_egress: true,
44
+ description: "Call Together AI API and screen response through Arkheia",
45
+ },
46
+ run_ollama: {
47
+ name: "run_ollama",
48
+ permissions: [Permission.READ, Permission.EXECUTE],
49
+ network_egress: false,
50
+ description: "Call local Ollama model and screen response through the local Arkheia verifier only",
51
+ },
52
+ memory_store: {
53
+ name: "memory_store",
54
+ permissions: [Permission.READ, Permission.WRITE],
55
+ network_egress: false,
56
+ description: "Store an entity and observations in the persistent knowledge graph",
57
+ },
58
+ memory_retrieve: {
59
+ name: "memory_retrieve",
60
+ permissions: [Permission.READ],
61
+ network_egress: false,
62
+ description: "Retrieve entities and their observations from the knowledge graph",
63
+ },
64
+ memory_relate: {
65
+ name: "memory_relate",
66
+ permissions: [Permission.READ, Permission.WRITE],
67
+ network_egress: false,
68
+ description: "Store a named relationship between two entities in the knowledge graph",
69
+ },
70
+ };
71
+ // ---------------------------------------------------------------------------
72
+ // Policy gate
73
+ // ---------------------------------------------------------------------------
74
+ class PolicyViolation extends Error {
75
+ tool_name;
76
+ reason;
77
+ constructor(tool_name, reason) {
78
+ super(`Policy violation for '${tool_name}': ${reason}`);
79
+ this.tool_name = tool_name;
80
+ this.reason = reason;
81
+ }
82
+ }
83
+ exports.PolicyViolation = PolicyViolation;
84
+ function check(tool_name) {
85
+ const policy = exports.REGISTRY[tool_name];
86
+ if (!policy) {
87
+ throw new PolicyViolation(tool_name, `not in allowlist — default deny. Known tools: ${Object.keys(exports.REGISTRY).sort().join(", ")}`);
88
+ }
89
+ return policy;
90
+ }
package/package.json CHANGED
@@ -1,44 +1,45 @@
1
1
  {
2
2
  "name": "@arkheia/mcp-server",
3
- "version": "1.2.1",
4
- "mcpName": "io.github.arkheiaai/mcp-server",
5
- "description": "Arkheia MCP Server — Fabrication detection for LLM outputs. Detect hallucination in any model's output with a single tool call.",
3
+ "version": "1.2.4",
4
+ "description": "Arkheia MCP Server — Fabrication detection for AI agents. Know when your AI is making things up.",
5
+ "main": "dist/index.js",
6
6
  "bin": {
7
- "mcp-server": "bin/arkheia-mcp.js"
7
+ "mcp-server": "dist/index.js"
8
8
  },
9
9
  "scripts": {
10
- "start": "node bin/arkheia-mcp.js",
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",
12
+ "start": "node dist/index.js",
13
+ "prepublishOnly": "npm run build",
11
14
  "postinstall": "node scripts/setup.js"
12
15
  },
16
+ "files": [
17
+ "dist/",
18
+ "scripts/",
19
+ "README.md",
20
+ "CLAUDE_MD_TEMPLATE.md"
21
+ ],
13
22
  "keywords": [
14
23
  "mcp",
15
24
  "ai",
16
25
  "fabrication",
17
- "hallucination",
18
26
  "detection",
19
- "llm",
20
- "claude",
21
- "gpt",
22
- "gemini",
23
- "governance",
24
- "audit",
25
- "grounding",
26
- "verification"
27
+ "hallucination",
28
+ "governance"
27
29
  ],
28
- "author": "Arkheia AI <support@arkheia.ai>",
30
+ "author": "Arkheia AI <dmurfet@arkheia.ai>",
29
31
  "license": "MIT",
30
- "homepage": "https://arkheia.ai/mcp",
31
- "repository": {
32
- "type": "git",
33
- "url": "git+https://github.com/arkheiaai/arkheia-mcp.git"
34
- },
35
32
  "engines": {
36
33
  "node": ">=18.0.0"
37
34
  },
38
- "files": [
39
- "bin/",
40
- "scripts/",
41
- "python/",
42
- "README.md"
43
- ]
35
+ "dependencies": {
36
+ "@modelcontextprotocol/sdk": "^1.12.0",
37
+ "sql.js": "^1.11.0",
38
+ "zod": "^3.23.8"
39
+ },
40
+ "devDependencies": {
41
+ "@types/sql.js": "^1.4.9",
42
+ "@types/node": "^20.14.10",
43
+ "typescript": "^5.5.3"
44
+ }
44
45
  }
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Installs the Arkheia detection protocol into AI CLI instruction files
4
+ * and registers the MCP server with each detected CLI.
5
+ *
6
+ * Usage:
7
+ * npx @arkheia/mcp-server --setup
8
+ * node scripts/setup-claude.js
9
+ *
10
+ * What it does:
11
+ * 1. Detects which AI CLIs are installed (claude, codex, gemini, grok)
12
+ * 2. Appends detection protocol to instruction files that need it:
13
+ * - Claude Code: ~/.claude/CLAUDE.md
14
+ * - Codex: ~/.codex/CODEX.md
15
+ * - Gemini: not needed (reads protocol from tool descriptions)
16
+ * - Grok: not needed (no instruction file mechanism)
17
+ * 3. Registers the MCP server with each detected CLI
18
+ */
19
+
20
+ const fs = require("fs");
21
+ const path = require("path");
22
+ const os = require("os");
23
+ const { execSync, execFileSync } = require("child_process");
24
+
25
+ const MARKER = "# Arkheia Integration — Detection Protocol";
26
+
27
+ const PROTOCOL = `
28
+ # Arkheia Integration — Detection Protocol
29
+
30
+ When Arkheia MCP tools are available in this session, follow this protocol.
31
+
32
+ ## Fabrication Detection
33
+
34
+ Call \`arkheia_verify\` on EVERY model response before surfacing it to the user. Do not skip responses that appear obviously correct.
35
+
36
+ ## Risk Escalation
37
+
38
+ - **HIGH risk**: Warn the user that the response may be fabricated. Include the \`detection_id\`. Still show the response — never hide or suppress it. Ask the user if they want to verify with a different model.
39
+ - **MEDIUM risk**: Show the response with a brief confidence note.
40
+ - **LOW risk**: Show normally.
41
+ - **UNKNOWN risk**: Flag for human review. Include the \`detection_id\`.
42
+
43
+ ## Cross-Model Verification
44
+
45
+ When HIGH or UNKNOWN risk is detected, offer to verify using: \`run_grok\`, \`run_gemini\`, \`run_ollama\`, \`run_together\`.
46
+
47
+ ## Audit Trail
48
+
49
+ Use \`arkheia_audit_log\` when the user asks about detection history or for compliance evidence.
50
+
51
+ ## Persistent Knowledge Graph
52
+
53
+ Use \`memory_store\` to persist facts, \`memory_retrieve\` to recall them, \`memory_relate\` to track relationships between entities.
54
+
55
+ ## Key Rules
56
+
57
+ 1. Never hide a response from the user regardless of risk level
58
+ 2. Always include the \`detection_id\` when reporting HIGH or UNKNOWN risk
59
+ 3. Call \`arkheia_verify\` proactively — do not wait for the user to ask
60
+ 4. Audit logging happens automatically through \`arkheia_verify\`
61
+ `;
62
+
63
+ function cmdExists(cmd) {
64
+ try {
65
+ execSync(process.platform === "win32" ? `where ${cmd}` : `which ${cmd}`, { stdio: "pipe" });
66
+ return true;
67
+ } catch { return false; }
68
+ }
69
+
70
+ function installProtocol(filePath, cliName) {
71
+ const dir = path.dirname(filePath);
72
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
73
+
74
+ if (fs.existsSync(filePath)) {
75
+ const existing = fs.readFileSync(filePath, "utf8");
76
+ if (existing.includes(MARKER)) {
77
+ console.log(` [${cliName}] Detection protocol already installed in ${filePath}`);
78
+ return;
79
+ }
80
+ fs.appendFileSync(filePath, "\n" + PROTOCOL);
81
+ console.log(` [${cliName}] Detection protocol appended to ${filePath}`);
82
+ } else {
83
+ fs.writeFileSync(filePath, PROTOCOL.trim() + "\n");
84
+ console.log(` [${cliName}] Detection protocol written to ${filePath}`);
85
+ }
86
+ }
87
+
88
+ // argv carries the real key for the CLI's own config; `display` is the same command with the key shown only as
89
+ // "$ARKHEIA_API_KEY", which is all that is ever printed (Codex B288 R1: a failure used to echo the full key).
90
+ function registerMcp(cli, argv, display) {
91
+ try {
92
+ execFileSync(argv[0], argv.slice(1), { stdio: "inherit", timeout: 15000 });
93
+ console.log(` [${cli}] MCP server registered`);
94
+ } catch {
95
+ console.log(` [${cli}] Auto-registration failed — run manually:`);
96
+ console.log(` ${display}`);
97
+ }
98
+ }
99
+
100
+ function main() {
101
+ const apiKey = process.env.ARKHEIA_API_KEY || "";
102
+ const home = os.homedir();
103
+ const detected = [];
104
+
105
+ console.log("\n[arkheia] Setting up detection protocol for installed AI CLIs...\n");
106
+
107
+ // ── Claude Code ──────────────────────────────────────────────
108
+ if (cmdExists("claude")) {
109
+ detected.push("claude");
110
+ console.log("[claude] Detected");
111
+ installProtocol(path.join(home, ".claude", "CLAUDE.md"), "claude");
112
+ if (apiKey) {
113
+ registerMcp("claude", ["claude", "mcp", "add", "arkheia", "-s", "user", "-e", `ARKHEIA_API_KEY=${apiKey}`, "--", "mcp-server"],
114
+ 'claude mcp add arkheia -s user -e ARKHEIA_API_KEY="$ARKHEIA_API_KEY" -- mcp-server');
115
+ } else {
116
+ console.log(' [claude] Set ARKHEIA_API_KEY then run: claude mcp add arkheia -s user -e ARKHEIA_API_KEY="$ARKHEIA_API_KEY" -- mcp-server');
117
+ }
118
+ }
119
+
120
+ // ── Codex ────────────────────────────────────────────────────
121
+ if (cmdExists("codex")) {
122
+ detected.push("codex");
123
+ console.log("[codex] Detected");
124
+ installProtocol(path.join(home, ".codex", "CODEX.md"), "codex");
125
+ if (apiKey) {
126
+ registerMcp("codex", ["codex", "mcp", "add", "arkheia", "--env", `ARKHEIA_API_KEY=${apiKey}`, "--", "mcp-server"],
127
+ 'codex mcp add arkheia --env ARKHEIA_API_KEY="$ARKHEIA_API_KEY" -- mcp-server');
128
+ } else {
129
+ console.log(' [codex] Set ARKHEIA_API_KEY then run: codex mcp add arkheia --env ARKHEIA_API_KEY="$ARKHEIA_API_KEY" -- mcp-server');
130
+ }
131
+ }
132
+
133
+ // ── Gemini ───────────────────────────────────────────────────
134
+ // Gemini reads the detection protocol directly from tool descriptions.
135
+ // No instruction file needed — just register the MCP server.
136
+ if (cmdExists("gemini")) {
137
+ detected.push("gemini");
138
+ console.log("[gemini] Detected (no instruction file needed — reads protocol from tool descriptions)");
139
+ if (apiKey) {
140
+ registerMcp("gemini", ["gemini", "mcp", "add", "-s", "user", "-e", `ARKHEIA_API_KEY=${apiKey}`, "arkheia", "mcp-server"],
141
+ 'gemini mcp add -s user -e ARKHEIA_API_KEY="$ARKHEIA_API_KEY" arkheia mcp-server');
142
+ } else {
143
+ console.log(' [gemini] Set ARKHEIA_API_KEY then run: gemini mcp add -s user -e ARKHEIA_API_KEY="$ARKHEIA_API_KEY" arkheia mcp-server');
144
+ }
145
+ }
146
+
147
+ // ── Grok ─────────────────────────────────────────────────────
148
+ // No instruction file mechanism. Register MCP server only.
149
+ if (cmdExists("grok")) {
150
+ detected.push("grok");
151
+ console.log("[grok] Detected (no instruction file mechanism)");
152
+ if (apiKey) {
153
+ registerMcp("grok", ["grok", "mcp", "add", "arkheia", "-t", "stdio", "-c", "mcp-server", "-e", `ARKHEIA_API_KEY=${apiKey}`],
154
+ 'grok mcp add arkheia -t stdio -c mcp-server -e ARKHEIA_API_KEY="$ARKHEIA_API_KEY"');
155
+ } else {
156
+ console.log(' [grok] Set ARKHEIA_API_KEY then run: grok mcp add arkheia -t stdio -c mcp-server -e ARKHEIA_API_KEY="$ARKHEIA_API_KEY"');
157
+ }
158
+ }
159
+
160
+ if (detected.length === 0) {
161
+ console.log("No AI CLIs detected on PATH (claude, codex, gemini, grok).");
162
+ console.log("Install one and re-run: npx @arkheia/mcp-server --setup");
163
+ } else {
164
+ console.log(`\n[arkheia] Setup complete for: ${detected.join(", ")}`);
165
+ console.log("[arkheia] Restart each CLI to activate Arkheia detection.\n");
166
+ }
167
+ }
168
+
169
+ main();