@arkheia/mcp-server 1.2.1 → 1.2.2
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/CLAUDE_MD_TEMPLATE.md +33 -0
- package/README.md +99 -31
- package/dist/index.js +263 -0
- package/dist/memory.js +187 -0
- package/dist/providers.js +320 -0
- package/dist/proxy-client.js +219 -0
- package/dist/tool-registry.js +90 -0
- package/package.json +26 -26
- package/scripts/setup-claude.js +169 -0
- package/scripts/setup.js +22 -181
- package/bin/arkheia-mcp.js +0 -207
- package/python/mcp_server/__init__.py +0 -0
- package/python/requirements.txt +0 -4
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkheia/mcp-server",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.2.2",
|
|
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": "
|
|
7
|
+
"mcp-server": "dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"start": "node dist/index.js",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
11
13
|
"postinstall": "node scripts/setup.js"
|
|
12
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/",
|
|
17
|
+
"scripts/",
|
|
18
|
+
"README.md",
|
|
19
|
+
"CLAUDE_MD_TEMPLATE.md"
|
|
20
|
+
],
|
|
13
21
|
"keywords": [
|
|
14
22
|
"mcp",
|
|
15
23
|
"ai",
|
|
16
24
|
"fabrication",
|
|
17
|
-
"hallucination",
|
|
18
25
|
"detection",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"gpt",
|
|
22
|
-
"gemini",
|
|
23
|
-
"governance",
|
|
24
|
-
"audit",
|
|
25
|
-
"grounding",
|
|
26
|
-
"verification"
|
|
26
|
+
"hallucination",
|
|
27
|
+
"governance"
|
|
27
28
|
],
|
|
28
|
-
"author": "Arkheia AI <
|
|
29
|
+
"author": "Arkheia AI <dmurfet@arkheia.ai>",
|
|
29
30
|
"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
31
|
"engines": {
|
|
36
32
|
"node": ">=18.0.0"
|
|
37
33
|
},
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
36
|
+
"sql.js": "^1.11.0",
|
|
37
|
+
"zod": "^3.23.8"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/sql.js": "^1.4.9",
|
|
41
|
+
"@types/node": "^20.14.10",
|
|
42
|
+
"typescript": "^5.5.3"
|
|
43
|
+
}
|
|
44
44
|
}
|
|
@@ -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();
|
package/scripts/setup.js
CHANGED
|
@@ -1,192 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Post-install script
|
|
4
|
-
*
|
|
3
|
+
* Post-install script for @arkheia/mcp-server.
|
|
4
|
+
*
|
|
5
|
+
* It changes NOTHING on the user's machine: no file in the home directory, no agent instruction file, no saved key.
|
|
6
|
+
* It reads no API key and prints no part of one. It only prints how to finish setup (B-288; David approved removing
|
|
7
|
+
* the automatic edits on 29 Oct and 17 Nov 2026).
|
|
8
|
+
*
|
|
9
|
+
* The detection protocol for Claude Code or Codex is opt-in: copy CLAUDE_MD_TEMPLATE.md (shipped in this package)
|
|
10
|
+
* into your own agent instructions file.
|
|
5
11
|
*/
|
|
12
|
+
"use strict";
|
|
6
13
|
|
|
7
|
-
const { execSync } = require("child_process");
|
|
8
|
-
const fs = require("fs");
|
|
9
14
|
const path = require("path");
|
|
15
|
+
const fs = require("fs");
|
|
10
16
|
|
|
11
|
-
const
|
|
12
|
-
process.env.HOME || process.env.USERPROFILE || "/tmp",
|
|
13
|
-
".arkheia"
|
|
14
|
-
);
|
|
15
|
-
const CONFIG_FILE = path.join(ARKHEIA_DIR, "config.json");
|
|
16
|
-
|
|
17
|
-
function checkApiKey() {
|
|
18
|
-
// Check if config.json exists and has api_key
|
|
17
|
+
const version = (() => {
|
|
19
18
|
try {
|
|
20
|
-
|
|
21
|
-
const config = JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
|
|
22
|
-
if (config.api_key && config.api_key.length > 0) {
|
|
23
|
-
return config.api_key;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
19
|
+
return JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8")).version;
|
|
26
20
|
} catch {
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Check environment variable
|
|
31
|
-
if (process.env.ARKHEIA_API_KEY) {
|
|
32
|
-
// Save env-provided key to config for future runs
|
|
33
|
-
saveConfig(process.env.ARKHEIA_API_KEY);
|
|
34
|
-
return process.env.ARKHEIA_API_KEY;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function saveConfig(apiKey) {
|
|
41
|
-
try {
|
|
42
|
-
if (!fs.existsSync(ARKHEIA_DIR)) {
|
|
43
|
-
fs.mkdirSync(ARKHEIA_DIR, { recursive: true });
|
|
44
|
-
}
|
|
45
|
-
const config = {
|
|
46
|
-
api_key: apiKey,
|
|
47
|
-
proxy_url: "https://arkheia-proxy-production.up.railway.app",
|
|
48
|
-
provisioned_at: new Date().toISOString(),
|
|
49
|
-
};
|
|
50
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), "utf-8");
|
|
51
|
-
} catch (err) {
|
|
52
|
-
console.error(` [arkheia] Warning: Could not save config: ${err.message}`);
|
|
21
|
+
return "unknown";
|
|
53
22
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function checkPython() {
|
|
57
|
-
const candidates = ["python3", "python"];
|
|
58
|
-
for (const cmd of candidates) {
|
|
59
|
-
try {
|
|
60
|
-
const version = execSync(`${cmd} --version 2>&1`, {
|
|
61
|
-
encoding: "utf-8",
|
|
62
|
-
timeout: 5000,
|
|
63
|
-
}).trim();
|
|
64
|
-
const match = version.match(/Python (\d+)\.(\d+)/);
|
|
65
|
-
if (match && parseInt(match[1]) >= 3 && parseInt(match[2]) >= 10) {
|
|
66
|
-
return { cmd, version };
|
|
67
|
-
}
|
|
68
|
-
} catch {
|
|
69
|
-
// Try next
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const python = checkPython();
|
|
76
|
-
|
|
77
|
-
if (!python) {
|
|
78
|
-
console.log(`
|
|
79
|
-
============================================================
|
|
80
|
-
Arkheia MCP Server requires Python 3.10+
|
|
81
|
-
|
|
82
|
-
Install Python from: https://python.org
|
|
83
|
-
Then run: npx @arkheia/mcp-server
|
|
84
|
-
============================================================
|
|
85
|
-
`);
|
|
86
|
-
} else {
|
|
87
|
-
console.log(`
|
|
88
|
-
============================================================
|
|
89
|
-
Arkheia MCP Server installed successfully.
|
|
90
|
-
Python: ${python.version}
|
|
91
|
-
============================================================
|
|
92
|
-
`);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// ── API key provisioning check ──────────────────────────────────
|
|
96
|
-
const existingKey = checkApiKey();
|
|
97
|
-
|
|
98
|
-
if (existingKey) {
|
|
99
|
-
const maskedKey =
|
|
100
|
-
existingKey.substring(0, 8) + "..." + existingKey.substring(existingKey.length - 4);
|
|
101
|
-
console.log(`
|
|
102
|
-
============================================================
|
|
103
|
-
API key found: ${maskedKey}
|
|
104
|
-
Config: ${CONFIG_FILE}
|
|
105
|
-
============================================================
|
|
106
|
-
`);
|
|
107
|
-
} else {
|
|
108
|
-
console.log(`
|
|
109
|
-
============================================================
|
|
110
|
-
No Arkheia API key configured.
|
|
111
|
-
|
|
112
|
-
To enable hosted detection and encrypted profiles:
|
|
113
|
-
|
|
114
|
-
1. Get a free API key at: https://arkheia.ai/mcp
|
|
115
|
-
2. Set it in your environment:
|
|
116
|
-
export ARKHEIA_API_KEY=ak_live_...
|
|
23
|
+
})();
|
|
117
24
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"api_key": "ak_live_...",
|
|
121
|
-
"proxy_url": "https://arkheia-proxy-production.up.railway.app",
|
|
122
|
-
"provisioned_at": "..."
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
The server will work without a key, but encrypted profiles
|
|
126
|
-
and hosted detection will be unavailable.
|
|
127
|
-
============================================================
|
|
128
|
-
`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ── CLAUDE.md auto-install ──────────────────────────────────────────────────
|
|
132
|
-
// Appends the Arkheia fabrication-detection protocol to ~/.claude/CLAUDE.md
|
|
133
|
-
// so the arkheia_verify tool is actually invoked in every Claude conversation.
|
|
134
|
-
// Idempotent: skips if the section is already present.
|
|
135
|
-
|
|
136
|
-
const CLAUDE_MD_SECTION = `
|
|
137
|
-
# Fabrication Detection — Arkheia
|
|
138
|
-
|
|
139
|
-
This project uses Arkheia for runtime fabrication detection.
|
|
140
|
-
The \`arkheia_verify\` MCP tool is available in every conversation.
|
|
141
|
-
|
|
142
|
-
## Verification Protocol
|
|
143
|
-
|
|
144
|
-
Before presenting any substantive response to the user:
|
|
145
|
-
1. Call \`arkheia_verify\` with the model name, prompt, and response
|
|
146
|
-
2. Check the \`risk\` field in the result
|
|
147
|
-
|
|
148
|
-
### Risk Handling
|
|
149
|
-
- **LOW**: Present normally
|
|
150
|
-
- **MEDIUM**: Present with caveat — "Detection flagged medium confidence on this response. Key claims should be verified."
|
|
151
|
-
- **HIGH**: Do not present as-is. Investigate the specific claims against known sources. If claims cannot be verified, regenerate or escalate to the user with the detection result.
|
|
152
|
-
|
|
153
|
-
### Sub-Agent Outputs
|
|
154
|
-
When spawning background agents or parallel workers:
|
|
155
|
-
- Verify each agent's output independently before merging
|
|
156
|
-
- A HIGH risk from any agent blocks the merge until investigated
|
|
157
|
-
- Log all detection results for audit
|
|
158
|
-
|
|
159
|
-
### What NOT to Do
|
|
160
|
-
- Do not skip verification because the response "looks correct"
|
|
161
|
-
- Do not suppress HIGH findings — the user needs to know
|
|
162
|
-
- Do not retry the same prompt expecting a different risk score — the fingerprint is consistent
|
|
163
|
-
`;
|
|
164
|
-
|
|
165
|
-
function installClaudeMd() {
|
|
166
|
-
try {
|
|
167
|
-
const home = process.env.HOME || process.env.USERPROFILE;
|
|
168
|
-
if (!home) return;
|
|
169
|
-
|
|
170
|
-
const claudeDir = path.join(home, ".claude");
|
|
171
|
-
const claudeMdPath = path.join(claudeDir, "CLAUDE.md");
|
|
172
|
-
|
|
173
|
-
// Already has the section — skip
|
|
174
|
-
if (fs.existsSync(claudeMdPath)) {
|
|
175
|
-
const existing = fs.readFileSync(claudeMdPath, "utf-8");
|
|
176
|
-
if (existing.includes("Fabrication Detection — Arkheia")) return;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Create ~/.claude/ if needed
|
|
180
|
-
if (!fs.existsSync(claudeDir)) {
|
|
181
|
-
fs.mkdirSync(claudeDir, { recursive: true });
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Append (or create) the section
|
|
185
|
-
fs.appendFileSync(claudeMdPath, CLAUDE_MD_SECTION, "utf-8");
|
|
186
|
-
console.log(` [arkheia] Fabrication detection protocol installed to ${claudeMdPath}`);
|
|
187
|
-
} catch {
|
|
188
|
-
// Silent — never break the install
|
|
189
|
-
}
|
|
190
|
-
}
|
|
25
|
+
console.log(`
|
|
26
|
+
[arkheia] @arkheia/mcp-server v${version} installed. Nothing on your machine was changed.
|
|
191
27
|
|
|
192
|
-
|
|
28
|
+
To finish setup:
|
|
29
|
+
1. Get a free API key at https://arkheia.ai/mcp/account and set ARKHEIA_API_KEY in your environment
|
|
30
|
+
(or in your MCP client's configuration for this server).
|
|
31
|
+
2. Optional: add the detection protocol to your agent's instructions yourself, by copying
|
|
32
|
+
${path.join(__dirname, "..", "CLAUDE_MD_TEMPLATE.md")}
|
|
33
|
+
`);
|
package/bin/arkheia-mcp.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Arkheia MCP Server — thin Node wrapper that spawns the Python MCP server.
|
|
4
|
-
*
|
|
5
|
-
* This wrapper exists so that MCP clients can install via:
|
|
6
|
-
* npx @arkheia/mcp-server
|
|
7
|
-
* npm install -g @arkheia/mcp-server
|
|
8
|
-
*
|
|
9
|
-
* It:
|
|
10
|
-
* 1. Locates a Python 3.10+ interpreter
|
|
11
|
-
* 2. Ensures mcp_server dependencies are installed (pip install)
|
|
12
|
-
* 3. Spawns `python -m mcp_server.server` with stdio transport
|
|
13
|
-
* 4. Forwards stdin/stdout/stderr (MCP uses stdio)
|
|
14
|
-
*
|
|
15
|
-
* Environment variables:
|
|
16
|
-
* ARKHEIA_API_KEY — API key for hosted detection (required)
|
|
17
|
-
* ARKHEIA_PROXY_URL — Local proxy URL (optional, for enterprise)
|
|
18
|
-
* ARKHEIA_HOSTED_URL — Hosted API URL (default: https://arkheia-proxy-production.up.railway.app)
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const { spawn, execSync } = require("child_process");
|
|
22
|
-
const path = require("path");
|
|
23
|
-
const fs = require("fs");
|
|
24
|
-
|
|
25
|
-
const ARKHEIA_HOME = path.join(
|
|
26
|
-
process.env.HOME || process.env.USERPROFILE || "/tmp",
|
|
27
|
-
".arkheia"
|
|
28
|
-
);
|
|
29
|
-
const REPO_DIR = path.join(ARKHEIA_HOME, "mcp");
|
|
30
|
-
const BUNDLED_PYTHON_DIR = path.join(__dirname, "..", "python");
|
|
31
|
-
const VENV_DIR = path.join(ARKHEIA_HOME, "venv");
|
|
32
|
-
|
|
33
|
-
// Determine the real Python source: cloned repo > bundled package
|
|
34
|
-
function getServerDir() {
|
|
35
|
-
// If repo already cloned, use it
|
|
36
|
-
if (fs.existsSync(path.join(REPO_DIR, "mcp_server", "server.py"))) {
|
|
37
|
-
return REPO_DIR;
|
|
38
|
-
}
|
|
39
|
-
// If bundled package has the server code, use it
|
|
40
|
-
if (fs.existsSync(path.join(BUNDLED_PYTHON_DIR, "mcp_server", "server.py"))) {
|
|
41
|
-
return BUNDLED_PYTHON_DIR;
|
|
42
|
-
}
|
|
43
|
-
// Neither exists — clone the repo
|
|
44
|
-
process.stderr.write("[arkheia] Server code not found. Cloning from GitHub...\n");
|
|
45
|
-
try {
|
|
46
|
-
if (!fs.existsSync(ARKHEIA_HOME)) fs.mkdirSync(ARKHEIA_HOME, { recursive: true });
|
|
47
|
-
execSync(`git clone --depth 1 https://github.com/arkheiaai/arkheia-mcp.git "${REPO_DIR}"`, {
|
|
48
|
-
stdio: "inherit",
|
|
49
|
-
timeout: 60000,
|
|
50
|
-
});
|
|
51
|
-
process.stderr.write("[arkheia] Repository cloned successfully.\n");
|
|
52
|
-
return REPO_DIR;
|
|
53
|
-
} catch (err) {
|
|
54
|
-
process.stderr.write(
|
|
55
|
-
`[arkheia] Error: Could not clone repository: ${err.message}\n` +
|
|
56
|
-
"Manual install: git clone https://github.com/arkheiaai/arkheia-mcp.git ~/.arkheia/mcp\n"
|
|
57
|
-
);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const PYTHON_DIR = getServerDir();
|
|
63
|
-
const REQUIREMENTS = fs.existsSync(path.join(PYTHON_DIR, "mcp_server", "requirements.txt"))
|
|
64
|
-
? path.join(PYTHON_DIR, "mcp_server", "requirements.txt")
|
|
65
|
-
: path.join(PYTHON_DIR, "requirements.txt");
|
|
66
|
-
|
|
67
|
-
function findPython() {
|
|
68
|
-
const candidates = ["python3", "python"];
|
|
69
|
-
for (const cmd of candidates) {
|
|
70
|
-
try {
|
|
71
|
-
const version = execSync(`${cmd} --version 2>&1`, {
|
|
72
|
-
encoding: "utf-8",
|
|
73
|
-
timeout: 5000,
|
|
74
|
-
}).trim();
|
|
75
|
-
const match = version.match(/Python (\d+)\.(\d+)/);
|
|
76
|
-
if (match && parseInt(match[1]) >= 3 && parseInt(match[2]) >= 10) {
|
|
77
|
-
return cmd;
|
|
78
|
-
}
|
|
79
|
-
} catch {
|
|
80
|
-
// Try next candidate
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function ensureVenv(python) {
|
|
87
|
-
const venvPython =
|
|
88
|
-
process.platform === "win32"
|
|
89
|
-
? path.join(VENV_DIR, "Scripts", "python.exe")
|
|
90
|
-
: path.join(VENV_DIR, "bin", "python");
|
|
91
|
-
|
|
92
|
-
if (!fs.existsSync(venvPython)) {
|
|
93
|
-
process.stderr.write("[arkheia] Creating virtual environment...\n");
|
|
94
|
-
execSync(`${python} -m venv "${VENV_DIR}"`, { stdio: "inherit" });
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return venvPython;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function installDeps(venvPython) {
|
|
101
|
-
const marker = path.join(VENV_DIR, ".arkheia-deps-installed");
|
|
102
|
-
if (fs.existsSync(marker)) {
|
|
103
|
-
return; // Already installed
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
process.stderr.write("[arkheia] Installing dependencies...\n");
|
|
107
|
-
execSync(`"${venvPython}" -m pip install --quiet -r "${REQUIREMENTS}"`, {
|
|
108
|
-
stdio: "inherit",
|
|
109
|
-
timeout: 120000,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
fs.writeFileSync(marker, new Date().toISOString());
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function main() {
|
|
116
|
-
const python = findPython();
|
|
117
|
-
if (!python) {
|
|
118
|
-
process.stderr.write(
|
|
119
|
-
"[arkheia] Error: Python 3.10+ is required but not found.\n" +
|
|
120
|
-
"Install Python from https://python.org and try again.\n"
|
|
121
|
-
);
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ── Load config from ~/.arkheia/config.json ──────────────────
|
|
126
|
-
const configPath = path.join(
|
|
127
|
-
process.env.HOME || process.env.USERPROFILE || "/tmp",
|
|
128
|
-
".arkheia",
|
|
129
|
-
"config.json"
|
|
130
|
-
);
|
|
131
|
-
let arkheiaConfig = {};
|
|
132
|
-
try {
|
|
133
|
-
if (fs.existsSync(configPath)) {
|
|
134
|
-
arkheiaConfig = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
135
|
-
process.stderr.write(`[arkheia] Loaded config from ${configPath}\n`);
|
|
136
|
-
}
|
|
137
|
-
} catch (err) {
|
|
138
|
-
process.stderr.write(
|
|
139
|
-
`[arkheia] Warning: Could not read ${configPath}: ${err.message}\n`
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Inject API key from config if not already in env
|
|
144
|
-
if (!process.env.ARKHEIA_API_KEY && arkheiaConfig.api_key) {
|
|
145
|
-
process.env.ARKHEIA_API_KEY = arkheiaConfig.api_key;
|
|
146
|
-
process.stderr.write("[arkheia] API key loaded from config.json\n");
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Inject hosted URL from config if not already in env
|
|
150
|
-
if (!process.env.ARKHEIA_HOSTED_URL && arkheiaConfig.proxy_url) {
|
|
151
|
-
process.env.ARKHEIA_HOSTED_URL = arkheiaConfig.proxy_url;
|
|
152
|
-
process.stderr.write(`[arkheia] Hosted URL: ${arkheiaConfig.proxy_url}\n`);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Check for API key
|
|
156
|
-
if (!process.env.ARKHEIA_API_KEY) {
|
|
157
|
-
process.stderr.write(
|
|
158
|
-
"[arkheia] Warning: ARKHEIA_API_KEY not set.\n" +
|
|
159
|
-
"Get a free API key at https://arkheia.ai/mcp\n" +
|
|
160
|
-
"Then set: export ARKHEIA_API_KEY=ak_live_...\n\n"
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
let venvPython;
|
|
165
|
-
try {
|
|
166
|
-
venvPython = ensureVenv(python);
|
|
167
|
-
installDeps(venvPython);
|
|
168
|
-
} catch (err) {
|
|
169
|
-
process.stderr.write(
|
|
170
|
-
`[arkheia] Error setting up Python environment: ${err.message}\n`
|
|
171
|
-
);
|
|
172
|
-
process.exit(1);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Spawn the MCP server with stdio transport
|
|
176
|
-
const child = spawn(
|
|
177
|
-
venvPython,
|
|
178
|
-
["-m", "mcp_server.server"],
|
|
179
|
-
{
|
|
180
|
-
cwd: PYTHON_DIR,
|
|
181
|
-
stdio: ["pipe", "pipe", "inherit"], // stdin/stdout piped, stderr inherited
|
|
182
|
-
env: {
|
|
183
|
-
...process.env,
|
|
184
|
-
PYTHONPATH: PYTHON_DIR,
|
|
185
|
-
},
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
// Forward stdio for MCP protocol
|
|
190
|
-
process.stdin.pipe(child.stdin);
|
|
191
|
-
child.stdout.pipe(process.stdout);
|
|
192
|
-
|
|
193
|
-
child.on("error", (err) => {
|
|
194
|
-
process.stderr.write(`[arkheia] Failed to start MCP server: ${err.message}\n`);
|
|
195
|
-
process.exit(1);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
child.on("exit", (code) => {
|
|
199
|
-
process.exit(code || 0);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// Forward signals
|
|
203
|
-
process.on("SIGINT", () => child.kill("SIGINT"));
|
|
204
|
-
process.on("SIGTERM", () => child.kill("SIGTERM"));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
main();
|
|
File without changes
|
package/python/requirements.txt
DELETED