π The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(init): skip writing .mcp.json when ruflo MCP already registered (#1779) (#1820)
rUv7cee60317835
diff --git a/v3/@claude-flow/cli/src/init/executor.ts b/v3/@claude-flow/cli/src/init/executor.tsindex 7aea458611..ff423159c5 100644--- a/v3/@claude-flow/cli/src/init/executor.ts+++ b/v3/@claude-flow/cli/src/init/executor.ts@@ -775,6 +775,49 @@ async function writeSettings(result.created.files.push('.claude/settings.json');}+/**+ * #1779 β Walk parents of `targetDir` plus the user-global Claude Code+ * config locations, looking for any `.mcp.json` (or `~/.claude.json`)+ * that already declares a `ruflo`-keyed MCP server. We use this to skip+ * writing our own `claude-flow`-keyed entry when the user has already+ * registered the same binary under the new name β that's exactly the+ * "same MCP server twice under two different prefixes" duplication the+ * issue describes.+ *+ * Returns the path of the file that already declares `ruflo` (so we can+ * surface it in the skipped-message), or null if none found.+ */+function detectExistingRufloMCP(targetDir: string): string | null {+ const home = (process.env.HOME ?? process.env.USERPROFILE) ?? '';+ const candidates = new Set<string>();+ // User-global Claude Code config locations+ if (home) {+ candidates.add(path.join(home, '.claude.json'));+ candidates.add(path.join(home, '.claude', 'mcp.json'));+ }+ // Walk parents of targetDir up to root, checking for .mcp.json at each+ let dir = path.resolve(targetDir);+ while (true) {+ candidates.add(path.join(dir, '.mcp.json'));+ const parent = path.dirname(dir);+ if (parent === dir) break;+ dir = parent;+ }+ // Skip the targetDir itself β that's the one we're about to write+ candidates.delete(path.join(path.resolve(targetDir), '.mcp.json'));++ for (const candidate of candidates) {+ if (!fs.existsSync(candidate)) continue;+ try {+ const parsed = JSON.parse(fs.readFileSync(candidate, 'utf-8'));+ if (parsed && typeof parsed === 'object' && parsed.mcpServers && typeof parsed.mcpServers === 'object') {+ if ('ruflo' in parsed.mcpServers) return candidate;+ }+ } catch { /* malformed JSON β ignore */ }+ }+ return null;+}+/*** Write .mcp.json*/@@ -790,6 +833,20 @@ async function writeMCPConfig(return;}+ // #1779 β Skip writing if the user already has a `ruflo`-keyed MCP+ // server registered elsewhere (parent .mcp.json, ~/.claude.json, etc).+ // Writing our `claude-flow`-keyed entry on top of that produces the+ // duplicate-registration the issue describes (~250 duplicate tools).+ // Force-mode (`--force`) bypasses this guard for users who actually+ // want both registrations.+ if (!options.force) {+ const existingRufloPath = detectExistingRufloMCP(targetDir);+ if (existingRufloPath) {+ result.skipped.push(`.mcp.json (existing 'ruflo' MCP registration found at ${existingRufloPath} β would create duplicate; pass --force to write anyway)`);+ return;+ }+ }+const content = generateMCPJson(options);fs.writeFileSync(mcpPath, content, 'utf-8');result.created.files.push('.mcp.json');