@claude-flow/cli 3.0.0-alpha.40 → 3.0.0-alpha.42

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/bin/cli.js CHANGED
@@ -3,12 +3,148 @@
3
3
  * @claude-flow/cli - CLI Entry Point
4
4
  *
5
5
  * Claude Flow V3 Command Line Interface
6
+ *
7
+ * Auto-detects MCP mode when stdin is piped and no args provided.
8
+ * This allows: echo '{"jsonrpc":"2.0",...}' | npx @claude-flow/cli
6
9
  */
7
10
 
8
- import { CLI } from '../dist/src/index.js';
11
+ // Check if we should run in MCP server mode
12
+ // Conditions: stdin is being piped AND no CLI arguments provided
13
+ const isMCPMode = !process.stdin.isTTY && process.argv.length === 2;
14
+
15
+ if (isMCPMode) {
16
+ // Run MCP server mode
17
+ const { listMCPTools, callMCPTool, hasTool } = await import('../dist/src/mcp-client.js');
18
+
19
+ const VERSION = '3.0.0';
20
+ const sessionId = `mcp-${Date.now()}-${Math.random().toString(36).substr(2, 4)}`;
21
+
22
+ console.error(
23
+ `[${new Date().toISOString()}] INFO [claude-flow-mcp] (${sessionId}) Starting in stdio mode`
24
+ );
25
+
26
+ let buffer = '';
27
+ process.stdin.setEncoding('utf8');
28
+ process.stdin.on('data', async (chunk) => {
29
+ buffer += chunk;
30
+ let lines = buffer.split('\n');
31
+ buffer = lines.pop() || '';
32
+
33
+ for (const line of lines) {
34
+ if (line.trim()) {
35
+ try {
36
+ const message = JSON.parse(line);
37
+ const response = await handleMessage(message);
38
+ if (response) {
39
+ console.log(JSON.stringify(response));
40
+ }
41
+ } catch (error) {
42
+ console.log(JSON.stringify({
43
+ jsonrpc: '2.0',
44
+ id: null,
45
+ error: { code: -32700, message: 'Parse error' },
46
+ }));
47
+ }
48
+ }
49
+ }
50
+ });
51
+
52
+ process.stdin.on('end', () => {
53
+ process.exit(0);
54
+ });
55
+
56
+ async function handleMessage(message) {
57
+ if (!message.method) {
58
+ return {
59
+ jsonrpc: '2.0',
60
+ id: message.id,
61
+ error: { code: -32600, message: 'Invalid Request: missing method' },
62
+ };
63
+ }
64
+
65
+ const params = message.params || {};
66
+
67
+ switch (message.method) {
68
+ case 'initialize':
69
+ return {
70
+ jsonrpc: '2.0',
71
+ id: message.id,
72
+ result: {
73
+ protocolVersion: '2024-11-05',
74
+ serverInfo: { name: 'claude-flow', version: VERSION },
75
+ capabilities: {
76
+ tools: { listChanged: true },
77
+ resources: { subscribe: true, listChanged: true },
78
+ },
79
+ },
80
+ };
81
+
82
+ case 'tools/list': {
83
+ const tools = listMCPTools();
84
+ return {
85
+ jsonrpc: '2.0',
86
+ id: message.id,
87
+ result: {
88
+ tools: tools.map(tool => ({
89
+ name: tool.name,
90
+ description: tool.description,
91
+ inputSchema: tool.inputSchema,
92
+ })),
93
+ },
94
+ };
95
+ }
96
+
97
+ case 'tools/call': {
98
+ const toolName = params.name;
99
+ const toolParams = params.arguments || {};
100
+
101
+ if (!hasTool(toolName)) {
102
+ return {
103
+ jsonrpc: '2.0',
104
+ id: message.id,
105
+ error: { code: -32601, message: `Tool not found: ${toolName}` },
106
+ };
107
+ }
108
+
109
+ try {
110
+ const result = await callMCPTool(toolName, toolParams, { sessionId });
111
+ return {
112
+ jsonrpc: '2.0',
113
+ id: message.id,
114
+ result: { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] },
115
+ };
116
+ } catch (error) {
117
+ return {
118
+ jsonrpc: '2.0',
119
+ id: message.id,
120
+ error: {
121
+ code: -32603,
122
+ message: error instanceof Error ? error.message : 'Tool execution failed',
123
+ },
124
+ };
125
+ }
126
+ }
127
+
128
+ case 'notifications/initialized':
129
+ return null;
130
+
131
+ case 'ping':
132
+ return { jsonrpc: '2.0', id: message.id, result: {} };
9
133
 
10
- const cli = new CLI();
11
- cli.run().catch((error) => {
12
- console.error('Fatal error:', error.message);
13
- process.exit(1);
14
- });
134
+ default:
135
+ return {
136
+ jsonrpc: '2.0',
137
+ id: message.id,
138
+ error: { code: -32601, message: `Method not found: ${message.method}` },
139
+ };
140
+ }
141
+ }
142
+ } else {
143
+ // Run normal CLI mode
144
+ const { CLI } = await import('../dist/src/index.js');
145
+ const cli = new CLI();
146
+ cli.run().catch((error) => {
147
+ console.error('Fatal error:', error.message);
148
+ process.exit(1);
149
+ });
150
+ }
package/bin/mcp-server.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.0.0-alpha.40",
3
+ "version": "3.0.0-alpha.42",
4
4
  "type": "module",
5
5
  "description": "CLI module - command parsing, prompts, output formatting",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",
8
8
  "sideEffects": false,
9
9
  "bin": {
10
+ "cli": "./bin/cli.js",
10
11
  "claude-flow": "./bin/cli.js",
11
12
  "claude-flow-mcp": "./bin/mcp-server.js"
12
13
  },