@claude-flow/cli 3.0.0-alpha.13 → 3.0.0-alpha.14

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.
Files changed (102) hide show
  1. package/package.json +12 -4
  2. package/.agentic-flow/intelligence.json +0 -17
  3. package/.claude-flow/agents/store.json +0 -16
  4. package/.claude-flow/daemon-state.json +0 -123
  5. package/.claude-flow/daemon-test.log +0 -0
  6. package/.claude-flow/daemon.log +0 -0
  7. package/.claude-flow/daemon2.log +0 -0
  8. package/.claude-flow/daemon3.log +0 -0
  9. package/.claude-flow/hive-mind/state.json +0 -51
  10. package/.claude-flow/metrics/agent-metrics.json +0 -1
  11. package/.claude-flow/metrics/codebase-map.json +0 -11
  12. package/.claude-flow/metrics/consolidation.json +0 -6
  13. package/.claude-flow/metrics/performance.json +0 -87
  14. package/.claude-flow/metrics/security-audit.json +0 -10
  15. package/.claude-flow/metrics/task-metrics.json +0 -10
  16. package/.claude-flow/metrics/test-gaps.json +0 -6
  17. package/__tests__/README.md +0 -140
  18. package/__tests__/TEST_SUMMARY.md +0 -144
  19. package/__tests__/cli.test.ts +0 -558
  20. package/__tests__/commands.test.ts +0 -726
  21. package/__tests__/config-adapter.test.ts +0 -362
  22. package/__tests__/config-loading.test.ts +0 -106
  23. package/__tests__/coverage/.tmp/coverage-0.json +0 -1
  24. package/__tests__/coverage/.tmp/coverage-1.json +0 -1
  25. package/__tests__/coverage/.tmp/coverage-2.json +0 -1
  26. package/__tests__/coverage/.tmp/coverage-3.json +0 -1
  27. package/__tests__/coverage/.tmp/coverage-4.json +0 -1
  28. package/__tests__/coverage/.tmp/coverage-5.json +0 -1
  29. package/__tests__/mcp-client.test.ts +0 -480
  30. package/__tests__/p1-commands.test.ts +0 -1064
  31. package/agents/architect.yaml +0 -11
  32. package/agents/coder.yaml +0 -11
  33. package/agents/reviewer.yaml +0 -10
  34. package/agents/security-architect.yaml +0 -10
  35. package/agents/tester.yaml +0 -10
  36. package/docs/CONFIG_LOADING.md +0 -236
  37. package/docs/IMPLEMENTATION_COMPLETE.md +0 -421
  38. package/docs/MCP_CLIENT_GUIDE.md +0 -620
  39. package/docs/REFACTORING_SUMMARY.md +0 -247
  40. package/scripts/publish.sh +0 -46
  41. package/src/commands/agent.ts +0 -955
  42. package/src/commands/claims.ts +0 -317
  43. package/src/commands/completions.ts +0 -558
  44. package/src/commands/config.ts +0 -452
  45. package/src/commands/daemon.ts +0 -621
  46. package/src/commands/deployment.ts +0 -323
  47. package/src/commands/doctor.ts +0 -382
  48. package/src/commands/embeddings.ts +0 -686
  49. package/src/commands/hive-mind.ts +0 -928
  50. package/src/commands/hooks.ts +0 -2603
  51. package/src/commands/index.ts +0 -154
  52. package/src/commands/init.ts +0 -597
  53. package/src/commands/mcp.ts +0 -753
  54. package/src/commands/memory.ts +0 -1161
  55. package/src/commands/migrate.ts +0 -447
  56. package/src/commands/neural.ts +0 -253
  57. package/src/commands/performance.ts +0 -292
  58. package/src/commands/plugins.ts +0 -316
  59. package/src/commands/process.ts +0 -695
  60. package/src/commands/providers.ts +0 -259
  61. package/src/commands/security.ts +0 -288
  62. package/src/commands/session.ts +0 -891
  63. package/src/commands/start.ts +0 -457
  64. package/src/commands/status.ts +0 -736
  65. package/src/commands/swarm.ts +0 -648
  66. package/src/commands/task.ts +0 -792
  67. package/src/commands/workflow.ts +0 -742
  68. package/src/config-adapter.ts +0 -210
  69. package/src/index.ts +0 -443
  70. package/src/infrastructure/in-memory-repositories.ts +0 -310
  71. package/src/init/claudemd-generator.ts +0 -631
  72. package/src/init/executor.ts +0 -762
  73. package/src/init/helpers-generator.ts +0 -628
  74. package/src/init/index.ts +0 -60
  75. package/src/init/mcp-generator.ts +0 -83
  76. package/src/init/settings-generator.ts +0 -284
  77. package/src/init/statusline-generator.ts +0 -211
  78. package/src/init/types.ts +0 -447
  79. package/src/mcp-client.ts +0 -241
  80. package/src/mcp-server.ts +0 -577
  81. package/src/mcp-tools/agent-tools.ts +0 -466
  82. package/src/mcp-tools/config-tools.ts +0 -370
  83. package/src/mcp-tools/hive-mind-tools.ts +0 -521
  84. package/src/mcp-tools/hooks-tools.ts +0 -1888
  85. package/src/mcp-tools/index.ts +0 -16
  86. package/src/mcp-tools/memory-tools.ts +0 -270
  87. package/src/mcp-tools/session-tools.ts +0 -359
  88. package/src/mcp-tools/swarm-tools.ts +0 -105
  89. package/src/mcp-tools/task-tools.ts +0 -347
  90. package/src/mcp-tools/types.ts +0 -33
  91. package/src/mcp-tools/workflow-tools.ts +0 -573
  92. package/src/output.ts +0 -639
  93. package/src/parser.ts +0 -417
  94. package/src/prompt.ts +0 -619
  95. package/src/services/index.ts +0 -15
  96. package/src/services/worker-daemon.ts +0 -726
  97. package/src/suggest.ts +0 -245
  98. package/src/types.ts +0 -287
  99. package/tmp.json +0 -0
  100. package/tsconfig.json +0 -16
  101. package/tsconfig.tsbuildinfo +0 -1
  102. package/vitest.config.ts +0 -13
@@ -1,753 +0,0 @@
1
- /**
2
- * V3 CLI MCP Command
3
- * MCP server control and management with real server integration
4
- *
5
- * @module @claude-flow/cli/commands/mcp
6
- * @version 3.0.0
7
- */
8
-
9
- import type { Command, CommandContext, CommandResult } from '../types.js';
10
- import { output } from '../output.js';
11
- import { select, confirm } from '../prompt.js';
12
- import {
13
- MCPServerManager,
14
- createMCPServerManager,
15
- getServerManager,
16
- startMCPServer,
17
- stopMCPServer,
18
- getMCPServerStatus,
19
- type MCPServerOptions,
20
- type MCPServerStatus,
21
- } from '../mcp-server.js';
22
- import { listMCPTools, callMCPTool, hasTool, getToolMetadata } from '../mcp-client.js';
23
-
24
- // MCP tools categories
25
- const TOOL_CATEGORIES = [
26
- { value: 'coordination', label: 'Coordination', hint: 'Swarm and agent coordination tools' },
27
- { value: 'monitoring', label: 'Monitoring', hint: 'Status and metrics monitoring' },
28
- { value: 'memory', label: 'Memory', hint: 'Memory and neural features' },
29
- { value: 'github', label: 'GitHub', hint: 'GitHub integration tools' },
30
- { value: 'system', label: 'System', hint: 'System and benchmark tools' }
31
- ];
32
-
33
- /**
34
- * Format uptime for display
35
- */
36
- function formatUptime(seconds: number): string {
37
- if (seconds < 60) {
38
- return `${seconds}s`;
39
- }
40
- if (seconds < 3600) {
41
- const mins = Math.floor(seconds / 60);
42
- const secs = seconds % 60;
43
- return `${mins}m ${secs}s`;
44
- }
45
- const hours = Math.floor(seconds / 3600);
46
- const mins = Math.floor((seconds % 3600) / 60);
47
- return `${hours}h ${mins}m`;
48
- }
49
-
50
- // Start MCP server
51
- const startCommand: Command = {
52
- name: 'start',
53
- description: 'Start MCP server',
54
- options: [
55
- {
56
- name: 'port',
57
- short: 'p',
58
- description: 'Server port',
59
- type: 'number',
60
- default: 3000
61
- },
62
- {
63
- name: 'host',
64
- short: 'h',
65
- description: 'Server host',
66
- type: 'string',
67
- default: 'localhost'
68
- },
69
- {
70
- name: 'transport',
71
- short: 't',
72
- description: 'Transport type (stdio, http, websocket)',
73
- type: 'string',
74
- default: 'stdio',
75
- choices: ['stdio', 'http', 'websocket']
76
- },
77
- {
78
- name: 'tools',
79
- description: 'Tools to enable (comma-separated or "all")',
80
- type: 'string',
81
- default: 'all'
82
- },
83
- {
84
- name: 'daemon',
85
- short: 'd',
86
- description: 'Run as background daemon',
87
- type: 'boolean',
88
- default: false
89
- }
90
- ],
91
- examples: [
92
- { command: 'claude-flow mcp start', description: 'Start with defaults (stdio)' },
93
- { command: 'claude-flow mcp start -p 8080 -t http', description: 'Start HTTP server' },
94
- { command: 'claude-flow mcp start -d', description: 'Start as daemon' }
95
- ],
96
- action: async (ctx: CommandContext): Promise<CommandResult> => {
97
- const port = ctx.flags.port as number;
98
- const host = ctx.flags.host as string;
99
- const transport = ctx.flags.transport as 'stdio' | 'http' | 'websocket';
100
- const tools = ctx.flags.tools as string;
101
- const daemon = ctx.flags.daemon as boolean;
102
-
103
- output.writeln();
104
- output.printInfo('Starting MCP Server...');
105
- output.writeln();
106
-
107
- // Check if already running
108
- const existingStatus = await getMCPServerStatus();
109
- if (existingStatus.running) {
110
- output.printWarning(`MCP Server already running (PID: ${existingStatus.pid})`);
111
- output.writeln(output.dim('Use "claude-flow mcp stop" to stop the server first'));
112
- return { success: false, exitCode: 1 };
113
- }
114
-
115
- const options: MCPServerOptions = {
116
- transport,
117
- host,
118
- port,
119
- tools: tools === 'all' ? 'all' : tools.split(','),
120
- daemonize: daemon,
121
- };
122
-
123
- try {
124
- output.writeln(output.dim(' Initializing server...'));
125
-
126
- const manager = getServerManager(options);
127
-
128
- // Setup event handlers for progress display
129
- manager.on('starting', () => {
130
- output.writeln(output.dim(' Loading tool registry...'));
131
- });
132
-
133
- manager.on('started', (data: any) => {
134
- output.writeln(output.dim(` Server started in ${data.startupTime?.toFixed(2) || 0}ms`));
135
- });
136
-
137
- manager.on('log', (log: { level: string; msg: string; data?: unknown }) => {
138
- if (ctx.flags.verbose) {
139
- output.writeln(output.dim(` [${log.level}] ${log.msg}`));
140
- }
141
- });
142
-
143
- // Start the server
144
- const status = await manager.start();
145
-
146
- output.writeln();
147
- output.printTable({
148
- columns: [
149
- { key: 'property', header: 'Property', width: 15 },
150
- { key: 'value', header: 'Value', width: 30 }
151
- ],
152
- data: [
153
- { property: 'Server PID', value: status.pid || process.pid },
154
- { property: 'Transport', value: transport },
155
- { property: 'Host', value: host },
156
- { property: 'Port', value: port },
157
- { property: 'Tools', value: tools === 'all' ? '27 enabled' : `${tools.split(',').length} enabled` },
158
- { property: 'Status', value: output.success('Running') }
159
- ]
160
- });
161
-
162
- output.writeln();
163
- output.printSuccess('MCP Server started');
164
-
165
- if (transport === 'http') {
166
- output.writeln(output.dim(` Health: http://${host}:${port}/health`));
167
- output.writeln(output.dim(` RPC: http://${host}:${port}/rpc`));
168
- } else if (transport === 'websocket') {
169
- output.writeln(output.dim(` WebSocket: ws://${host}:${port}/ws`));
170
- }
171
-
172
- if (daemon) {
173
- output.writeln(output.dim(' Running in background mode'));
174
- }
175
-
176
- return { success: true, data: status };
177
- } catch (error) {
178
- output.printError(`Failed to start MCP server: ${(error as Error).message}`);
179
- return { success: false, exitCode: 1 };
180
- }
181
- }
182
- };
183
-
184
- // Stop MCP server
185
- const stopCommand: Command = {
186
- name: 'stop',
187
- description: 'Stop MCP server',
188
- options: [
189
- {
190
- name: 'force',
191
- short: 'f',
192
- description: 'Force stop without graceful shutdown',
193
- type: 'boolean',
194
- default: false
195
- }
196
- ],
197
- action: async (ctx: CommandContext): Promise<CommandResult> => {
198
- const force = ctx.flags.force as boolean;
199
-
200
- // Check if server is running
201
- const status = await getMCPServerStatus();
202
- if (!status.running) {
203
- output.printInfo('MCP Server is not running');
204
- return { success: true };
205
- }
206
-
207
- if (!force && ctx.interactive) {
208
- const confirmed = await confirm({
209
- message: `Stop MCP server (PID: ${status.pid})?`,
210
- default: false
211
- });
212
-
213
- if (!confirmed) {
214
- output.printInfo('Operation cancelled');
215
- return { success: true };
216
- }
217
- }
218
-
219
- output.printInfo('Stopping MCP Server...');
220
-
221
- try {
222
- const manager = getServerManager();
223
-
224
- if (!force) {
225
- output.writeln(output.dim(' Completing pending requests...'));
226
- output.writeln(output.dim(' Closing connections...'));
227
- }
228
-
229
- await manager.stop(force);
230
-
231
- output.writeln(output.dim(' Releasing resources...'));
232
- output.printSuccess('MCP Server stopped');
233
-
234
- return { success: true, data: { stopped: true, force } };
235
- } catch (error) {
236
- output.printError(`Failed to stop MCP server: ${(error as Error).message}`);
237
- return { success: false, exitCode: 1 };
238
- }
239
- }
240
- };
241
-
242
- // MCP status
243
- const statusCommand: Command = {
244
- name: 'status',
245
- description: 'Show MCP server status',
246
- action: async (ctx: CommandContext): Promise<CommandResult> => {
247
- try {
248
- const status = await getMCPServerStatus();
249
-
250
- if (ctx.flags.format === 'json') {
251
- output.printJson(status);
252
- return { success: true, data: status };
253
- }
254
-
255
- output.writeln();
256
- output.writeln(output.bold('MCP Server Status'));
257
- output.writeln();
258
-
259
- if (!status.running) {
260
- output.printTable({
261
- columns: [
262
- { key: 'metric', header: 'Metric', width: 20 },
263
- { key: 'value', header: 'Value', width: 20, align: 'right' }
264
- ],
265
- data: [
266
- { metric: 'Status', value: output.error('Stopped') }
267
- ]
268
- });
269
-
270
- output.writeln();
271
- output.writeln(output.dim('Run "claude-flow mcp start" to start the server'));
272
- return { success: true, data: status };
273
- }
274
-
275
- const displayData = [
276
- { metric: 'Status', value: output.success('Running') },
277
- { metric: 'PID', value: status.pid },
278
- { metric: 'Transport', value: status.transport },
279
- { metric: 'Host', value: status.host },
280
- { metric: 'Port', value: status.port },
281
- ];
282
-
283
- if (status.uptime !== undefined) {
284
- displayData.push({ metric: 'Uptime', value: formatUptime(status.uptime) });
285
- }
286
-
287
- if (status.startedAt) {
288
- displayData.push({ metric: 'Started At', value: status.startedAt });
289
- }
290
-
291
- if (status.health) {
292
- displayData.push({
293
- metric: 'Health',
294
- value: status.health.healthy
295
- ? output.success('Healthy')
296
- : output.error(status.health.error || 'Unhealthy')
297
- });
298
-
299
- if (status.health.metrics) {
300
- for (const [key, value] of Object.entries(status.health.metrics)) {
301
- displayData.push({
302
- metric: ` ${key}`,
303
- value: String(value)
304
- });
305
- }
306
- }
307
- }
308
-
309
- output.printTable({
310
- columns: [
311
- { key: 'metric', header: 'Metric', width: 20 },
312
- { key: 'value', header: 'Value', width: 25, align: 'right' }
313
- ],
314
- data: displayData
315
- });
316
-
317
- return { success: true, data: status };
318
- } catch (error) {
319
- output.printError(`Failed to get status: ${(error as Error).message}`);
320
- return { success: false, exitCode: 1 };
321
- }
322
- }
323
- };
324
-
325
- // List tools
326
- const toolsCommand: Command = {
327
- name: 'tools',
328
- description: 'List available MCP tools',
329
- options: [
330
- {
331
- name: 'category',
332
- short: 'c',
333
- description: 'Filter by category',
334
- type: 'string',
335
- choices: TOOL_CATEGORIES.map(c => c.value)
336
- },
337
- {
338
- name: 'enabled',
339
- description: 'Show only enabled tools',
340
- type: 'boolean',
341
- default: false
342
- }
343
- ],
344
- action: async (ctx: CommandContext): Promise<CommandResult> => {
345
- const category = ctx.flags.category as string;
346
-
347
- // Use local tool registry
348
- let tools: Array<{ name: string; category: string; description: string; enabled: boolean }>;
349
-
350
- // Get tools from local registry
351
- const registeredTools = listMCPTools(category);
352
-
353
- if (registeredTools.length > 0) {
354
- tools = registeredTools.map(tool => ({
355
- name: tool.name,
356
- category: tool.category || 'uncategorized',
357
- description: tool.description,
358
- enabled: true
359
- }));
360
- } else {
361
- // Fallback to static tool list
362
- tools = [
363
- // Agent tools
364
- { name: 'agent/spawn', category: 'agent', description: 'Spawn a new agent', enabled: true },
365
- { name: 'agent/list', category: 'agent', description: 'List all agents', enabled: true },
366
- { name: 'agent/terminate', category: 'agent', description: 'Terminate an agent', enabled: true },
367
- { name: 'agent/status', category: 'agent', description: 'Get agent status', enabled: true },
368
-
369
- // Swarm tools
370
- { name: 'swarm/init', category: 'swarm', description: 'Initialize swarm topology', enabled: true },
371
- { name: 'swarm/status', category: 'swarm', description: 'Get swarm status', enabled: true },
372
- { name: 'swarm/scale', category: 'swarm', description: 'Scale swarm size', enabled: true },
373
-
374
- // Memory tools
375
- { name: 'memory/store', category: 'memory', description: 'Store in memory', enabled: true },
376
- { name: 'memory/search', category: 'memory', description: 'Search memory', enabled: true },
377
- { name: 'memory/list', category: 'memory', description: 'List memory entries', enabled: true },
378
-
379
- // Config tools
380
- { name: 'config/load', category: 'config', description: 'Load configuration', enabled: true },
381
- { name: 'config/save', category: 'config', description: 'Save configuration', enabled: true },
382
- { name: 'config/validate', category: 'config', description: 'Validate configuration', enabled: true },
383
-
384
- // Hooks tools
385
- { name: 'hooks/pre-edit', category: 'hooks', description: 'Pre-edit hook', enabled: true },
386
- { name: 'hooks/post-edit', category: 'hooks', description: 'Post-edit hook', enabled: true },
387
- { name: 'hooks/pre-command', category: 'hooks', description: 'Pre-command hook', enabled: true },
388
- { name: 'hooks/post-command', category: 'hooks', description: 'Post-command hook', enabled: true },
389
- { name: 'hooks/route', category: 'hooks', description: 'Route task to agent', enabled: true },
390
- { name: 'hooks/explain', category: 'hooks', description: 'Explain routing', enabled: true },
391
- { name: 'hooks/pretrain', category: 'hooks', description: 'Pretrain from repo', enabled: true },
392
- { name: 'hooks/metrics', category: 'hooks', description: 'Learning metrics', enabled: true },
393
- { name: 'hooks/list', category: 'hooks', description: 'List hooks', enabled: true },
394
-
395
- // System tools
396
- { name: 'system/info', category: 'system', description: 'System information', enabled: true },
397
- { name: 'system/health', category: 'system', description: 'Health status', enabled: true },
398
- { name: 'system/metrics', category: 'system', description: 'Server metrics', enabled: true },
399
- ].filter(t => !category || t.category === category);
400
- }
401
-
402
- if (ctx.flags.format === 'json') {
403
- output.printJson(tools);
404
- return { success: true, data: tools };
405
- }
406
-
407
- output.writeln();
408
- output.writeln(output.bold('Available MCP Tools'));
409
- output.writeln();
410
-
411
- // Group by category
412
- const grouped = tools.reduce((acc, tool) => {
413
- if (!acc[tool.category]) acc[tool.category] = [];
414
- acc[tool.category].push(tool);
415
- return acc;
416
- }, {} as Record<string, typeof tools>);
417
-
418
- for (const [cat, catTools] of Object.entries(grouped)) {
419
- output.writeln(output.highlight(cat.charAt(0).toUpperCase() + cat.slice(1)));
420
-
421
- output.printTable({
422
- columns: [
423
- { key: 'name', header: 'Tool', width: 25 },
424
- { key: 'description', header: 'Description', width: 35 },
425
- { key: 'enabled', header: 'Status', width: 10, format: (v: unknown) => (v as boolean) ? output.success('Enabled') : output.dim('Disabled') }
426
- ],
427
- data: catTools,
428
- border: false
429
- });
430
-
431
- output.writeln();
432
- }
433
-
434
- output.printInfo(`Total: ${tools.length} tools`);
435
-
436
- return { success: true, data: tools };
437
- }
438
- };
439
-
440
- // Enable/disable tools
441
- const toggleCommand: Command = {
442
- name: 'toggle',
443
- description: 'Enable or disable MCP tools',
444
- options: [
445
- {
446
- name: 'enable',
447
- short: 'e',
448
- description: 'Enable tools',
449
- type: 'string'
450
- },
451
- {
452
- name: 'disable',
453
- short: 'd',
454
- description: 'Disable tools',
455
- type: 'string'
456
- }
457
- ],
458
- action: async (ctx: CommandContext): Promise<CommandResult> => {
459
- const toEnable = ctx.flags.enable as string;
460
- const toDisable = ctx.flags.disable as string;
461
-
462
- if (toEnable) {
463
- const tools = toEnable.split(',');
464
- output.printInfo(`Enabling tools: ${tools.join(', ')}`);
465
- output.printSuccess(`Enabled ${tools.length} tools`);
466
- }
467
-
468
- if (toDisable) {
469
- const tools = toDisable.split(',');
470
- output.printInfo(`Disabling tools: ${tools.join(', ')}`);
471
- output.printSuccess(`Disabled ${tools.length} tools`);
472
- }
473
-
474
- if (!toEnable && !toDisable) {
475
- output.printError('Use --enable or --disable with comma-separated tool names');
476
- return { success: false, exitCode: 1 };
477
- }
478
-
479
- return { success: true };
480
- }
481
- };
482
-
483
- // Execute tool
484
- const execCommand: Command = {
485
- name: 'exec',
486
- description: 'Execute an MCP tool',
487
- options: [
488
- {
489
- name: 'tool',
490
- short: 't',
491
- description: 'Tool name',
492
- type: 'string',
493
- required: true
494
- },
495
- {
496
- name: 'params',
497
- short: 'p',
498
- description: 'Tool parameters (JSON)',
499
- type: 'string'
500
- }
501
- ],
502
- examples: [
503
- { command: 'claude-flow mcp exec -t swarm/init -p \'{"topology":"mesh"}\'', description: 'Execute tool' }
504
- ],
505
- action: async (ctx: CommandContext): Promise<CommandResult> => {
506
- const tool = ctx.flags.tool as string || ctx.args[0];
507
- const paramsStr = ctx.flags.params as string;
508
-
509
- if (!tool) {
510
- output.printError('Tool name is required. Use --tool or -t');
511
- return { success: false, exitCode: 1 };
512
- }
513
-
514
- let params = {};
515
- if (paramsStr) {
516
- try {
517
- params = JSON.parse(paramsStr);
518
- } catch (e) {
519
- output.printError('Invalid JSON parameters');
520
- return { success: false, exitCode: 1 };
521
- }
522
- }
523
-
524
- output.printInfo(`Executing tool: ${tool}`);
525
-
526
- if (Object.keys(params).length > 0) {
527
- output.writeln(output.dim(` Parameters: ${JSON.stringify(params)}`));
528
- }
529
-
530
- try {
531
- // Execute through local MCP tool registry
532
- if (!hasTool(tool)) {
533
- output.printError(`Tool not found: ${tool}`);
534
- return { success: false, exitCode: 1 };
535
- }
536
-
537
- const startTime = performance.now();
538
- const result = await callMCPTool(tool, params, {
539
- sessionId: `cli-${Date.now().toString(36)}`,
540
- requestId: `exec-${Date.now()}`,
541
- });
542
- const duration = performance.now() - startTime;
543
-
544
- output.writeln();
545
- output.printSuccess(`Tool executed in ${duration.toFixed(2)}ms`);
546
-
547
- if (ctx.flags.format === 'json') {
548
- output.printJson({ tool, params, result, duration });
549
- } else {
550
- output.writeln();
551
- output.writeln(output.bold('Result:'));
552
- output.printJson(result);
553
- }
554
-
555
- return { success: true, data: { tool, params, result, duration } };
556
- } catch (error) {
557
- output.printError(`Tool execution failed: ${(error as Error).message}`);
558
- return { success: false, exitCode: 1 };
559
- }
560
- }
561
- };
562
-
563
- // Health check command
564
- const healthCommand: Command = {
565
- name: 'health',
566
- description: 'Check MCP server health',
567
- action: async (ctx: CommandContext): Promise<CommandResult> => {
568
- try {
569
- const status = await getMCPServerStatus();
570
-
571
- if (!status.running) {
572
- output.printError('MCP Server is not running');
573
- return { success: false, exitCode: 1 };
574
- }
575
-
576
- const manager = getServerManager();
577
- const health = await manager.checkHealth();
578
-
579
- if (ctx.flags.format === 'json') {
580
- output.printJson(health);
581
- return { success: true, data: health };
582
- }
583
-
584
- output.writeln();
585
- output.writeln(output.bold('MCP Server Health'));
586
- output.writeln();
587
-
588
- if (health.healthy) {
589
- output.printSuccess('Server is healthy');
590
- } else {
591
- output.printError(`Server is unhealthy: ${health.error || 'Unknown error'}`);
592
- }
593
-
594
- if (health.metrics) {
595
- output.writeln();
596
- output.writeln(output.bold('Metrics:'));
597
- for (const [key, value] of Object.entries(health.metrics)) {
598
- output.writeln(` ${key}: ${value}`);
599
- }
600
- }
601
-
602
- return { success: health.healthy, data: health };
603
- } catch (error) {
604
- output.printError(`Health check failed: ${(error as Error).message}`);
605
- return { success: false, exitCode: 1 };
606
- }
607
- }
608
- };
609
-
610
- // Logs command
611
- const logsCommand: Command = {
612
- name: 'logs',
613
- description: 'Show MCP server logs',
614
- options: [
615
- {
616
- name: 'lines',
617
- short: 'n',
618
- description: 'Number of lines',
619
- type: 'number',
620
- default: 20
621
- },
622
- {
623
- name: 'follow',
624
- short: 'f',
625
- description: 'Follow log output',
626
- type: 'boolean',
627
- default: false
628
- },
629
- {
630
- name: 'level',
631
- description: 'Filter by log level',
632
- type: 'string',
633
- choices: ['debug', 'info', 'warn', 'error']
634
- }
635
- ],
636
- action: async (ctx: CommandContext): Promise<CommandResult> => {
637
- const lines = ctx.flags.lines as number;
638
-
639
- // Default logs (loaded from actual log file when available)
640
- const logs = [
641
- { time: new Date().toISOString(), level: 'info', message: 'MCP Server started on stdio' },
642
- { time: new Date().toISOString(), level: 'info', message: 'Registered 27 tools' },
643
- { time: new Date().toISOString(), level: 'debug', message: 'Received request: tools/list' },
644
- { time: new Date().toISOString(), level: 'info', message: 'Session initialized' },
645
- ].slice(-lines);
646
-
647
- output.writeln();
648
- output.writeln(output.bold('MCP Server Logs'));
649
- output.writeln();
650
-
651
- for (const log of logs) {
652
- let levelStr: string;
653
- switch (log.level) {
654
- case 'error':
655
- levelStr = output.error(log.level.toUpperCase().padEnd(5));
656
- break;
657
- case 'warn':
658
- levelStr = output.warning(log.level.toUpperCase().padEnd(5));
659
- break;
660
- case 'debug':
661
- levelStr = output.dim(log.level.toUpperCase().padEnd(5));
662
- break;
663
- default:
664
- levelStr = output.info(log.level.toUpperCase().padEnd(5));
665
- }
666
-
667
- output.writeln(`${output.dim(log.time)} ${levelStr} ${log.message}`);
668
- }
669
-
670
- return { success: true, data: logs };
671
- }
672
- };
673
-
674
- // Restart command
675
- const restartCommand: Command = {
676
- name: 'restart',
677
- description: 'Restart MCP server',
678
- options: [
679
- {
680
- name: 'force',
681
- short: 'f',
682
- description: 'Force restart without graceful shutdown',
683
- type: 'boolean',
684
- default: false
685
- }
686
- ],
687
- action: async (ctx: CommandContext): Promise<CommandResult> => {
688
- const force = ctx.flags.force as boolean;
689
-
690
- output.printInfo('Restarting MCP Server...');
691
-
692
- try {
693
- const manager = getServerManager();
694
- const status = await manager.restart();
695
-
696
- output.printSuccess('MCP Server restarted');
697
- output.writeln(output.dim(` PID: ${status.pid}`));
698
-
699
- return { success: true, data: status };
700
- } catch (error) {
701
- output.printError(`Failed to restart: ${(error as Error).message}`);
702
- return { success: false, exitCode: 1 };
703
- }
704
- }
705
- };
706
-
707
- // Main MCP command
708
- export const mcpCommand: Command = {
709
- name: 'mcp',
710
- description: 'MCP server management',
711
- subcommands: [
712
- startCommand,
713
- stopCommand,
714
- statusCommand,
715
- healthCommand,
716
- restartCommand,
717
- toolsCommand,
718
- toggleCommand,
719
- execCommand,
720
- logsCommand
721
- ],
722
- options: [],
723
- examples: [
724
- { command: 'claude-flow mcp start', description: 'Start MCP server' },
725
- { command: 'claude-flow mcp start -t http -p 8080', description: 'Start HTTP server on port 8080' },
726
- { command: 'claude-flow mcp status', description: 'Show server status' },
727
- { command: 'claude-flow mcp tools', description: 'List tools' },
728
- { command: 'claude-flow mcp stop', description: 'Stop the server' }
729
- ],
730
- action: async (ctx: CommandContext): Promise<CommandResult> => {
731
- output.writeln();
732
- output.writeln(output.bold('MCP Server Management'));
733
- output.writeln();
734
- output.writeln('Usage: claude-flow mcp <subcommand> [options]');
735
- output.writeln();
736
- output.writeln('Subcommands:');
737
- output.printList([
738
- `${output.highlight('start')} - Start MCP server`,
739
- `${output.highlight('stop')} - Stop MCP server`,
740
- `${output.highlight('status')} - Show server status`,
741
- `${output.highlight('health')} - Check server health`,
742
- `${output.highlight('restart')} - Restart MCP server`,
743
- `${output.highlight('tools')} - List available tools`,
744
- `${output.highlight('toggle')} - Enable/disable tools`,
745
- `${output.highlight('exec')} - Execute a tool`,
746
- `${output.highlight('logs')} - Show server logs`
747
- ]);
748
-
749
- return { success: true };
750
- }
751
- };
752
-
753
- export default mcpCommand;