multiagents 0.1.2 → 0.1.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/cli/install-mcp.ts +209 -63
- package/cli/setup.ts +44 -214
- package/package.json +1 -1
- package/.mcp.json +0 -12
package/cli/install-mcp.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
|
-
* multiagents install-mcp — Configure MCP servers for
|
|
3
|
+
* multiagents install-mcp — Configure MCP servers globally for all detected agent CLIs.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 3. Prints instructions to restart Claude Code
|
|
5
|
+
* Claude Code: `claude mcp add -s user` → writes to ~/.claude.json
|
|
6
|
+
* Docs: https://docs.anthropic.com/en/docs/claude-code
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Codex CLI: `codex mcp add` → writes to ~/.codex/config.toml
|
|
9
|
+
* Docs: https://developers.openai.com/codex/mcp
|
|
10
|
+
*
|
|
11
|
+
* Gemini CLI: Direct write to ~/.gemini/settings.json (no CLI command for mcp add)
|
|
12
|
+
* Docs: https://geminicli.com/docs/tools/mcp-server/
|
|
13
|
+
*
|
|
14
|
+
* Each agent has its own config format and location. This script handles all three.
|
|
11
15
|
*/
|
|
12
16
|
|
|
13
17
|
import * as fs from "node:fs";
|
|
@@ -15,9 +19,8 @@ import * as path from "node:path";
|
|
|
15
19
|
import * as os from "node:os";
|
|
16
20
|
|
|
17
21
|
const HOME = os.homedir();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const SETTINGS_JSON = path.join(CLAUDE_DIR, "settings.json");
|
|
22
|
+
|
|
23
|
+
// --- Binary resolution ---
|
|
21
24
|
|
|
22
25
|
function findBinary(name: string): string {
|
|
23
26
|
try {
|
|
@@ -28,6 +31,8 @@ function findBinary(name: string): string {
|
|
|
28
31
|
|
|
29
32
|
const candidates = [
|
|
30
33
|
path.join(HOME, ".bun", "bin", name),
|
|
34
|
+
path.join(HOME, ".local", "bin", name),
|
|
35
|
+
path.join(HOME, ".npm-global", "bin", name),
|
|
31
36
|
`/usr/local/bin/${name}`,
|
|
32
37
|
`/opt/homebrew/bin/${name}`,
|
|
33
38
|
];
|
|
@@ -37,89 +42,230 @@ function findBinary(name: string): string {
|
|
|
37
42
|
return name;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
function findAgentCli(name: string): string | null {
|
|
46
|
+
// Check `which` first
|
|
47
|
+
try {
|
|
48
|
+
const which = Bun.spawnSync(["which", name]);
|
|
49
|
+
if (which.exitCode === 0) return new TextDecoder().decode(which.stdout).trim();
|
|
50
|
+
} catch { /* ok */ }
|
|
51
|
+
|
|
52
|
+
// Known install locations
|
|
53
|
+
const knownPaths: Record<string, string[]> = {
|
|
54
|
+
claude: [
|
|
55
|
+
path.join(HOME, ".local", "bin", "claude"),
|
|
56
|
+
path.join(HOME, ".claude", "bin", "claude"),
|
|
57
|
+
"/usr/local/bin/claude",
|
|
58
|
+
"/opt/homebrew/bin/claude",
|
|
59
|
+
],
|
|
60
|
+
codex: [
|
|
61
|
+
path.join(HOME, ".local", "bin", "codex"),
|
|
62
|
+
path.join(HOME, ".npm-global", "bin", "codex"),
|
|
63
|
+
"/usr/local/bin/codex",
|
|
64
|
+
"/opt/homebrew/bin/codex",
|
|
65
|
+
],
|
|
66
|
+
gemini: [
|
|
67
|
+
path.join(HOME, ".local", "bin", "gemini"),
|
|
68
|
+
path.join(HOME, ".npm-global", "bin", "gemini"),
|
|
69
|
+
"/usr/local/bin/gemini",
|
|
70
|
+
"/opt/homebrew/bin/gemini",
|
|
71
|
+
],
|
|
72
|
+
};
|
|
45
73
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
fs.mkdirSync(CLAUDE_DIR, { recursive: true });
|
|
74
|
+
for (const p of (knownPaths[name] ?? [])) {
|
|
75
|
+
if (fs.existsSync(p)) return p;
|
|
49
76
|
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// --- Claude Code ---
|
|
81
|
+
// Uses: `claude mcp add <name> -s user -- <command>`
|
|
82
|
+
// Writes to: ~/.claude.json → mcpServers
|
|
83
|
+
// Docs: https://docs.anthropic.com/en/docs/claude-code
|
|
84
|
+
|
|
85
|
+
function configureClaude(serverBin: string, orchBin: string): string[] {
|
|
86
|
+
const logs: string[] = [];
|
|
87
|
+
const claudePath = findAgentCli("claude");
|
|
88
|
+
|
|
89
|
+
if (claudePath) {
|
|
90
|
+
// Use the official CLI (preferred)
|
|
91
|
+
// Remove first to avoid duplicates
|
|
92
|
+
Bun.spawnSync([claudePath, "mcp", "remove", "multiagents", "-s", "user"], { stderr: "ignore", stdout: "ignore" });
|
|
93
|
+
Bun.spawnSync([claudePath, "mcp", "remove", "multiagents-orch", "-s", "user"], { stderr: "ignore", stdout: "ignore" });
|
|
94
|
+
|
|
95
|
+
const r1 = Bun.spawnSync([claudePath, "mcp", "add", "multiagents", "-s", "user", "--", serverBin]);
|
|
96
|
+
const r2 = Bun.spawnSync([claudePath, "mcp", "add", "multiagents-orch", "-s", "user", "--", orchBin]);
|
|
50
97
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
mcpConfig = JSON.parse(fs.readFileSync(MCP_JSON, "utf-8"));
|
|
55
|
-
if (!mcpConfig.mcpServers) mcpConfig.mcpServers = {};
|
|
56
|
-
} catch {
|
|
57
|
-
fs.copyFileSync(MCP_JSON, MCP_JSON + ".bak");
|
|
58
|
-
mcpConfig = { mcpServers: {} };
|
|
59
|
-
logs.push(" \x1b[33m!\x1b[0m Existing .mcp.json was corrupted — backed up and recreated");
|
|
98
|
+
if (r1.exitCode === 0 && r2.exitCode === 0) {
|
|
99
|
+
logs.push(" \x1b[32m✔\x1b[0m Claude Code: MCP servers added (via claude mcp add -s user)");
|
|
100
|
+
return logs;
|
|
60
101
|
}
|
|
102
|
+
logs.push(" \x1b[33m!\x1b[0m Claude Code: CLI method failed, falling back to file config");
|
|
61
103
|
}
|
|
62
104
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
105
|
+
// Fallback: write directly to ~/.claude.json
|
|
106
|
+
const configPath = path.join(HOME, ".claude.json");
|
|
107
|
+
let config: Record<string, unknown> = {};
|
|
108
|
+
if (fs.existsSync(configPath)) {
|
|
109
|
+
try { config = JSON.parse(fs.readFileSync(configPath, "utf-8")); } catch { config = {}; }
|
|
110
|
+
}
|
|
67
111
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
112
|
+
const mcpServers = (config.mcpServers as Record<string, unknown>) ?? {};
|
|
113
|
+
mcpServers["multiagents"] = { type: "stdio", command: serverBin, args: [], env: {} };
|
|
114
|
+
mcpServers["multiagents-orch"] = { type: "stdio", command: orchBin, args: [], env: {} };
|
|
115
|
+
config.mcpServers = mcpServers;
|
|
116
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
117
|
+
logs.push(" \x1b[32m✔\x1b[0m Claude Code: MCP servers written to ~/.claude.json");
|
|
118
|
+
return logs;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// --- Codex CLI ---
|
|
122
|
+
// Uses: `codex mcp add <name> -- <command> <args...>`
|
|
123
|
+
// Writes to: ~/.codex/config.toml → [mcp_servers.<name>]
|
|
124
|
+
// Docs: https://developers.openai.com/codex/mcp
|
|
125
|
+
|
|
126
|
+
function configureCodex(serverBin: string): string[] {
|
|
127
|
+
const logs: string[] = [];
|
|
128
|
+
const codexPath = findAgentCli("codex");
|
|
129
|
+
|
|
130
|
+
if (codexPath) {
|
|
131
|
+
// Use the official CLI (preferred)
|
|
132
|
+
// Remove first to avoid duplicates
|
|
133
|
+
Bun.spawnSync([codexPath, "mcp", "remove", "multiagents"], { stderr: "ignore", stdout: "ignore" });
|
|
134
|
+
|
|
135
|
+
const r1 = Bun.spawnSync([codexPath, "mcp", "add", "multiagents", "--", serverBin, "--agent-type", "codex"]);
|
|
136
|
+
if (r1.exitCode === 0) {
|
|
137
|
+
logs.push(" \x1b[32m✔\x1b[0m Codex CLI: MCP server added (via codex mcp add)");
|
|
75
138
|
return logs;
|
|
76
139
|
}
|
|
140
|
+
logs.push(" \x1b[33m!\x1b[0m Codex CLI: CLI method failed, falling back to file config");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Fallback: write directly to ~/.codex/config.toml
|
|
144
|
+
const codexDir = path.join(HOME, ".codex");
|
|
145
|
+
const configPath = path.join(codexDir, "config.toml");
|
|
146
|
+
|
|
147
|
+
if (!fs.existsSync(codexDir)) {
|
|
148
|
+
fs.mkdirSync(codexDir, { recursive: true });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let existing = "";
|
|
152
|
+
if (fs.existsSync(configPath)) {
|
|
153
|
+
existing = fs.readFileSync(configPath, "utf-8");
|
|
77
154
|
}
|
|
78
155
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
logs.push(" \x1b[32m✔\x1b[0m Enabled in ~/.claude/settings.json");
|
|
156
|
+
// Check if [mcp_servers.multiagents] already exists
|
|
157
|
+
if (existing.includes("[mcp_servers.multiagents]")) {
|
|
158
|
+
// Replace existing block
|
|
159
|
+
existing = existing.replace(
|
|
160
|
+
/\[mcp_servers\.multiagents\][^\[]*/s,
|
|
161
|
+
`[mcp_servers.multiagents]\ncommand = "${serverBin}"\nargs = ["--agent-type", "codex"]\n\n`
|
|
162
|
+
);
|
|
87
163
|
} else {
|
|
88
|
-
|
|
164
|
+
// Append new block
|
|
165
|
+
existing += `\n[mcp_servers.multiagents]\ncommand = "${serverBin}"\nargs = ["--agent-type", "codex"]\n`;
|
|
89
166
|
}
|
|
90
167
|
|
|
168
|
+
fs.writeFileSync(configPath, existing);
|
|
169
|
+
logs.push(" \x1b[32m✔\x1b[0m Codex CLI: MCP server written to ~/.codex/config.toml");
|
|
91
170
|
return logs;
|
|
92
171
|
}
|
|
93
172
|
|
|
173
|
+
// --- Gemini CLI ---
|
|
174
|
+
// No CLI command for adding MCP servers (as of March 2026).
|
|
175
|
+
// Direct write to: ~/.gemini/settings.json → mcpServers
|
|
176
|
+
// Docs: https://geminicli.com/docs/tools/mcp-server/
|
|
177
|
+
|
|
178
|
+
function configureGemini(serverBin: string): string[] {
|
|
179
|
+
const logs: string[] = [];
|
|
180
|
+
const geminiDir = path.join(HOME, ".gemini");
|
|
181
|
+
const configPath = path.join(geminiDir, "settings.json");
|
|
182
|
+
|
|
183
|
+
if (!fs.existsSync(geminiDir)) {
|
|
184
|
+
fs.mkdirSync(geminiDir, { recursive: true });
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let settings: Record<string, unknown> = {};
|
|
188
|
+
if (fs.existsSync(configPath)) {
|
|
189
|
+
try { settings = JSON.parse(fs.readFileSync(configPath, "utf-8")); } catch { settings = {}; }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const mcpServers = (settings.mcpServers as Record<string, unknown>) ?? {};
|
|
193
|
+
mcpServers["multiagents"] = {
|
|
194
|
+
command: serverBin,
|
|
195
|
+
args: ["--agent-type", "gemini"],
|
|
196
|
+
timeout: 30000,
|
|
197
|
+
};
|
|
198
|
+
settings.mcpServers = mcpServers;
|
|
199
|
+
|
|
200
|
+
fs.writeFileSync(configPath, JSON.stringify(settings, null, 2) + "\n");
|
|
201
|
+
logs.push(" \x1b[32m✔\x1b[0m Gemini CLI: MCP server written to ~/.gemini/settings.json");
|
|
202
|
+
return logs;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// --- Public API ---
|
|
206
|
+
|
|
207
|
+
interface ConfigResult {
|
|
208
|
+
logs: string[];
|
|
209
|
+
configured: string[];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function configureMcp(): ConfigResult {
|
|
213
|
+
const serverBin = findBinary("multiagents-server");
|
|
214
|
+
const orchBin = findBinary("multiagents-orch");
|
|
215
|
+
const logs: string[] = [];
|
|
216
|
+
const configured: string[] = [];
|
|
217
|
+
|
|
218
|
+
// Claude Code (always — it's the primary orchestrator)
|
|
219
|
+
const claudeLogs = configureClaude(serverBin, orchBin);
|
|
220
|
+
logs.push(...claudeLogs);
|
|
221
|
+
configured.push("claude");
|
|
222
|
+
|
|
223
|
+
// Codex CLI (if installed)
|
|
224
|
+
if (findAgentCli("codex")) {
|
|
225
|
+
const codexLogs = configureCodex(serverBin);
|
|
226
|
+
logs.push(...codexLogs);
|
|
227
|
+
configured.push("codex");
|
|
228
|
+
} else {
|
|
229
|
+
logs.push(" \x1b[90m-\x1b[0m Codex CLI: not installed, skipping");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Gemini CLI (if installed)
|
|
233
|
+
if (findAgentCli("gemini")) {
|
|
234
|
+
const geminiLogs = configureGemini(serverBin);
|
|
235
|
+
logs.push(...geminiLogs);
|
|
236
|
+
configured.push("gemini");
|
|
237
|
+
} else {
|
|
238
|
+
logs.push(" \x1b[90m-\x1b[0m Gemini CLI: not installed, skipping");
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return { logs, configured };
|
|
242
|
+
}
|
|
243
|
+
|
|
94
244
|
/** Verbose version — standalone `multiagents install-mcp` command. */
|
|
95
245
|
export async function installMcp(): Promise<void> {
|
|
96
246
|
console.log("\n\x1b[1m\x1b[36m multiagents install-mcp\x1b[0m");
|
|
97
|
-
console.log("\x1b[90m Configure MCP servers for
|
|
247
|
+
console.log("\x1b[90m Configure MCP servers for all detected agent CLIs\x1b[0m\n");
|
|
98
248
|
|
|
99
|
-
const logs = configureMcp();
|
|
249
|
+
const { logs, configured } = configureMcp();
|
|
100
250
|
for (const line of logs) console.log(line);
|
|
101
251
|
|
|
102
252
|
console.log(`
|
|
103
|
-
\x1b[1m\x1b[32mDone!\x1b[0m MCP
|
|
104
|
-
|
|
105
|
-
\x1b[1mNext step:\x1b[0m Restart Claude Code to load the new tools.
|
|
106
|
-
Exit Claude Code and run: \x1b[90mclaude\x1b[0m
|
|
253
|
+
\x1b[1m\x1b[32mDone!\x1b[0m MCP configured for: ${configured.join(", ")}
|
|
107
254
|
|
|
108
|
-
\x1b[
|
|
109
|
-
\x1b[90m {
|
|
110
|
-
"mcpServers": {
|
|
111
|
-
"multiagents": { "command": "multiagents-server", "args": [] },
|
|
112
|
-
"multiagents-orch": { "command": "multiagents-orch", "args": [] }
|
|
113
|
-
}
|
|
114
|
-
}\x1b[0m
|
|
255
|
+
\x1b[1mNext step:\x1b[0m Restart your agent CLIs to load the new tools.
|
|
115
256
|
|
|
116
|
-
|
|
117
|
-
\x1b[
|
|
257
|
+
\x1b[1mVerify:\x1b[0m
|
|
258
|
+
${configured.includes("claude") ? " Claude: \x1b[90mclaude mcp list | grep multiagent\x1b[0m\n" : ""}${configured.includes("codex") ? " Codex: \x1b[90mcodex mcp list\x1b[0m\n" : ""}${configured.includes("gemini") ? " Gemini: \x1b[90mCheck ~/.gemini/settings.json\x1b[0m\n" : ""}
|
|
259
|
+
\x1b[1mManual setup:\x1b[0m
|
|
260
|
+
Claude: \x1b[90mclaude mcp add multiagents -s user -- multiagents-server\x1b[0m
|
|
261
|
+
Codex: \x1b[90mcodex mcp add multiagents -- multiagents-server --agent-type codex\x1b[0m
|
|
262
|
+
Gemini: Add to ~/.gemini/settings.json:
|
|
263
|
+
\x1b[90m{"mcpServers":{"multiagents":{"command":"multiagents-server","args":["--agent-type","gemini"]}}}\x1b[0m
|
|
118
264
|
`);
|
|
119
265
|
}
|
|
120
266
|
|
|
121
|
-
/** Quiet version — called from `setup` flow
|
|
267
|
+
/** Quiet version — called from `setup` flow. */
|
|
122
268
|
export async function installMcpSilent(): Promise<void> {
|
|
123
|
-
const logs = configureMcp();
|
|
269
|
+
const { logs } = configureMcp();
|
|
124
270
|
for (const line of logs) console.log(line);
|
|
125
271
|
}
|
package/cli/setup.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
// ============================================================================
|
|
2
|
-
// multiagents —
|
|
2
|
+
// multiagents — Setup: detect agents + install MCP globally
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
|
-
import { DEFAULT_BROKER_PORT, BROKER_HOSTNAME
|
|
5
|
+
import { DEFAULT_BROKER_PORT, BROKER_HOSTNAME } from "../shared/constants.ts";
|
|
6
6
|
import { BrokerClient } from "../shared/broker-client.ts";
|
|
7
|
-
import { expandHome, getGitRoot, slugify } from "../shared/utils.ts";
|
|
8
|
-
import type { AgentType, SessionFile } from "../shared/types.ts";
|
|
9
|
-
import * as readline from "node:readline";
|
|
10
7
|
import * as path from "node:path";
|
|
11
8
|
import * as fs from "node:fs";
|
|
12
9
|
import * as os from "node:os";
|
|
@@ -14,20 +11,7 @@ import * as os from "node:os";
|
|
|
14
11
|
const BROKER_PORT = parseInt(process.env.MULTIAGENTS_PORT ?? String(DEFAULT_BROKER_PORT), 10);
|
|
15
12
|
const BROKER_URL = `http://${BROKER_HOSTNAME}:${BROKER_PORT}`;
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function prompt(question: string, defaultValue?: string): Promise<string> {
|
|
20
|
-
return new Promise((resolve) => {
|
|
21
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
22
|
-
const suffix = defaultValue ? ` [${defaultValue}]` : "";
|
|
23
|
-
rl.question(`${question}${suffix}: `, (answer) => {
|
|
24
|
-
rl.close();
|
|
25
|
-
resolve(answer.trim() || defaultValue || "");
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Known install locations per agent type, checked as fallbacks when `which` fails. */
|
|
14
|
+
/** Known install locations per agent type. */
|
|
31
15
|
const KNOWN_PATHS: Record<string, string[]> = {
|
|
32
16
|
claude: [
|
|
33
17
|
path.join(os.homedir(), ".local", "bin", "claude"),
|
|
@@ -50,7 +34,6 @@ const KNOWN_PATHS: Record<string, string[]> = {
|
|
|
50
34
|
};
|
|
51
35
|
|
|
52
36
|
function detectAgent(name: string): { available: boolean; version?: string; resolvedPath?: string } {
|
|
53
|
-
// 1. Try `which`
|
|
54
37
|
let agentPath: string | null = null;
|
|
55
38
|
try {
|
|
56
39
|
const which = Bun.spawnSync(["which", name]);
|
|
@@ -59,50 +42,38 @@ function detectAgent(name: string): { available: boolean; version?: string; reso
|
|
|
59
42
|
}
|
|
60
43
|
} catch { /* which failed */ }
|
|
61
44
|
|
|
62
|
-
// 2. Fallback: check known paths
|
|
63
45
|
if (!agentPath) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
if (fs.existsSync(p)) {
|
|
67
|
-
agentPath = p;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
46
|
+
for (const p of (KNOWN_PATHS[name] ?? [])) {
|
|
47
|
+
if (fs.existsSync(p)) { agentPath = p; break; }
|
|
70
48
|
}
|
|
71
49
|
}
|
|
72
50
|
|
|
73
51
|
if (!agentPath) return { available: false };
|
|
74
52
|
|
|
75
|
-
// 3. Get version (with timeout protection — some CLIs hang)
|
|
76
53
|
let version: string | undefined;
|
|
77
54
|
try {
|
|
78
|
-
const ver = Bun.spawnSync([agentPath, "--version"], {
|
|
79
|
-
timeout: 5000, // 5s timeout
|
|
80
|
-
});
|
|
55
|
+
const ver = Bun.spawnSync([agentPath, "--version"], { timeout: 5000 });
|
|
81
56
|
if (ver.exitCode === 0) {
|
|
82
57
|
version = new TextDecoder().decode(ver.stdout).trim().split("\n")[0] || undefined;
|
|
83
58
|
}
|
|
84
|
-
} catch {
|
|
85
|
-
// Version check failed — agent exists but version unknown
|
|
86
|
-
version = undefined;
|
|
87
|
-
}
|
|
59
|
+
} catch { version = undefined; }
|
|
88
60
|
|
|
89
61
|
return { available: true, version, resolvedPath: agentPath };
|
|
90
62
|
}
|
|
91
63
|
|
|
92
64
|
export async function setup(): Promise<void> {
|
|
93
|
-
// 1. Header banner
|
|
94
65
|
console.log(`
|
|
95
|
-
\x1b[1m\x1b[36m multiagents\x1b[0m
|
|
96
|
-
\x1b[90m
|
|
66
|
+
\x1b[1m\x1b[36m multiagents setup\x1b[0m
|
|
67
|
+
\x1b[90m Configure MCP + detect agents\x1b[0m
|
|
97
68
|
\x1b[90m ─────────────────────────────────\x1b[0m
|
|
98
69
|
`);
|
|
99
70
|
|
|
100
|
-
//
|
|
71
|
+
// 1. Detect agents
|
|
101
72
|
console.log("\x1b[1mDetecting installed agents...\x1b[0m\n");
|
|
102
|
-
const agents
|
|
103
|
-
{
|
|
104
|
-
{
|
|
105
|
-
{
|
|
73
|
+
const agents = [
|
|
74
|
+
{ name: "Claude Code", cmd: "claude", info: detectAgent("claude") },
|
|
75
|
+
{ name: "Codex CLI", cmd: "codex", info: detectAgent("codex") },
|
|
76
|
+
{ name: "Gemini CLI", cmd: "gemini", info: detectAgent("gemini") },
|
|
106
77
|
];
|
|
107
78
|
|
|
108
79
|
for (const a of agents) {
|
|
@@ -111,202 +82,61 @@ export async function setup(): Promise<void> {
|
|
|
111
82
|
console.log(` ${icon} ${a.name}${ver}`);
|
|
112
83
|
}
|
|
113
84
|
|
|
114
|
-
const available = agents.filter(
|
|
85
|
+
const available = agents.filter(a => a.info.available);
|
|
115
86
|
if (available.length === 0) {
|
|
116
|
-
console.error("\n\x1b[31mNo supported agents found. Install at least one
|
|
117
|
-
process.exit(1);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 3. Prompt user to select agents
|
|
121
|
-
console.log("\n\x1b[1mSelect agents to orchestrate:\x1b[0m\n");
|
|
122
|
-
for (let i = 0; i < available.length; i++) {
|
|
123
|
-
console.log(` ${i + 1}. ${available[i].name} (${available[i].cmd})`);
|
|
124
|
-
}
|
|
125
|
-
console.log(` a. All available agents`);
|
|
126
|
-
|
|
127
|
-
const selection = await prompt("\nEnter numbers separated by commas, or 'a' for all", "a");
|
|
128
|
-
let selected: typeof available;
|
|
129
|
-
if (selection === "a" || selection === "A") {
|
|
130
|
-
selected = available;
|
|
131
|
-
} else {
|
|
132
|
-
const indices = selection.split(",").map((s) => parseInt(s.trim(), 10) - 1);
|
|
133
|
-
selected = indices
|
|
134
|
-
.filter((i) => i >= 0 && i < available.length)
|
|
135
|
-
.map((i) => available[i]);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (selected.length === 0) {
|
|
139
|
-
console.error("\n\x1b[31mNo agents selected.\x1b[0m");
|
|
87
|
+
console.error("\n\x1b[31mNo supported agents found. Install at least one: claude, codex, or gemini.\x1b[0m");
|
|
140
88
|
process.exit(1);
|
|
141
89
|
}
|
|
142
|
-
console.log(`\nSelected: ${selected.map((a) => a.name).join(", ")}`);
|
|
143
90
|
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
const resolvedDir = path.resolve(expandHome(projectDir));
|
|
147
|
-
if (!fs.existsSync(resolvedDir)) {
|
|
148
|
-
console.error(`\n\x1b[31mDirectory does not exist: ${resolvedDir}\x1b[0m`);
|
|
149
|
-
process.exit(1);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// 5. Prompt for session name
|
|
153
|
-
const dirName = path.basename(resolvedDir);
|
|
154
|
-
const sessionName = await prompt("Session name", dirName);
|
|
155
|
-
const sessionId = slugify(sessionName);
|
|
156
|
-
|
|
157
|
-
// 6. Install global MCP config (Claude Code + settings.json)
|
|
158
|
-
console.log("\n\x1b[1mConfiguring global MCP...\x1b[0m\n");
|
|
91
|
+
// 2. Install global MCP config
|
|
92
|
+
console.log("\n\x1b[1mConfiguring MCP servers...\x1b[0m\n");
|
|
159
93
|
const { installMcpSilent } = await import("./install-mcp.ts");
|
|
160
94
|
await installMcpSilent();
|
|
161
95
|
|
|
162
|
-
//
|
|
163
|
-
console.log("\x1b[1mConfiguring per-agent MCP...\x1b[0m\n");
|
|
164
|
-
|
|
165
|
-
const cliPath = path.resolve(import.meta.dir, "..");
|
|
166
|
-
|
|
167
|
-
for (const agent of selected) {
|
|
168
|
-
try {
|
|
169
|
-
switch (agent.type) {
|
|
170
|
-
case "claude":
|
|
171
|
-
await configureClaudeMcp(resolvedDir, cliPath);
|
|
172
|
-
break;
|
|
173
|
-
case "codex":
|
|
174
|
-
await configureCodexMcp(resolvedDir, cliPath);
|
|
175
|
-
break;
|
|
176
|
-
case "gemini":
|
|
177
|
-
await configureGeminiMcp(cliPath);
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
console.log(` \x1b[32m✔\x1b[0m ${agent.name} MCP configured`);
|
|
181
|
-
} catch (e) {
|
|
182
|
-
console.error(` \x1b[31m✗\x1b[0m ${agent.name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// 7. Start broker
|
|
96
|
+
// 3. Start broker
|
|
187
97
|
console.log("\n\x1b[1mStarting broker...\x1b[0m");
|
|
188
98
|
const client = new BrokerClient(BROKER_URL);
|
|
189
99
|
let brokerAlive = await client.isAlive();
|
|
190
100
|
if (!brokerAlive) {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
});
|
|
101
|
+
const brokerBin = findBrokerBinary();
|
|
102
|
+
const proc = Bun.spawn([brokerBin], { stdio: ["ignore", "ignore", "ignore"] });
|
|
194
103
|
proc.unref();
|
|
195
104
|
for (let i = 0; i < 30; i++) {
|
|
196
105
|
if (await client.isAlive()) { brokerAlive = true; break; }
|
|
197
106
|
await Bun.sleep(200);
|
|
198
107
|
}
|
|
199
108
|
}
|
|
200
|
-
if (
|
|
201
|
-
console.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
console.log(` \x1b[32m✔\x1b[0m Broker running on ${BROKER_URL}`);
|
|
205
|
-
|
|
206
|
-
// 8. Create session
|
|
207
|
-
console.log("\n\x1b[1mCreating session...\x1b[0m");
|
|
208
|
-
const gitRoot = await getGitRoot(resolvedDir);
|
|
209
|
-
try {
|
|
210
|
-
await client.createSession({
|
|
211
|
-
id: sessionId,
|
|
212
|
-
name: sessionName,
|
|
213
|
-
project_dir: resolvedDir,
|
|
214
|
-
git_root: gitRoot,
|
|
215
|
-
});
|
|
216
|
-
console.log(` \x1b[32m✔\x1b[0m Session "${sessionName}" (${sessionId}) created`);
|
|
217
|
-
} catch (e) {
|
|
218
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
219
|
-
if (msg.includes("409") || msg.includes("UNIQUE") || msg.includes("already")) {
|
|
220
|
-
console.log(` \x1b[33m!\x1b[0m Session "${sessionId}" already exists, reusing`);
|
|
221
|
-
} else {
|
|
222
|
-
throw e;
|
|
223
|
-
}
|
|
109
|
+
if (brokerAlive) {
|
|
110
|
+
console.log(` \x1b[32m✔\x1b[0m Broker running on ${BROKER_URL}`);
|
|
111
|
+
} else {
|
|
112
|
+
console.log(` \x1b[33m!\x1b[0m Broker not started — will auto-start when agents connect`);
|
|
224
113
|
}
|
|
225
114
|
|
|
226
|
-
//
|
|
227
|
-
const sessionDir = path.join(resolvedDir, SESSION_DIR);
|
|
228
|
-
if (!fs.existsSync(sessionDir)) fs.mkdirSync(sessionDir, { recursive: true });
|
|
229
|
-
|
|
230
|
-
const sessionFile: SessionFile = {
|
|
231
|
-
session_id: sessionId,
|
|
232
|
-
created_at: new Date().toISOString(),
|
|
233
|
-
broker_port: BROKER_PORT,
|
|
234
|
-
};
|
|
235
|
-
await Bun.write(path.join(resolvedDir, SESSION_FILE), JSON.stringify(sessionFile, null, 2));
|
|
236
|
-
console.log(` \x1b[32m✔\x1b[0m Wrote ${SESSION_FILE}`);
|
|
237
|
-
|
|
238
|
-
// 10. Print next steps
|
|
115
|
+
// 4. Done
|
|
239
116
|
console.log(`
|
|
240
117
|
\x1b[1m\x1b[32mSetup complete!\x1b[0m
|
|
241
118
|
|
|
242
|
-
\x1b[
|
|
243
|
-
1.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
\x1b[90mmultiagents orchestrator\x1b[0m
|
|
119
|
+
\x1b[1mUsage:\x1b[0m
|
|
120
|
+
1. Restart Claude Code to load the multiagents tools.
|
|
121
|
+
2. In Claude Code, ask it to use the multiagents tools.
|
|
122
|
+
3. Or use the orchestrator to create a team:
|
|
123
|
+
\x1b[90mmultiagents create-team --project /path/to/project\x1b[0m
|
|
124
|
+
|
|
125
|
+
\x1b[1mAvailable commands:\x1b[0m
|
|
126
|
+
\x1b[90mmultiagents dashboard\x1b[0m Live monitoring
|
|
127
|
+
\x1b[90mmultiagents status\x1b[0m Broker health + peers
|
|
128
|
+
\x1b[90mmultiagents peers\x1b[0m List connected agents
|
|
129
|
+
\x1b[90mmultiagents install-mcp\x1b[0m Reconfigure MCP if needed
|
|
254
130
|
`);
|
|
255
131
|
}
|
|
256
132
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
async function configureClaudeMcp(projectDir: string, cliPath: string): Promise<void> {
|
|
260
|
-
// Write project-level .mcp.json
|
|
261
|
-
const mcpPath = path.join(projectDir, ".mcp.json");
|
|
262
|
-
let config: Record<string, unknown> = {};
|
|
263
|
-
try {
|
|
264
|
-
const existing = await Bun.file(mcpPath).text();
|
|
265
|
-
config = JSON.parse(existing);
|
|
266
|
-
} catch { /* file doesn't exist */ }
|
|
267
|
-
|
|
268
|
-
const mcpServers = (config.mcpServers as Record<string, unknown>) ?? {};
|
|
269
|
-
mcpServers["multiagents"] = {
|
|
270
|
-
command: "bun",
|
|
271
|
-
args: [path.resolve(cliPath, "cli.ts"), "mcp-server", "--agent-type", "claude"],
|
|
272
|
-
};
|
|
273
|
-
config.mcpServers = mcpServers;
|
|
274
|
-
await Bun.write(mcpPath, JSON.stringify(config, null, 2));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
async function configureCodexMcp(projectDir: string, cliPath: string): Promise<void> {
|
|
278
|
-
// Write .codex/config.toml
|
|
279
|
-
const codexDir = path.join(projectDir, ".codex");
|
|
280
|
-
if (!fs.existsSync(codexDir)) fs.mkdirSync(codexDir, { recursive: true });
|
|
281
|
-
|
|
282
|
-
const tomlPath = path.join(codexDir, "config.toml");
|
|
283
|
-
let existing = "";
|
|
284
|
-
try { existing = await Bun.file(tomlPath).text(); } catch { /* ok */ }
|
|
285
|
-
|
|
286
|
-
// Remove any existing multiagents section
|
|
287
|
-
existing = existing.replace(/\[mcp_servers\.multiagents\][\s\S]*?(?=\n\[|$)/, "").trim();
|
|
288
|
-
|
|
289
|
-
const entry = `\n\n[mcp_servers.multiagents]\ncommand = "bun"\nargs = [${JSON.stringify(path.resolve(cliPath, "cli.ts"))}, "mcp-server", "--agent-type", "codex"]\n`;
|
|
290
|
-
await Bun.write(tomlPath, existing + entry);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
async function configureGeminiMcp(cliPath: string): Promise<void> {
|
|
294
|
-
// Write ~/.gemini/settings.json
|
|
295
|
-
const geminiDir = expandHome("~/.gemini");
|
|
296
|
-
if (!fs.existsSync(geminiDir)) fs.mkdirSync(geminiDir, { recursive: true });
|
|
297
|
-
|
|
298
|
-
const settingsPath = path.join(geminiDir, "settings.json");
|
|
299
|
-
let config: Record<string, unknown> = {};
|
|
133
|
+
function findBrokerBinary(): string {
|
|
300
134
|
try {
|
|
301
|
-
const
|
|
302
|
-
|
|
135
|
+
const which = Bun.spawnSync(["which", "multiagents-broker"]);
|
|
136
|
+
const found = new TextDecoder().decode(which.stdout).trim();
|
|
137
|
+
if (found) return found;
|
|
303
138
|
} catch { /* ok */ }
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
command: "bun",
|
|
308
|
-
args: [path.resolve(cliPath, "cli.ts"), "mcp-server", "--agent-type", "gemini"],
|
|
309
|
-
};
|
|
310
|
-
config.mcpServers = mcpServers;
|
|
311
|
-
await Bun.write(settingsPath, JSON.stringify(config, null, 2));
|
|
139
|
+
const bun = path.join(os.homedir(), ".bun", "bin", "multiagents-broker");
|
|
140
|
+
if (fs.existsSync(bun)) return bun;
|
|
141
|
+
return "multiagents-broker";
|
|
312
142
|
}
|
package/package.json
CHANGED
package/.mcp.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mcpServers": {
|
|
3
|
-
"agent-peers": {
|
|
4
|
-
"command": "/Users/armanandreasyan/.bun/bin/bun",
|
|
5
|
-
"args": ["/Users/armanandreasyan/Documents/multi-agent-peers/server.ts"]
|
|
6
|
-
},
|
|
7
|
-
"agent-peers-orchestrator": {
|
|
8
|
-
"command": "/Users/armanandreasyan/.bun/bin/bun",
|
|
9
|
-
"args": ["/Users/armanandreasyan/Documents/multi-agent-peers/orchestrator/orchestrator-server.ts"]
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|