snow-flow 2.0.2 → 2.0.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.
Files changed (173) hide show
  1. package/{.claude/mcp-config.json → .mcp.json} +13 -12
  2. package/.releaserc.json +47 -0
  3. package/README.md +48 -1
  4. package/package.json +1 -1
  5. package/.claude/claude-settings.json +0 -15
  6. package/.claude/commands/analysis/README.md +0 -9
  7. package/.claude/commands/automation/README.md +0 -9
  8. package/.claude/commands/github/README.md +0 -11
  9. package/.claude/commands/helpers/standard-checkpoint-hooks.sh +0 -179
  10. package/.claude/commands/hooks/README.md +0 -11
  11. package/.claude/commands/monitoring/README.md +0 -9
  12. package/.claude/commands/optimization/README.md +0 -9
  13. package/.claude/commands/training/README.md +0 -9
  14. package/.claude/commands/workflows/README.md +0 -9
  15. package/.claude/config.json +0 -36
  16. package/.claude/helpers/github-setup.sh +0 -28
  17. package/.claude/helpers/quick-start.sh +0 -19
  18. package/.claude/helpers/setup-mcp.sh +0 -18
  19. package/.claude/settings.json +0 -114
  20. package/.claude/settings.local.json +0 -33
  21. package/.claude-flow/metrics/agent-metrics.json +0 -1
  22. package/.claude-flow/metrics/performance.json +0 -9
  23. package/.claude-flow/metrics/system-metrics.json +0 -15986
  24. package/.claude-flow/metrics/task-metrics.json +0 -10
  25. package/.roo/README.md +0 -402
  26. package/.roo/mcp-list.txt +0 -257
  27. package/.roo/mcp.json +0 -32
  28. package/.roo/workflows/basic-tdd.json +0 -32
  29. package/.roomodes +0 -201
  30. package/CLAUDE.md +0 -393
  31. package/bin/snow-flow.js +0 -3
  32. package/dist/cli.js.bak +0 -2052
  33. package/dist/config/snow-flow-config.d.ts +0 -1492
  34. package/dist/config/snow-flow-config.js +0 -938
  35. package/scripts/create-env.js +0 -91
  36. package/scripts/postinstall.js +0 -30
  37. package/scripts/register-mcp-servers.js +0 -210
  38. package/scripts/reset-mcp-servers.js +0 -246
  39. package/scripts/setup-mcp.js +0 -106
  40. package/scripts/update-version.js +0 -31
  41. package/src/agents/README.md +0 -192
  42. package/src/agents/base-agent.ts +0 -251
  43. package/src/agents/coordinator.ts +0 -971
  44. package/src/agents/index.ts +0 -18
  45. package/src/agents/queen-403-handler.ts +0 -230
  46. package/src/agents/queen-agent.ts +0 -1399
  47. package/src/agents/script-writer-agent.ts +0 -769
  48. package/src/agents/security-agent.ts +0 -726
  49. package/src/agents/widget-creator-agent.ts +0 -568
  50. package/src/api/error-handling.ts +0 -1758
  51. package/src/api/natural-language-mapper.ts +0 -630
  52. package/src/api/performance-optimizer.ts +0 -891
  53. package/src/api/transaction-manager.ts +0 -754
  54. package/src/cli/deploy-artifact.ts +0 -304
  55. package/src/cli/snow-flow-cli-integration.ts +0 -434
  56. package/src/cli.ts +0 -4455
  57. package/src/cli.ts.bak +0 -5616
  58. package/src/compliance/advanced-compliance-system.ts +0 -1268
  59. package/src/compliance/index.ts +0 -19
  60. package/src/config/snow-flow-config.ts +0 -1019
  61. package/src/documentation/index.ts +0 -16
  62. package/src/documentation/self-documenting-system.ts +0 -1421
  63. package/src/dynamic-version.ts +0 -44
  64. package/src/healing/index.ts +0 -20
  65. package/src/healing/self-healing-system.ts +0 -1435
  66. package/src/health/README.md +0 -161
  67. package/src/health/system-health.ts +0 -995
  68. package/src/index.ts +0 -60
  69. package/src/intelligence/acl-analyzer.ts +0 -377
  70. package/src/intelligence/auto-resolution-engine.ts +0 -643
  71. package/src/intelligence/gap-analysis-engine.ts +0 -488
  72. package/src/intelligence/manual-instructions-generator.ts +0 -744
  73. package/src/intelligence/mcp-coverage-analyzer.ts +0 -708
  74. package/src/intelligence/multi-pass-requirements-analyzer.ts +0 -603
  75. package/src/intelligence/performance-recommendations-engine.ts +0 -1223
  76. package/src/intelligence/requirements-analyzer.ts +0 -1148
  77. package/src/intelligence/task-analyzer.ts +0 -628
  78. package/src/managers/scope-manager.ts +0 -555
  79. package/src/mcp/advanced/servicenow-advanced-features-mcp.ts +0 -16110
  80. package/src/mcp/base-mcp-server.ts +0 -660
  81. package/src/mcp/http-transport-wrapper.ts +0 -426
  82. package/src/mcp/service-discovery-client.ts +0 -312
  83. package/src/mcp/servicenow-automation-mcp-refactored.ts +0 -678
  84. package/src/mcp/servicenow-automation-mcp.ts +0 -838
  85. package/src/mcp/servicenow-deployment-mcp-refactored.ts +0 -1292
  86. package/src/mcp/servicenow-deployment-mcp.ts +0 -7244
  87. package/src/mcp/servicenow-graph-memory-mcp-refactored.ts +0 -721
  88. package/src/mcp/servicenow-graph-memory-mcp.ts +0 -832
  89. package/src/mcp/servicenow-integration-mcp-refactored.ts +0 -655
  90. package/src/mcp/servicenow-integration-mcp.ts +0 -819
  91. package/src/mcp/servicenow-intelligent-mcp-refactored.ts +0 -977
  92. package/src/mcp/servicenow-intelligent-mcp.ts +0 -4638
  93. package/src/mcp/servicenow-mcp-server.ts +0 -728
  94. package/src/mcp/servicenow-memory-mcp.ts +0 -474
  95. package/src/mcp/servicenow-operations-mcp-refactored.ts +0 -1995
  96. package/src/mcp/servicenow-operations-mcp.ts +0 -3384
  97. package/src/mcp/servicenow-platform-development-mcp-refactored.ts +0 -611
  98. package/src/mcp/servicenow-platform-development-mcp.ts +0 -970
  99. package/src/mcp/servicenow-progressive-indexer.ts +0 -370
  100. package/src/mcp/servicenow-reporting-analytics-mcp-refactored.ts +0 -695
  101. package/src/mcp/servicenow-reporting-analytics-mcp.ts +0 -1123
  102. package/src/mcp/servicenow-security-compliance-mcp-refactored.ts +0 -642
  103. package/src/mcp/servicenow-security-compliance-mcp.ts +0 -1157
  104. package/src/mcp/servicenow-update-set-mcp-refactored.ts +0 -751
  105. package/src/mcp/servicenow-update-set-mcp.ts +0 -811
  106. package/src/mcp/shared/agent-context-provider.ts +0 -365
  107. package/src/mcp/shared/base-mcp-server.ts +0 -2463
  108. package/src/mcp/shared/mcp-memory-manager.ts +0 -540
  109. package/src/mcp/shared/mcp-resource-manager.ts +0 -367
  110. package/src/mcp/snow-flow-mcp.ts +0 -911
  111. package/src/mcp/start-all-mcp-servers.ts +0 -102
  112. package/src/mcp/start-servicenow-mcp.ts +0 -67
  113. package/src/monitoring/enhanced-monitoring-system.ts +0 -1345
  114. package/src/monitoring/performance-tracker.ts +0 -777
  115. package/src/optimization/cost-optimization-engine.ts +0 -1125
  116. package/src/optimization/index.ts +0 -10
  117. package/src/queen/README.md +0 -403
  118. package/src/queen/agent-factory.ts +0 -574
  119. package/src/queen/index.ts +0 -94
  120. package/src/queen/mcp-execution-bridge.ts +0 -681
  121. package/src/queen/neural-learning.ts +0 -319
  122. package/src/queen/parallel-agent-engine.ts +0 -848
  123. package/src/queen/queen-memory-system.ts +0 -490
  124. package/src/queen/queen-memory.ts +0 -456
  125. package/src/queen/servicenow-queen.ts +0 -1029
  126. package/src/queen/types.ts +0 -87
  127. package/src/rollback/smart-rollback-system.ts +0 -866
  128. package/src/schemas/deployment.schema.json +0 -58
  129. package/src/schemas/flow.schema.json +0 -79
  130. package/src/schemas/widget.schema.json +0 -72
  131. package/src/snow-flow-system.ts +0 -541
  132. package/src/sparc/sparc-help.ts +0 -49
  133. package/src/sparc/team-sparc.ts +0 -88
  134. package/src/strategies/global-scope-strategy.ts +0 -736
  135. package/src/templates/base/application.template.json +0 -45
  136. package/src/templates/base/business_rule.template.json +0 -33
  137. package/src/templates/base/script_include.template.json +0 -18
  138. package/src/templates/base/table.template.json +0 -64
  139. package/src/templates/base/widget.template.json +0 -25
  140. package/src/templates/patterns/composite.incident-management.template.json +0 -140
  141. package/src/templates/patterns/widget.dashboard.template.json +0 -238
  142. package/src/templates/patterns/widget.datatable.template.json +0 -292
  143. package/src/testing/integration-test-suite.ts +0 -1276
  144. package/src/types/index.ts +0 -183
  145. package/src/types/neo4j-driver.d.ts +0 -23
  146. package/src/types/servicenow.types.ts +0 -307
  147. package/src/types/snow-flow.types.ts +0 -186
  148. package/src/types/todo.types.ts +0 -70
  149. package/src/utils/action-type-cache.ts +0 -286
  150. package/src/utils/agent-detector.ts +0 -573
  151. package/src/utils/artifact-tracker.ts +0 -379
  152. package/src/utils/dependency-detector.ts +0 -233
  153. package/src/utils/deployment-metadata-handler.ts +0 -518
  154. package/src/utils/error-recovery.ts +0 -680
  155. package/src/utils/logger.ts +0 -60
  156. package/src/utils/mcp-auth-middleware.ts +0 -262
  157. package/src/utils/mcp-config-manager.ts +0 -270
  158. package/src/utils/mcp-server-manager.ts +0 -446
  159. package/src/utils/mcp-tool-registry.ts +0 -298
  160. package/src/utils/migrate-snow-flow.ts +0 -98
  161. package/src/utils/oauth-html-templates.ts +0 -188
  162. package/src/utils/scope-utils.ts +0 -443
  163. package/src/utils/servicenow-client.ts +0 -3321
  164. package/src/utils/servicenow-id-generator.ts +0 -181
  165. package/src/utils/snow-memory-manager.ts +0 -605
  166. package/src/utils/snow-oauth.ts +0 -797
  167. package/src/utils/template-engine.ts +0 -463
  168. package/src/utils/theme-manager.ts +0 -295
  169. package/src/utils/unified-auth-store.ts +0 -222
  170. package/src/utils/update-set-importer.ts +0 -422
  171. package/src/utils/update-set-xml-packager.ts +0 -371
  172. package/src/utils/widget-template-generator.ts +0 -1744
  173. package/src/version.ts +0 -1950
@@ -1,911 +0,0 @@
1
- /**
2
- * Snow-Flow MCP Server
3
- * Provides coordination tools for multi-agent orchestration
4
- */
5
-
6
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
- import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
- import {
9
- CallToolRequestSchema,
10
- ListToolsRequestSchema,
11
- Tool,
12
- } from '@modelcontextprotocol/sdk/types.js';
13
-
14
- interface Agent {
15
- id: string;
16
- type: string;
17
- name: string;
18
- status: 'idle' | 'busy' | 'completed';
19
- capabilities: string[];
20
- createdAt: Date;
21
- }
22
-
23
- interface Swarm {
24
- id: string;
25
- topology: 'hierarchical' | 'mesh' | 'ring' | 'star';
26
- maxAgents: number;
27
- strategy: string;
28
- agents: Agent[];
29
- status: 'initializing' | 'active' | 'completed';
30
- createdAt: Date;
31
- }
32
-
33
- interface Task {
34
- id: string;
35
- description: string;
36
- status: 'pending' | 'in_progress' | 'completed';
37
- assignedAgent?: string;
38
- result?: any;
39
- createdAt: Date;
40
- }
41
-
42
- interface Memory {
43
- [key: string]: any;
44
- }
45
-
46
- class SnowFlowMCPServer {
47
- private server: Server;
48
- private swarms: Map<string, Swarm> = new Map();
49
- private agents: Map<string, Agent> = new Map();
50
- private tasks: Map<string, Task> = new Map();
51
- private memory: Memory = {};
52
- private neuralModels: Map<string, any> = new Map();
53
-
54
- constructor() {
55
- this.server = new Server(
56
- {
57
- name: 'snow-flow',
58
- version: '1.0.0',
59
- },
60
- {
61
- capabilities: {
62
- tools: {},
63
- },
64
- }
65
- );
66
-
67
- this.setupToolHandlers();
68
- }
69
-
70
- private setupToolHandlers() {
71
- // List tools handler
72
- this.server.setRequestHandler(ListToolsRequestSchema, async () => {
73
- const tools: Tool[] = [
74
- // Swarm Management
75
- {
76
- name: 'swarm_init',
77
- description: 'Initialize swarm with topology and configuration',
78
- inputSchema: {
79
- type: 'object',
80
- properties: {
81
- topology: {
82
- type: 'string',
83
- enum: ['hierarchical', 'mesh', 'ring', 'star'],
84
- },
85
- maxAgents: {
86
- type: 'number',
87
- default: 8,
88
- },
89
- strategy: {
90
- type: 'string',
91
- default: 'auto',
92
- },
93
- },
94
- required: ['topology'],
95
- },
96
- },
97
- {
98
- name: 'agent_spawn',
99
- description: 'Create specialized AI agents',
100
- inputSchema: {
101
- type: 'object',
102
- properties: {
103
- type: {
104
- type: 'string',
105
- enum: [
106
- 'coordinator',
107
- 'researcher',
108
- 'coder',
109
- 'analyst',
110
- 'architect',
111
- 'tester',
112
- 'reviewer',
113
- 'optimizer',
114
- 'documenter',
115
- 'monitor',
116
- 'specialist',
117
- ],
118
- },
119
- name: {
120
- type: 'string',
121
- },
122
- capabilities: {
123
- type: 'array',
124
- },
125
- swarmId: {
126
- type: 'string',
127
- },
128
- },
129
- required: ['type'],
130
- },
131
- },
132
- {
133
- name: 'task_orchestrate',
134
- description: 'Orchestrate complex task workflows',
135
- inputSchema: {
136
- type: 'object',
137
- properties: {
138
- task: {
139
- type: 'string',
140
- },
141
- strategy: {
142
- type: 'string',
143
- enum: ['parallel', 'sequential', 'adaptive', 'balanced'],
144
- },
145
- priority: {
146
- type: 'string',
147
- enum: ['low', 'medium', 'high', 'critical'],
148
- },
149
- dependencies: {
150
- type: 'array',
151
- },
152
- },
153
- required: ['task'],
154
- },
155
- },
156
- {
157
- name: 'swarm_status',
158
- description: 'Monitor swarm health and performance',
159
- inputSchema: {
160
- type: 'object',
161
- properties: {
162
- swarmId: {
163
- type: 'string',
164
- },
165
- },
166
- },
167
- },
168
- // Neural & Memory
169
- {
170
- name: 'neural_status',
171
- description: 'Check neural network status',
172
- inputSchema: {
173
- type: 'object',
174
- properties: {
175
- modelId: {
176
- type: 'string',
177
- },
178
- },
179
- },
180
- },
181
- {
182
- name: 'neural_train',
183
- description: 'Train neural patterns with WASM SIMD acceleration',
184
- inputSchema: {
185
- type: 'object',
186
- properties: {
187
- pattern_type: {
188
- type: 'string',
189
- enum: ['coordination', 'optimization', 'prediction'],
190
- },
191
- training_data: {
192
- type: 'string',
193
- },
194
- epochs: {
195
- type: 'number',
196
- default: 50,
197
- },
198
- },
199
- required: ['pattern_type', 'training_data'],
200
- },
201
- },
202
- {
203
- name: 'neural_patterns',
204
- description: 'Analyze cognitive patterns',
205
- inputSchema: {
206
- type: 'object',
207
- properties: {
208
- action: {
209
- type: 'string',
210
- enum: ['analyze', 'learn', 'predict'],
211
- },
212
- operation: {
213
- type: 'string',
214
- },
215
- outcome: {
216
- type: 'string',
217
- },
218
- metadata: {
219
- type: 'object',
220
- },
221
- },
222
- required: ['action'],
223
- },
224
- },
225
- {
226
- name: 'memory_usage',
227
- description: 'Store/retrieve persistent memory with TTL and namespacing',
228
- inputSchema: {
229
- type: 'object',
230
- properties: {
231
- action: {
232
- type: 'string',
233
- enum: ['store', 'retrieve', 'list', 'delete', 'search'],
234
- },
235
- key: {
236
- type: 'string',
237
- },
238
- value: {
239
- type: 'string',
240
- },
241
- namespace: {
242
- type: 'string',
243
- default: 'default',
244
- },
245
- ttl: {
246
- type: 'number',
247
- },
248
- },
249
- required: ['action'],
250
- },
251
- },
252
- {
253
- name: 'memory_search',
254
- description: 'Search memory with patterns',
255
- inputSchema: {
256
- type: 'object',
257
- properties: {
258
- pattern: {
259
- type: 'string',
260
- },
261
- namespace: {
262
- type: 'string',
263
- },
264
- limit: {
265
- type: 'number',
266
- default: 10,
267
- },
268
- },
269
- required: ['pattern'],
270
- },
271
- },
272
- // Performance & Monitoring
273
- {
274
- name: 'performance_report',
275
- description: 'Generate performance reports with real-time metrics',
276
- inputSchema: {
277
- type: 'object',
278
- properties: {
279
- format: {
280
- type: 'string',
281
- enum: ['summary', 'detailed', 'json'],
282
- default: 'summary',
283
- },
284
- timeframe: {
285
- type: 'string',
286
- enum: ['24h', '7d', '30d'],
287
- default: '24h',
288
- },
289
- },
290
- },
291
- },
292
- {
293
- name: 'token_usage',
294
- description: 'Analyze token consumption',
295
- inputSchema: {
296
- type: 'object',
297
- properties: {
298
- operation: {
299
- type: 'string',
300
- },
301
- timeframe: {
302
- type: 'string',
303
- default: '24h',
304
- },
305
- },
306
- },
307
- },
308
- ];
309
-
310
- return { tools };
311
- });
312
-
313
- // Call tool handler
314
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
315
- const { name, arguments: args } = request.params;
316
-
317
- try {
318
- switch (name) {
319
- case 'swarm_init':
320
- return await this.handleSwarmInit(args);
321
- case 'agent_spawn':
322
- return await this.handleAgentSpawn(args);
323
- case 'task_orchestrate':
324
- return await this.handleTaskOrchestrate(args);
325
- case 'swarm_status':
326
- return await this.handleSwarmStatus(args);
327
- case 'memory_usage':
328
- return await this.handleMemoryUsage(args);
329
- case 'memory_search':
330
- return await this.handleMemorySearch(args);
331
- case 'neural_train':
332
- return await this.handleNeuralTrain(args);
333
- case 'neural_patterns':
334
- return await this.handleNeuralPatterns(args);
335
- case 'performance_report':
336
- return await this.handlePerformanceReport(args);
337
- case 'neural_status':
338
- return await this.handleNeuralStatus(args);
339
- case 'token_usage':
340
- return await this.handleTokenUsage(args);
341
- default:
342
- return {
343
- content: [
344
- {
345
- type: 'text',
346
- text: JSON.stringify({
347
- error: `Tool ${name} not implemented yet`,
348
- status: 'not_implemented',
349
- }),
350
- },
351
- ],
352
- };
353
- }
354
- } catch (error: any) {
355
- return {
356
- content: [
357
- {
358
- type: 'text',
359
- text: JSON.stringify({
360
- error: error.message,
361
- status: 'error',
362
- }),
363
- },
364
- ],
365
- };
366
- }
367
- });
368
- }
369
-
370
- private async handleSwarmInit(args: any) {
371
- const swarmId = `swarm_${Date.now()}`;
372
- const swarm: Swarm = {
373
- id: swarmId,
374
- topology: args.topology,
375
- maxAgents: args.maxAgents || 8,
376
- strategy: args.strategy || 'auto',
377
- agents: [],
378
- status: 'initializing',
379
- createdAt: new Date(),
380
- };
381
-
382
- this.swarms.set(swarmId, swarm);
383
-
384
- // Initialize coordinator agent automatically
385
- const coordinator: Agent = {
386
- id: `agent_${Date.now()}_coordinator`,
387
- type: 'coordinator',
388
- name: 'Swarm Coordinator',
389
- status: 'idle',
390
- capabilities: ['coordination', 'task_distribution', 'monitoring'],
391
- createdAt: new Date(),
392
- };
393
-
394
- this.agents.set(coordinator.id, coordinator);
395
- swarm.agents.push(coordinator);
396
- swarm.status = 'active';
397
-
398
- return {
399
- content: [
400
- {
401
- type: 'text',
402
- text: JSON.stringify({
403
- swarmId,
404
- topology: swarm.topology,
405
- maxAgents: swarm.maxAgents,
406
- strategy: swarm.strategy,
407
- coordinator: coordinator.id,
408
- status: 'active',
409
- message: `Swarm initialized with ${swarm.topology} topology`,
410
- }),
411
- },
412
- ],
413
- };
414
- }
415
-
416
- private async handleAgentSpawn(args: any) {
417
- const agentId = `agent_${Date.now()}_${args.type}`;
418
- const agent: Agent = {
419
- id: agentId,
420
- type: args.type,
421
- name: args.name || `${args.type.charAt(0).toUpperCase() + args.type.slice(1)} Agent`,
422
- status: 'idle',
423
- capabilities: args.capabilities || this.getDefaultCapabilities(args.type),
424
- createdAt: new Date(),
425
- };
426
-
427
- this.agents.set(agentId, agent);
428
-
429
- // Add to swarm if specified
430
- if (args.swarmId && this.swarms.has(args.swarmId)) {
431
- const swarm = this.swarms.get(args.swarmId)!;
432
- swarm.agents.push(agent);
433
- }
434
-
435
- return {
436
- content: [
437
- {
438
- type: 'text',
439
- text: JSON.stringify({
440
- agentId,
441
- type: agent.type,
442
- name: agent.name,
443
- capabilities: agent.capabilities,
444
- status: 'spawned',
445
- message: `Agent ${agent.name} spawned successfully`,
446
- }),
447
- },
448
- ],
449
- };
450
- }
451
-
452
- private async handleTaskOrchestrate(args: any) {
453
- const taskId = `task_${Date.now()}`;
454
- const task: Task = {
455
- id: taskId,
456
- description: args.task,
457
- status: 'pending',
458
- createdAt: new Date(),
459
- };
460
-
461
- this.tasks.set(taskId, task);
462
-
463
- // Simulate task orchestration
464
- task.status = 'in_progress';
465
-
466
- // Find available agent
467
- const availableAgent = Array.from(this.agents.values()).find((a) => a.status === 'idle');
468
- if (availableAgent) {
469
- task.assignedAgent = availableAgent.id;
470
- availableAgent.status = 'busy';
471
- }
472
-
473
- return {
474
- content: [
475
- {
476
- type: 'text',
477
- text: JSON.stringify({
478
- taskId,
479
- task: task.description,
480
- strategy: args.strategy || 'adaptive',
481
- priority: args.priority || 'medium',
482
- status: 'orchestrating',
483
- assignedAgent: task.assignedAgent,
484
- message: 'Task orchestration initiated',
485
- }),
486
- },
487
- ],
488
- };
489
- }
490
-
491
- private async handleSwarmStatus(args: any) {
492
- const swarmId = args.swarmId;
493
-
494
- if (!swarmId) {
495
- // Return all swarms status
496
- const allSwarms = Array.from(this.swarms.entries()).map(([id, swarm]) => ({
497
- id,
498
- topology: swarm.topology,
499
- agents: swarm.agents.length,
500
- maxAgents: swarm.maxAgents,
501
- status: swarm.status,
502
- }));
503
-
504
- return {
505
- content: [
506
- {
507
- type: 'text',
508
- text: JSON.stringify({
509
- swarms: allSwarms,
510
- totalSwarms: allSwarms.length,
511
- activeSwarms: allSwarms.filter((s) => s.status === 'active').length,
512
- }),
513
- },
514
- ],
515
- };
516
- }
517
-
518
- const swarm = this.swarms.get(swarmId);
519
- if (!swarm) {
520
- throw new Error(`Swarm ${swarmId} not found`);
521
- }
522
-
523
- return {
524
- content: [
525
- {
526
- type: 'text',
527
- text: JSON.stringify({
528
- swarmId,
529
- topology: swarm.topology,
530
- agents: swarm.agents.map((a) => ({
531
- id: a.id,
532
- type: a.type,
533
- name: a.name,
534
- status: a.status,
535
- })),
536
- totalAgents: swarm.agents.length,
537
- maxAgents: swarm.maxAgents,
538
- status: swarm.status,
539
- uptime: Date.now() - swarm.createdAt.getTime(),
540
- }),
541
- },
542
- ],
543
- };
544
- }
545
-
546
- private async handleMemoryUsage(args: any) {
547
- const { action, key, value, namespace = 'default' } = args;
548
- const memoryKey = `${namespace}:${key}`;
549
-
550
- switch (action) {
551
- case 'store': {
552
- this.memory[memoryKey] = {
553
- value,
554
- timestamp: Date.now(),
555
- ttl: args.ttl,
556
- };
557
- return {
558
- content: [
559
- {
560
- type: 'text',
561
- text: JSON.stringify({
562
- action: 'stored',
563
- key: memoryKey,
564
- status: 'success',
565
- }),
566
- },
567
- ],
568
- };
569
- }
570
-
571
- case 'retrieve': {
572
- const data = this.memory[memoryKey];
573
- if (!data) {
574
- return {
575
- content: [
576
- {
577
- type: 'text',
578
- text: JSON.stringify({
579
- action: 'retrieve',
580
- key: memoryKey,
581
- value: null,
582
- status: 'not_found',
583
- }),
584
- },
585
- ],
586
- };
587
- }
588
- return {
589
- content: [
590
- {
591
- type: 'text',
592
- text: JSON.stringify({
593
- action: 'retrieve',
594
- key: memoryKey,
595
- value: data.value,
596
- timestamp: data.timestamp,
597
- status: 'success',
598
- }),
599
- },
600
- ],
601
- };
602
- }
603
-
604
- case 'list': {
605
- const keys = Object.keys(this.memory).filter((k) => k.startsWith(namespace));
606
- return {
607
- content: [
608
- {
609
- type: 'text',
610
- text: JSON.stringify({
611
- action: 'list',
612
- namespace,
613
- keys,
614
- count: keys.length,
615
- status: 'success',
616
- }),
617
- },
618
- ],
619
- };
620
- }
621
-
622
- case 'delete': {
623
- delete this.memory[memoryKey];
624
- return {
625
- content: [
626
- {
627
- type: 'text',
628
- text: JSON.stringify({
629
- action: 'deleted',
630
- key: memoryKey,
631
- status: 'success',
632
- }),
633
- },
634
- ],
635
- };
636
- }
637
-
638
- default:
639
- throw new Error(`Unknown memory action: ${action}`);
640
- }
641
- }
642
-
643
- private async handleMemorySearch(args: any) {
644
- const { pattern, namespace = 'default', limit = 10 } = args;
645
- const regex = new RegExp(pattern, 'i');
646
-
647
- const matches = Object.entries(this.memory)
648
- .filter(([key, data]) => {
649
- if (namespace && !key.startsWith(namespace)) return false;
650
- return regex.test(key) || regex.test(JSON.stringify(data.value));
651
- })
652
- .slice(0, limit)
653
- .map(([key, data]) => ({
654
- key,
655
- value: data.value,
656
- timestamp: data.timestamp,
657
- }));
658
-
659
- return {
660
- content: [
661
- {
662
- type: 'text',
663
- text: JSON.stringify({
664
- pattern,
665
- namespace,
666
- matches,
667
- count: matches.length,
668
- status: 'success',
669
- }),
670
- },
671
- ],
672
- };
673
- }
674
-
675
- private async handleNeuralTrain(args: any) {
676
- const { pattern_type, epochs = 50 } = args;
677
- const modelId = `model_${pattern_type}_${Date.now()}`;
678
-
679
- // Simulate neural training
680
- const model = {
681
- id: modelId,
682
- type: pattern_type,
683
- epochs,
684
- accuracy: 0.85 + Math.random() * 0.1,
685
- loss: 0.15 - Math.random() * 0.05,
686
- trainedAt: new Date(),
687
- };
688
-
689
- this.neuralModels.set(modelId, model);
690
-
691
- return {
692
- content: [
693
- {
694
- type: 'text',
695
- text: JSON.stringify({
696
- modelId,
697
- pattern_type,
698
- epochs,
699
- accuracy: model.accuracy.toFixed(3),
700
- loss: model.loss.toFixed(3),
701
- status: 'trained',
702
- message: `Model trained successfully with ${epochs} epochs`,
703
- }),
704
- },
705
- ],
706
- };
707
- }
708
-
709
- private async handleNeuralPatterns(args: any) {
710
- const { action, operation, outcome } = args;
711
-
712
- switch (action) {
713
- case 'analyze':
714
- return {
715
- content: [
716
- {
717
- type: 'text',
718
- text: JSON.stringify({
719
- action: 'analyze',
720
- patterns: [
721
- 'coordination_efficiency: 87%',
722
- 'task_distribution: balanced',
723
- 'agent_utilization: 76%',
724
- 'bottlenecks: none detected',
725
- ],
726
- recommendations: [
727
- 'Consider adding more specialized agents',
728
- 'Optimize task queuing algorithm',
729
- ],
730
- status: 'analyzed',
731
- }),
732
- },
733
- ],
734
- };
735
-
736
- case 'learn':
737
- return {
738
- content: [
739
- {
740
- type: 'text',
741
- text: JSON.stringify({
742
- action: 'learn',
743
- operation,
744
- outcome,
745
- learned: true,
746
- confidence: 0.92,
747
- status: 'learned',
748
- }),
749
- },
750
- ],
751
- };
752
-
753
- case 'predict':
754
- return {
755
- content: [
756
- {
757
- type: 'text',
758
- text: JSON.stringify({
759
- action: 'predict',
760
- prediction: 'Task will complete successfully',
761
- confidence: 0.88,
762
- factors: ['agent availability', 'task complexity', 'historical performance'],
763
- status: 'predicted',
764
- }),
765
- },
766
- ],
767
- };
768
-
769
- default:
770
- throw new Error(`Unknown neural action: ${action}`);
771
- }
772
- }
773
-
774
- private async handlePerformanceReport(args: any) {
775
- const { format = 'summary', timeframe = '24h' } = args;
776
-
777
- const report = {
778
- timeframe,
779
- metrics: {
780
- totalTasks: this.tasks.size,
781
- completedTasks: Array.from(this.tasks.values()).filter((t) => t.status === 'completed')
782
- .length,
783
- activeAgents: Array.from(this.agents.values()).filter((a) => a.status === 'busy').length,
784
- totalAgents: this.agents.size,
785
- activeSwarms: Array.from(this.swarms.values()).filter((s) => s.status === 'active').length,
786
- averageTaskTime: '2.3 minutes',
787
- successRate: '94.2%',
788
- },
789
- performance: {
790
- cpu_usage: '23%',
791
- memory_usage: '512MB',
792
- token_usage: '45,231',
793
- api_calls: '1,234',
794
- },
795
- };
796
-
797
- if (format === 'detailed') {
798
- report['taskBreakdown'] = Array.from(this.tasks.values()).map((t) => ({
799
- id: t.id,
800
- description: t.description,
801
- status: t.status,
802
- duration: t.status === 'completed' ? '2.1 min' : 'ongoing',
803
- }));
804
- }
805
-
806
- return {
807
- content: [
808
- {
809
- type: 'text',
810
- text: JSON.stringify(report),
811
- },
812
- ],
813
- };
814
- }
815
-
816
- private async handleNeuralStatus(args: any) {
817
- const { modelId } = args;
818
-
819
- // Simulate neural network status
820
- const status = {
821
- modelId: modelId || 'default-model',
822
- status: 'active',
823
- accuracy: 94.5,
824
- lastTrained: new Date(Date.now() - 3600000).toISOString(), // 1 hour ago
825
- totalPatterns: 1250,
826
- activeNeurons: 8192,
827
- performance: {
828
- inferenceTime: '12ms',
829
- trainingSpeed: '1000 patterns/sec',
830
- memoryUsage: '256MB'
831
- },
832
- capabilities: ['coordination', 'optimization', 'prediction'],
833
- health: 'optimal'
834
- };
835
-
836
- return {
837
- content: [
838
- {
839
- type: 'text',
840
- text: JSON.stringify(status),
841
- },
842
- ],
843
- };
844
- }
845
-
846
- private async handleTokenUsage(args: any) {
847
- const { operation, timeframe = '24h' } = args;
848
-
849
- // Simulate token usage data
850
- const usage = {
851
- timeframe,
852
- operation: operation || 'all',
853
- totalTokens: 145231,
854
- breakdown: {
855
- swarm_operations: 45231,
856
- neural_training: 32000,
857
- memory_operations: 15000,
858
- task_orchestration: 28000,
859
- performance_analysis: 25000
860
- },
861
- costEstimate: '$2.45',
862
- efficiency: {
863
- tokensPerOperation: 342,
864
- cachingEnabled: true,
865
- compressionRatio: 1.8
866
- },
867
- recommendations: [
868
- 'Enable batch operations to reduce token usage by 30%',
869
- 'Use memory caching for repeated queries',
870
- 'Consider smaller models for simple tasks'
871
- ]
872
- };
873
-
874
- return {
875
- content: [
876
- {
877
- type: 'text',
878
- text: JSON.stringify(usage),
879
- },
880
- ],
881
- };
882
- }
883
-
884
- private getDefaultCapabilities(type: string): string[] {
885
- const capabilities: { [key: string]: string[] } = {
886
- coordinator: ['task_distribution', 'monitoring', 'coordination'],
887
- researcher: ['information_gathering', 'analysis', 'summarization'],
888
- coder: ['implementation', 'debugging', 'optimization'],
889
- analyst: ['data_analysis', 'pattern_recognition', 'reporting'],
890
- architect: ['system_design', 'planning', 'documentation'],
891
- tester: ['testing', 'validation', 'quality_assurance'],
892
- reviewer: ['code_review', 'best_practices', 'feedback'],
893
- optimizer: ['performance_tuning', 'efficiency', 'scaling'],
894
- documenter: ['documentation', 'examples', 'tutorials'],
895
- monitor: ['monitoring', 'alerting', 'logging'],
896
- specialist: ['domain_expertise', 'problem_solving', 'innovation'],
897
- };
898
-
899
- return capabilities[type] || ['general_purpose'];
900
- }
901
-
902
- async run() {
903
- const transport = new StdioServerTransport();
904
- await this.server.connect(transport);
905
- console.error('Snow-Flow MCP server running on stdio');
906
- }
907
- }
908
-
909
- // Run the server
910
- const server = new SnowFlowMCPServer();
911
- server.run().catch(console.error);