Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

Checkpoint: File edits

rUvaa6c628f21a9
diff --git a/v3/@claude-flow/cli/bin/cli.js b/v3/@claude-flow/cli/bin/cli.js
index e0ba5c0cce..7e1eebf0c7 100755
--- a/v3/@claude-flow/cli/bin/cli.js
+++ b/v3/@claude-flow/cli/bin/cli.js
@@ -3,12 +3,148 @@
* @claude-flow/cli - CLI Entry Point
*
* Claude Flow V3 Command Line Interface
+ *
+ * Auto-detects MCP mode when stdin is piped and no args provided.
+ * This allows: echo '{"jsonrpc":"2.0",...}' | npx @claude-flow/cli
*/
-import { CLI } from '../dist/src/index.js';
+// Check if we should run in MCP server mode
+// Conditions: stdin is being piped AND no CLI arguments provided
+const isMCPMode = !process.stdin.isTTY && process.argv.length === 2;
+
+if (isMCPMode) {
+ // Run MCP server mode
+ const { listMCPTools, callMCPTool, hasTool } = await import('../dist/src/mcp-client.js');
+
+ const VERSION = '3.0.0';
+ const sessionId = `mcp-${Date.now()}-${Math.random().toString(36).substr(2, 4)}`;
+
+ console.error(
+ `[${new Date().toISOString()}] INFO [claude-flow-mcp] (${sessionId}) Starting in stdio mode`
+ );
+
+ let buffer = '';
+ process.stdin.setEncoding('utf8');
+ process.stdin.on('data', async (chunk) => {
+ buffer += chunk;
+ let lines = buffer.split('\n');
+ buffer = lines.pop() || '';
+
+ for (const line of lines) {
+ if (line.trim()) {
+ try {
+ const message = JSON.parse(line);
+ const response = await handleMessage(message);
+ if (response) {
+ console.log(JSON.stringify(response));
+ }
+ } catch (error) {
+ console.log(JSON.stringify({
+ jsonrpc: '2.0',
+ id: null,
+ error: { code: -32700, message: 'Parse error' },
+ }));
+ }
+ }
+ }
+ });
+
+ process.stdin.on('end', () => {
+ process.exit(0);
+ });
+
+ async function handleMessage(message) {
+ if (!message.method) {
+ return {
+ jsonrpc: '2.0',
+ id: message.id,
+ error: { code: -32600, message: 'Invalid Request: missing method' },
+ };
+ }
+
+ const params = message.params || {};
+
+ switch (message.method) {
+ case 'initialize':
+ return {
+ jsonrpc: '2.0',
+ id: message.id,
+ result: {
+ protocolVersion: '2024-11-05',
+ serverInfo: { name: 'claude-flow', version: VERSION },
+ capabilities: {
+ tools: { listChanged: true },
+ resources: { subscribe: true, listChanged: true },
+ },
+ },
+ };
+
+ case 'tools/list': {
+ const tools = listMCPTools();
+ return {
+ jsonrpc: '2.0',
+ id: message.id,
+ result: {
+ tools: tools.map(tool => ({
+ name: tool.name,
+ description: tool.description,
+ inputSchema: tool.inputSchema,
+ })),
+ },
+ };
+ }
+
+ case 'tools/call': {
+ const toolName = params.name;
+ const toolParams = params.arguments || {};
+
+ if (!hasTool(toolName)) {
+ return {
+ jsonrpc: '2.0',
+ id: message.id,
+ error: { code: -32601, message: `Tool not found: ${toolName}` },
+ };
+ }
+
+ try {
+ const result = await callMCPTool(toolName, toolParams, { sessionId });
+ return {
+ jsonrpc: '2.0',
+ id: message.id,
+ result: { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] },
+ };
+ } catch (error) {
+ return {
+ jsonrpc: '2.0',
+ id: message.id,
+ error: {
+ code: -32603,
+ message: error instanceof Error ? error.message : 'Tool execution failed',
+ },
+ };
+ }
+ }
+
+ case 'notifications/initialized':
+ return null;
+
+ case 'ping':
+ return { jsonrpc: '2.0', id: message.id, result: {} };
-const cli = new CLI();
-cli.run().catch((error) => {
- console.error('Fatal error:', error.message);
- process.exit(1);
-});
+ default:
+ return {
+ jsonrpc: '2.0',
+ id: message.id,
+ error: { code: -32601, message: `Method not found: ${message.method}` },
+ };
+ }
+ }
+} else {
+ // Run normal CLI mode
+ const { CLI } = await import('../dist/src/index.js');
+ const cli = new CLI();
+ cli.run().catch((error) => {
+ console.error('Fatal error:', error.message);
+ process.exit(1);
+ });
+}
diff --git a/v3/@claude-flow/cli/bin/mcp-server.js b/v3/@claude-flow/cli/bin/mcp-server.js
old mode 100644
new mode 100755
diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json
index 25cf1560ea..a995852467 100644
--- a/v3/@claude-flow/cli/package.json
+++ b/v3/@claude-flow/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/cli",
- "version": "3.0.0-alpha.40",
+ "version": "3.0.0-alpha.41",
"type": "module",
"description": "CLI module - command parsing, prompts, output formatting",
"main": "dist/src/index.js",
diff --git a/v3/package-lock.json b/v3/package-lock.json
index 11daa67bfe..3792abd10a 100644
--- a/v3/package-lock.json
+++ b/v3/package-lock.json
@@ -124,13 +124,14 @@
}
},
"@claude-flow/cli": {
- "version": "3.0.0-alpha.40",
+ "version": "3.0.0-alpha.41",
"dependencies": {
"@claude-flow/shared": "^3.0.0-alpha.1"
},
"bin": {
"claude-flow": "bin/cli.js",
- "claude-flow-mcp": "bin/mcp-server.js"
+ "claude-flow-mcp": "bin/mcp-server.js",
+ "cli": "bin/cli.js"
},
"devDependencies": {
"typescript": "^5.3.0",