multiagents 0.1.1 → 0.1.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/cli/install-mcp.ts +37 -42
- package/cli/setup.ts +63 -8
- package/package.json +1 -1
- package/scripts/postinstall.ts +4 -93
package/cli/install-mcp.ts
CHANGED
|
@@ -20,11 +20,12 @@ const MCP_JSON = path.join(CLAUDE_DIR, ".mcp.json");
|
|
|
20
20
|
const SETTINGS_JSON = path.join(CLAUDE_DIR, "settings.json");
|
|
21
21
|
|
|
22
22
|
function findBinary(name: string): string {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
try {
|
|
24
|
+
const which = Bun.spawnSync(["which", name]);
|
|
25
|
+
const found = new TextDecoder().decode(which.stdout).trim();
|
|
26
|
+
if (found) return found;
|
|
27
|
+
} catch { /* ok */ }
|
|
26
28
|
|
|
27
|
-
// Fallback to common locations
|
|
28
29
|
const candidates = [
|
|
29
30
|
path.join(HOME, ".bun", "bin", name),
|
|
30
31
|
`/usr/local/bin/${name}`,
|
|
@@ -33,20 +34,16 @@ function findBinary(name: string): string {
|
|
|
33
34
|
for (const c of candidates) {
|
|
34
35
|
if (fs.existsSync(c)) return c;
|
|
35
36
|
}
|
|
36
|
-
return name;
|
|
37
|
+
return name;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
/** Core logic — configures .mcp.json + settings.json. Returns log lines. */
|
|
41
|
+
function configureMcp(): string[] {
|
|
42
|
+
const logs: string[] = [];
|
|
43
43
|
const serverBin = findBinary("multiagents-server");
|
|
44
44
|
const orchBin = findBinary("multiagents-orch");
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
console.log(` Orchestrator binary: ${orchBin}\n`);
|
|
48
|
-
|
|
49
|
-
// --- Step 1: Write ~/.claude/.mcp.json ---
|
|
46
|
+
// Step 1: Write ~/.claude/.mcp.json
|
|
50
47
|
if (!fs.existsSync(CLAUDE_DIR)) {
|
|
51
48
|
fs.mkdirSync(CLAUDE_DIR, { recursive: true });
|
|
52
49
|
}
|
|
@@ -59,57 +56,49 @@ export async function installMcp(): Promise<void> {
|
|
|
59
56
|
} catch {
|
|
60
57
|
fs.copyFileSync(MCP_JSON, MCP_JSON + ".bak");
|
|
61
58
|
mcpConfig = { mcpServers: {} };
|
|
62
|
-
|
|
59
|
+
logs.push(" \x1b[33m!\x1b[0m Existing .mcp.json was corrupted — backed up and recreated");
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
mcpConfig.mcpServers["multiagents"] = {
|
|
67
|
-
|
|
68
|
-
args: [],
|
|
69
|
-
};
|
|
70
|
-
mcpConfig.mcpServers["multiagents-orch"] = {
|
|
71
|
-
command: orchBin,
|
|
72
|
-
args: [],
|
|
73
|
-
};
|
|
74
|
-
|
|
63
|
+
mcpConfig.mcpServers["multiagents"] = { command: serverBin, args: [] };
|
|
64
|
+
mcpConfig.mcpServers["multiagents-orch"] = { command: orchBin, args: [] };
|
|
75
65
|
fs.writeFileSync(MCP_JSON, JSON.stringify(mcpConfig, null, 2) + "\n");
|
|
76
|
-
|
|
66
|
+
logs.push(" \x1b[32m✔\x1b[0m Global MCP configured (~/.claude/.mcp.json)");
|
|
77
67
|
|
|
78
|
-
//
|
|
68
|
+
// Step 2: Enable in ~/.claude/settings.json
|
|
79
69
|
let settings: Record<string, unknown> = {};
|
|
80
70
|
if (fs.existsSync(SETTINGS_JSON)) {
|
|
81
71
|
try {
|
|
82
72
|
settings = JSON.parse(fs.readFileSync(SETTINGS_JSON, "utf-8"));
|
|
83
73
|
} catch {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return;
|
|
74
|
+
logs.push(" \x1b[33m!\x1b[0m Could not parse settings.json — skipping auto-enable");
|
|
75
|
+
return logs;
|
|
87
76
|
}
|
|
88
77
|
}
|
|
89
78
|
|
|
90
|
-
|
|
91
|
-
let enabled = (settings.enabledMcpjsonServers as string[]) ?? [];
|
|
79
|
+
const enabled = (settings.enabledMcpjsonServers as string[]) ?? [];
|
|
92
80
|
let changed = false;
|
|
93
|
-
if (!enabled.includes("multiagents")) {
|
|
94
|
-
|
|
95
|
-
changed = true;
|
|
96
|
-
}
|
|
97
|
-
if (!enabled.includes("multiagents-orch")) {
|
|
98
|
-
enabled.push("multiagents-orch");
|
|
99
|
-
changed = true;
|
|
100
|
-
}
|
|
81
|
+
if (!enabled.includes("multiagents")) { enabled.push("multiagents"); changed = true; }
|
|
82
|
+
if (!enabled.includes("multiagents-orch")) { enabled.push("multiagents-orch"); changed = true; }
|
|
101
83
|
if (changed) {
|
|
102
84
|
settings.enabledMcpjsonServers = enabled;
|
|
103
85
|
fs.writeFileSync(SETTINGS_JSON, JSON.stringify(settings, null, 2) + "\n");
|
|
104
|
-
|
|
86
|
+
logs.push(" \x1b[32m✔\x1b[0m Enabled in ~/.claude/settings.json");
|
|
105
87
|
} else {
|
|
106
|
-
|
|
88
|
+
logs.push(" \x1b[32m✔\x1b[0m Already enabled in settings.json");
|
|
107
89
|
}
|
|
108
90
|
|
|
109
|
-
|
|
91
|
+
return logs;
|
|
110
92
|
}
|
|
111
93
|
|
|
112
|
-
|
|
94
|
+
/** Verbose version — standalone `multiagents install-mcp` command. */
|
|
95
|
+
export async function installMcp(): Promise<void> {
|
|
96
|
+
console.log("\n\x1b[1m\x1b[36m multiagents install-mcp\x1b[0m");
|
|
97
|
+
console.log("\x1b[90m Configure MCP servers for Claude Code\x1b[0m\n");
|
|
98
|
+
|
|
99
|
+
const logs = configureMcp();
|
|
100
|
+
for (const line of logs) console.log(line);
|
|
101
|
+
|
|
113
102
|
console.log(`
|
|
114
103
|
\x1b[1m\x1b[32mDone!\x1b[0m MCP servers configured.
|
|
115
104
|
|
|
@@ -128,3 +117,9 @@ And add to ~/.claude/settings.json:
|
|
|
128
117
|
\x1b[90m "enabledMcpjsonServers": ["multiagents", "multiagents-orch"]\x1b[0m
|
|
129
118
|
`);
|
|
130
119
|
}
|
|
120
|
+
|
|
121
|
+
/** Quiet version — called from `setup` flow, prints compact output. */
|
|
122
|
+
export async function installMcpSilent(): Promise<void> {
|
|
123
|
+
const logs = configureMcp();
|
|
124
|
+
for (const line of logs) console.log(line);
|
|
125
|
+
}
|
package/cli/setup.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { AgentType, SessionFile } from "../shared/types.ts";
|
|
|
9
9
|
import * as readline from "node:readline";
|
|
10
10
|
import * as path from "node:path";
|
|
11
11
|
import * as fs from "node:fs";
|
|
12
|
+
import * as os from "node:os";
|
|
12
13
|
|
|
13
14
|
const BROKER_PORT = parseInt(process.env.MULTIAGENTS_PORT ?? String(DEFAULT_BROKER_PORT), 10);
|
|
14
15
|
const BROKER_URL = `http://${BROKER_HOSTNAME}:${BROKER_PORT}`;
|
|
@@ -26,17 +27,66 @@ function prompt(question: string, defaultValue?: string): Promise<string> {
|
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
/** Known install locations per agent type, checked as fallbacks when `which` fails. */
|
|
31
|
+
const KNOWN_PATHS: Record<string, string[]> = {
|
|
32
|
+
claude: [
|
|
33
|
+
path.join(os.homedir(), ".local", "bin", "claude"),
|
|
34
|
+
path.join(os.homedir(), ".claude", "bin", "claude"),
|
|
35
|
+
"/usr/local/bin/claude",
|
|
36
|
+
"/opt/homebrew/bin/claude",
|
|
37
|
+
],
|
|
38
|
+
codex: [
|
|
39
|
+
"/usr/local/bin/codex",
|
|
40
|
+
path.join(os.homedir(), ".local", "bin", "codex"),
|
|
41
|
+
path.join(os.homedir(), ".npm-global", "bin", "codex"),
|
|
42
|
+
"/opt/homebrew/bin/codex",
|
|
43
|
+
],
|
|
44
|
+
gemini: [
|
|
45
|
+
path.join(os.homedir(), ".local", "bin", "gemini"),
|
|
46
|
+
"/usr/local/bin/gemini",
|
|
47
|
+
"/opt/homebrew/bin/gemini",
|
|
48
|
+
path.join(os.homedir(), ".npm-global", "bin", "gemini"),
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function detectAgent(name: string): { available: boolean; version?: string; resolvedPath?: string } {
|
|
53
|
+
// 1. Try `which`
|
|
54
|
+
let agentPath: string | null = null;
|
|
30
55
|
try {
|
|
31
56
|
const which = Bun.spawnSync(["which", name]);
|
|
32
|
-
if (which.exitCode
|
|
57
|
+
if (which.exitCode === 0) {
|
|
58
|
+
agentPath = new TextDecoder().decode(which.stdout).trim();
|
|
59
|
+
}
|
|
60
|
+
} catch { /* which failed */ }
|
|
61
|
+
|
|
62
|
+
// 2. Fallback: check known paths
|
|
63
|
+
if (!agentPath) {
|
|
64
|
+
const candidates = KNOWN_PATHS[name] ?? [];
|
|
65
|
+
for (const p of candidates) {
|
|
66
|
+
if (fs.existsSync(p)) {
|
|
67
|
+
agentPath = p;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!agentPath) return { available: false };
|
|
33
74
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
75
|
+
// 3. Get version (with timeout protection — some CLIs hang)
|
|
76
|
+
let version: string | undefined;
|
|
77
|
+
try {
|
|
78
|
+
const ver = Bun.spawnSync([agentPath, "--version"], {
|
|
79
|
+
timeout: 5000, // 5s timeout
|
|
80
|
+
});
|
|
81
|
+
if (ver.exitCode === 0) {
|
|
82
|
+
version = new TextDecoder().decode(ver.stdout).trim().split("\n")[0] || undefined;
|
|
83
|
+
}
|
|
37
84
|
} catch {
|
|
38
|
-
|
|
85
|
+
// Version check failed — agent exists but version unknown
|
|
86
|
+
version = undefined;
|
|
39
87
|
}
|
|
88
|
+
|
|
89
|
+
return { available: true, version, resolvedPath: agentPath };
|
|
40
90
|
}
|
|
41
91
|
|
|
42
92
|
export async function setup(): Promise<void> {
|
|
@@ -104,8 +154,13 @@ export async function setup(): Promise<void> {
|
|
|
104
154
|
const sessionName = await prompt("Session name", dirName);
|
|
105
155
|
const sessionId = slugify(sessionName);
|
|
106
156
|
|
|
107
|
-
// 6.
|
|
108
|
-
console.log("\n\x1b[1mConfiguring MCP
|
|
157
|
+
// 6. Install global MCP config (Claude Code + settings.json)
|
|
158
|
+
console.log("\n\x1b[1mConfiguring global MCP...\x1b[0m\n");
|
|
159
|
+
const { installMcpSilent } = await import("./install-mcp.ts");
|
|
160
|
+
await installMcpSilent();
|
|
161
|
+
|
|
162
|
+
// 7. Configure per-agent MCP
|
|
163
|
+
console.log("\x1b[1mConfiguring per-agent MCP...\x1b[0m\n");
|
|
109
164
|
|
|
110
165
|
const cliPath = path.resolve(import.meta.dir, "..");
|
|
111
166
|
|
package/package.json
CHANGED
package/scripts/postinstall.ts
CHANGED
|
@@ -1,105 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
3
|
* Post-install script: auto-configures MCP servers for Claude Code.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* so Claude Code can discover the tools without manual configuration.
|
|
7
|
-
*
|
|
8
|
-
* Safe: only adds entries if they don't already exist. Never overwrites.
|
|
4
|
+
* Delegates to the same logic as `multiagents install-mcp`.
|
|
5
|
+
* If it fails, prints fallback instructions — never breaks the install.
|
|
9
6
|
*/
|
|
10
7
|
|
|
11
|
-
import * as fs from "node:fs";
|
|
12
|
-
import * as path from "node:path";
|
|
13
|
-
import * as os from "node:os";
|
|
14
|
-
|
|
15
|
-
const HOME = os.homedir();
|
|
16
|
-
const CLAUDE_DIR = path.join(HOME, ".claude");
|
|
17
|
-
const MCP_JSON = path.join(CLAUDE_DIR, ".mcp.json");
|
|
18
|
-
|
|
19
|
-
// Use installed binary names — works regardless of install location
|
|
20
|
-
function findBinary(name: string): string {
|
|
21
|
-
try {
|
|
22
|
-
const which = Bun.spawnSync(["which", name]);
|
|
23
|
-
const found = new TextDecoder().decode(which.stdout).trim();
|
|
24
|
-
if (found) return found;
|
|
25
|
-
} catch { /* ok */ }
|
|
26
|
-
const defaultPath = path.join(HOME, ".bun", "bin", name);
|
|
27
|
-
if (fs.existsSync(defaultPath)) return defaultPath;
|
|
28
|
-
return name; // fallback
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const SERVER_BIN = findBinary("multiagents-server");
|
|
32
|
-
const ORCH_BIN = findBinary("multiagents-orch");
|
|
33
|
-
|
|
34
8
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
fs.mkdirSync(CLAUDE_DIR, { recursive: true });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Read or create .mcp.json
|
|
41
|
-
let config: { mcpServers: Record<string, unknown> } = { mcpServers: {} };
|
|
42
|
-
if (fs.existsSync(MCP_JSON)) {
|
|
43
|
-
try {
|
|
44
|
-
config = JSON.parse(fs.readFileSync(MCP_JSON, "utf-8"));
|
|
45
|
-
if (!config.mcpServers) config.mcpServers = {};
|
|
46
|
-
} catch {
|
|
47
|
-
// Corrupted file — back up and recreate
|
|
48
|
-
fs.copyFileSync(MCP_JSON, MCP_JSON + ".bak");
|
|
49
|
-
config = { mcpServers: {} };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let changed = false;
|
|
54
|
-
|
|
55
|
-
// Add multiagents MCP server (using installed binary names)
|
|
56
|
-
if (!config.mcpServers["multiagents"]) {
|
|
57
|
-
config.mcpServers["multiagents"] = {
|
|
58
|
-
command: SERVER_BIN,
|
|
59
|
-
args: [],
|
|
60
|
-
};
|
|
61
|
-
changed = true;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Add orchestrator MCP server
|
|
65
|
-
if (!config.mcpServers["multiagents-orch"]) {
|
|
66
|
-
config.mcpServers["multiagents-orch"] = {
|
|
67
|
-
command: ORCH_BIN,
|
|
68
|
-
args: [],
|
|
69
|
-
};
|
|
70
|
-
changed = true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (changed) {
|
|
74
|
-
fs.writeFileSync(MCP_JSON, JSON.stringify(config, null, 2) + "\n");
|
|
75
|
-
console.log("[multiagents] MCP servers configured in ~/.claude/.mcp.json");
|
|
76
|
-
} else {
|
|
77
|
-
console.log("[multiagents] MCP servers already configured in .mcp.json");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Also enable in settings.json
|
|
81
|
-
const SETTINGS_JSON = path.join(CLAUDE_DIR, "settings.json");
|
|
82
|
-
if (fs.existsSync(SETTINGS_JSON)) {
|
|
83
|
-
try {
|
|
84
|
-
const settings = JSON.parse(fs.readFileSync(SETTINGS_JSON, "utf-8"));
|
|
85
|
-
const enabled: string[] = settings.enabledMcpjsonServers ?? [];
|
|
86
|
-
let settingsChanged = false;
|
|
87
|
-
if (!enabled.includes("multiagents")) { enabled.push("multiagents"); settingsChanged = true; }
|
|
88
|
-
if (!enabled.includes("multiagents-orch")) { enabled.push("multiagents-orch"); settingsChanged = true; }
|
|
89
|
-
if (settingsChanged) {
|
|
90
|
-
settings.enabledMcpjsonServers = enabled;
|
|
91
|
-
fs.writeFileSync(SETTINGS_JSON, JSON.stringify(settings, null, 2) + "\n");
|
|
92
|
-
console.log("[multiagents] Enabled in ~/.claude/settings.json");
|
|
93
|
-
}
|
|
94
|
-
} catch {
|
|
95
|
-
// Don't fail install over settings.json
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
9
|
+
const { installMcpSilent } = await import("../cli/install-mcp.ts");
|
|
10
|
+
await installMcpSilent();
|
|
99
11
|
console.log("[multiagents] Restart Claude Code to pick up the new tools.");
|
|
100
12
|
console.log("[multiagents] If tools don't appear, run: multiagents install-mcp");
|
|
101
13
|
} catch (e) {
|
|
102
|
-
// Postinstall should never fail the install
|
|
103
14
|
console.error(`[multiagents] postinstall warning: ${e instanceof Error ? e.message : String(e)}`);
|
|
104
15
|
console.error("[multiagents] Run 'multiagents install-mcp' to configure manually.");
|
|
105
16
|
}
|