claude-flow-novice 1.5.12 → 1.5.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.
- package/.claude/agents/analysis/code-review/analyze-code-quality.md +160 -177
- package/.claude/agents/architecture/system-design/arch-system-design.md +118 -153
- package/.claude-flow-novice/dist/mcp/auth.js +347 -0
- package/.claude-flow-novice/dist/mcp/claude-code-wrapper.js +717 -0
- package/.claude-flow-novice/dist/mcp/claude-flow-tools.js +1365 -0
- package/.claude-flow-novice/dist/mcp/client.js +201 -0
- package/.claude-flow-novice/dist/mcp/index.js +192 -0
- package/.claude-flow-novice/dist/mcp/integrate-wrapper.js +85 -0
- package/.claude-flow-novice/dist/mcp/lifecycle-manager.js +348 -0
- package/.claude-flow-novice/dist/mcp/load-balancer.js +386 -0
- package/.claude-flow-novice/dist/mcp/mcp-config-manager.js +1362 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-novice-simplified.js +583 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-novice.js +723 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-sdk.js +649 -0
- package/.claude-flow-novice/dist/mcp/mcp-server.js +2256 -0
- package/.claude-flow-novice/dist/mcp/orchestration-integration.js +800 -0
- package/.claude-flow-novice/dist/mcp/performance-monitor.js +489 -0
- package/.claude-flow-novice/dist/mcp/protocol-manager.js +376 -0
- package/.claude-flow-novice/dist/mcp/router.js +220 -0
- package/.claude-flow-novice/dist/mcp/ruv-swarm-tools.js +671 -0
- package/.claude-flow-novice/dist/mcp/ruv-swarm-wrapper.js +254 -0
- package/.claude-flow-novice/dist/mcp/server-with-wrapper.js +32 -0
- package/.claude-flow-novice/dist/mcp/server-wrapper-mode.js +26 -0
- package/.claude-flow-novice/dist/mcp/server.js +539 -0
- package/.claude-flow-novice/dist/mcp/session-manager.js +338 -0
- package/.claude-flow-novice/dist/mcp/sparc-modes.js +455 -0
- package/.claude-flow-novice/dist/mcp/swarm-tools.js +903 -0
- package/.claude-flow-novice/dist/mcp/tools.js +426 -0
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js +23 -1
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
- package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +42 -102
- package/.claude-flow-novice/dist/src/config/web-portal-config.js +2 -1
- package/.claude-flow-novice/dist/src/config/web-portal-config.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js +36 -0
- package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js.map +1 -0
- package/.claude-flow-novice/dist/src/preferences/user-preference-manager.js +371 -0
- package/.claude-flow-novice/dist/src/preferences/user-preference-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/index.js +12 -0
- package/.claude-flow-novice/dist/src/validators/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js +261 -0
- package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js +204 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-integration.js +189 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/portal-server.js +12 -5
- package/.claude-flow-novice/dist/src/web/portal-server.js.map +1 -1
- package/config/hooks/post-edit-pipeline.js +231 -10
- package/package.json +4 -2
- package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md +4 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Client for Model Context Protocol
|
|
3
|
+
*/ import { EventEmitter } from 'node:events';
|
|
4
|
+
import { logger } from '../core/logger.js';
|
|
5
|
+
import { RecoveryManager } from './recovery/index.js';
|
|
6
|
+
export class MCPClient extends EventEmitter {
|
|
7
|
+
transport;
|
|
8
|
+
timeout;
|
|
9
|
+
connected = false;
|
|
10
|
+
recoveryManager;
|
|
11
|
+
pendingRequests = new Map();
|
|
12
|
+
constructor(config){
|
|
13
|
+
super();
|
|
14
|
+
this.transport = config.transport;
|
|
15
|
+
this.timeout = config.timeout || 30000;
|
|
16
|
+
// Initialize recovery manager if enabled
|
|
17
|
+
if (config.enableRecovery) {
|
|
18
|
+
this.recoveryManager = new RecoveryManager(this, config.mcpConfig || {}, logger, config.recoveryConfig);
|
|
19
|
+
this.setupRecoveryHandlers();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async connect() {
|
|
23
|
+
try {
|
|
24
|
+
await this.transport.connect();
|
|
25
|
+
this.connected = true;
|
|
26
|
+
logger.info('MCP Client connected');
|
|
27
|
+
// Start recovery manager if enabled
|
|
28
|
+
if (this.recoveryManager) {
|
|
29
|
+
await this.recoveryManager.start();
|
|
30
|
+
}
|
|
31
|
+
this.emit('connected');
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.error('Failed to connect MCP client', error);
|
|
34
|
+
this.connected = false;
|
|
35
|
+
// Trigger recovery if enabled
|
|
36
|
+
if (this.recoveryManager) {
|
|
37
|
+
await this.recoveryManager.forceRecovery();
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async disconnect() {
|
|
43
|
+
if (this.connected) {
|
|
44
|
+
// Stop recovery manager first
|
|
45
|
+
if (this.recoveryManager) {
|
|
46
|
+
await this.recoveryManager.stop();
|
|
47
|
+
}
|
|
48
|
+
await this.transport.disconnect();
|
|
49
|
+
this.connected = false;
|
|
50
|
+
logger.info('MCP Client disconnected');
|
|
51
|
+
this.emit('disconnected');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async request(method, params) {
|
|
55
|
+
const request = {
|
|
56
|
+
jsonrpc: '2.0',
|
|
57
|
+
method,
|
|
58
|
+
params,
|
|
59
|
+
id: Math.random().toString(36).slice(2)
|
|
60
|
+
};
|
|
61
|
+
// If recovery manager is enabled, let it handle the request
|
|
62
|
+
if (this.recoveryManager && !this.connected) {
|
|
63
|
+
await this.recoveryManager.handleRequest(request);
|
|
64
|
+
}
|
|
65
|
+
if (!this.connected) {
|
|
66
|
+
throw new Error('Client not connected');
|
|
67
|
+
}
|
|
68
|
+
// Create promise for tracking the request
|
|
69
|
+
const requestPromise = new Promise((resolve, reject)=>{
|
|
70
|
+
const timer = setTimeout(()=>{
|
|
71
|
+
this.pendingRequests.delete(request.id);
|
|
72
|
+
reject(new Error(`Request timeout: ${method}`));
|
|
73
|
+
}, this.timeout);
|
|
74
|
+
this.pendingRequests.set(request.id, {
|
|
75
|
+
resolve,
|
|
76
|
+
reject,
|
|
77
|
+
timer
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
try {
|
|
81
|
+
const response = await this.transport.sendRequest(request);
|
|
82
|
+
// Clear pending request
|
|
83
|
+
const pending = this.pendingRequests.get(request.id);
|
|
84
|
+
if (pending) {
|
|
85
|
+
clearTimeout(pending.timer);
|
|
86
|
+
this.pendingRequests.delete(request.id);
|
|
87
|
+
}
|
|
88
|
+
if ('error' in response) {
|
|
89
|
+
throw new Error(response.error);
|
|
90
|
+
}
|
|
91
|
+
return response.result;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
// Clear pending request on error
|
|
94
|
+
const pending = this.pendingRequests.get(request.id);
|
|
95
|
+
if (pending) {
|
|
96
|
+
clearTimeout(pending.timer);
|
|
97
|
+
this.pendingRequests.delete(request.id);
|
|
98
|
+
}
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async notify(method, params) {
|
|
103
|
+
// Special handling for heartbeat notifications
|
|
104
|
+
if (method === 'heartbeat') {
|
|
105
|
+
// Always allow heartbeat notifications for recovery
|
|
106
|
+
const notification = {
|
|
107
|
+
jsonrpc: '2.0',
|
|
108
|
+
method,
|
|
109
|
+
params
|
|
110
|
+
};
|
|
111
|
+
if (this.transport.sendNotification) {
|
|
112
|
+
await this.transport.sendNotification(notification);
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!this.connected) {
|
|
117
|
+
throw new Error('Client not connected');
|
|
118
|
+
}
|
|
119
|
+
const notification = {
|
|
120
|
+
jsonrpc: '2.0',
|
|
121
|
+
method,
|
|
122
|
+
params
|
|
123
|
+
};
|
|
124
|
+
if (this.transport.sendNotification) {
|
|
125
|
+
await this.transport.sendNotification(notification);
|
|
126
|
+
} else {
|
|
127
|
+
throw new Error('Transport does not support notifications');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
isConnected() {
|
|
131
|
+
return this.connected;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get recovery status if recovery is enabled
|
|
135
|
+
*/ getRecoveryStatus() {
|
|
136
|
+
return this.recoveryManager?.getStatus();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Force a recovery attempt
|
|
140
|
+
*/ async forceRecovery() {
|
|
141
|
+
if (!this.recoveryManager) {
|
|
142
|
+
throw new Error('Recovery not enabled');
|
|
143
|
+
}
|
|
144
|
+
return this.recoveryManager.forceRecovery();
|
|
145
|
+
}
|
|
146
|
+
setupRecoveryHandlers() {
|
|
147
|
+
if (!this.recoveryManager) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// Handle recovery events
|
|
151
|
+
this.recoveryManager.on('recoveryStart', ({ trigger })=>{
|
|
152
|
+
logger.info('Recovery started', {
|
|
153
|
+
trigger
|
|
154
|
+
});
|
|
155
|
+
this.emit('recoveryStart', {
|
|
156
|
+
trigger
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
this.recoveryManager.on('recoveryComplete', ({ success, duration })=>{
|
|
160
|
+
if (success) {
|
|
161
|
+
logger.info('Recovery completed successfully', {
|
|
162
|
+
duration
|
|
163
|
+
});
|
|
164
|
+
this.connected = true;
|
|
165
|
+
this.emit('recoverySuccess', {
|
|
166
|
+
duration
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
logger.error('Recovery failed');
|
|
170
|
+
this.emit('recoveryFailed', {
|
|
171
|
+
duration
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
this.recoveryManager.on('fallbackActivated', (state)=>{
|
|
176
|
+
logger.warn('Fallback mode activated', state);
|
|
177
|
+
this.emit('fallbackActivated', state);
|
|
178
|
+
});
|
|
179
|
+
this.recoveryManager.on('healthChange', (newStatus, oldStatus)=>{
|
|
180
|
+
this.emit('healthChange', newStatus, oldStatus);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Cleanup resources
|
|
185
|
+
*/ async cleanup() {
|
|
186
|
+
// Clear all pending requests
|
|
187
|
+
for (const [id, pending] of this.pendingRequests){
|
|
188
|
+
clearTimeout(pending.timer);
|
|
189
|
+
pending.reject(new Error('Client cleanup'));
|
|
190
|
+
}
|
|
191
|
+
this.pendingRequests.clear();
|
|
192
|
+
// Cleanup recovery manager
|
|
193
|
+
if (this.recoveryManager) {
|
|
194
|
+
await this.recoveryManager.cleanup();
|
|
195
|
+
}
|
|
196
|
+
// Disconnect if connected
|
|
197
|
+
await this.disconnect();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP (Model Context Protocol) Module
|
|
3
|
+
* Export all MCP components for easy integration
|
|
4
|
+
*/ // Core MCP Server
|
|
5
|
+
export { MCPServer } from './server.js';
|
|
6
|
+
// Lifecycle Management
|
|
7
|
+
export { MCPLifecycleManager, LifecycleState } from './lifecycle-manager.js';
|
|
8
|
+
// Tool Registry and Management
|
|
9
|
+
export { ToolRegistry } from './tools.js';
|
|
10
|
+
// Protocol Management
|
|
11
|
+
export { MCPProtocolManager } from './protocol-manager.js';
|
|
12
|
+
// Authentication and Authorization
|
|
13
|
+
export { AuthManager, Permissions } from './auth.js';
|
|
14
|
+
// Performance Monitoring
|
|
15
|
+
export { MCPPerformanceMonitor } from './performance-monitor.js';
|
|
16
|
+
// Orchestration Integration
|
|
17
|
+
export { MCPOrchestrationIntegration } from './orchestration-integration.js';
|
|
18
|
+
export { StdioTransport } from './transports/stdio.js';
|
|
19
|
+
export { HttpTransport } from './transports/http.js';
|
|
20
|
+
// Request Routing
|
|
21
|
+
export { RequestRouter } from './router.js';
|
|
22
|
+
// Session Management
|
|
23
|
+
export { SessionManager } from './session-manager.js';
|
|
24
|
+
// Load Balancing
|
|
25
|
+
export { LoadBalancer, RequestQueue } from './load-balancer.js';
|
|
26
|
+
// Tool Implementations
|
|
27
|
+
export { createClaudeFlowTools } from './claude-flow-tools.js';
|
|
28
|
+
export { createSwarmTools } from './swarm-tools.js';
|
|
29
|
+
/**
|
|
30
|
+
* MCP Integration Factory
|
|
31
|
+
* Provides a simple way to create a complete MCP integration
|
|
32
|
+
*/ export class MCPIntegrationFactory {
|
|
33
|
+
/**
|
|
34
|
+
* Create a complete MCP integration with all components
|
|
35
|
+
*/ static async createIntegration(config) {
|
|
36
|
+
const { mcpConfig, orchestrationConfig = {}, components = {}, logger } = config;
|
|
37
|
+
const integration = new MCPOrchestrationIntegration(mcpConfig, {
|
|
38
|
+
enabledIntegrations: {
|
|
39
|
+
orchestrator: true,
|
|
40
|
+
swarm: true,
|
|
41
|
+
agents: true,
|
|
42
|
+
resources: true,
|
|
43
|
+
memory: true,
|
|
44
|
+
monitoring: true,
|
|
45
|
+
terminals: true
|
|
46
|
+
},
|
|
47
|
+
autoStart: true,
|
|
48
|
+
healthCheckInterval: 30000,
|
|
49
|
+
reconnectAttempts: 3,
|
|
50
|
+
reconnectDelay: 5000,
|
|
51
|
+
enableMetrics: true,
|
|
52
|
+
enableAlerts: true,
|
|
53
|
+
...orchestrationConfig
|
|
54
|
+
}, components, logger);
|
|
55
|
+
return integration;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a standalone MCP server (without orchestration integration)
|
|
59
|
+
*/ static async createStandaloneServer(config) {
|
|
60
|
+
const { mcpConfig, logger, enableLifecycleManagement = true, enablePerformanceMonitoring = true } = config;
|
|
61
|
+
const eventBus = new (await import('node:events')).EventEmitter();
|
|
62
|
+
const server = new MCPServer(mcpConfig, eventBus, logger);
|
|
63
|
+
let lifecycleManager;
|
|
64
|
+
let performanceMonitor;
|
|
65
|
+
if (enableLifecycleManagement) {
|
|
66
|
+
lifecycleManager = new MCPLifecycleManager(mcpConfig, logger, ()=>server);
|
|
67
|
+
}
|
|
68
|
+
if (enablePerformanceMonitoring) {
|
|
69
|
+
performanceMonitor = new MCPPerformanceMonitor(logger);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
server,
|
|
73
|
+
lifecycleManager,
|
|
74
|
+
performanceMonitor
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a development/testing MCP setup
|
|
79
|
+
*/ static async createDevelopmentSetup(logger) {
|
|
80
|
+
const mcpConfig = {
|
|
81
|
+
transport: 'stdio',
|
|
82
|
+
enableMetrics: true,
|
|
83
|
+
auth: {
|
|
84
|
+
enabled: false,
|
|
85
|
+
method: 'token'
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const { server, lifecycleManager, performanceMonitor } = await this.createStandaloneServer({
|
|
89
|
+
mcpConfig,
|
|
90
|
+
logger,
|
|
91
|
+
enableLifecycleManagement: true,
|
|
92
|
+
enablePerformanceMonitoring: true
|
|
93
|
+
});
|
|
94
|
+
const protocolManager = new MCPProtocolManager(logger);
|
|
95
|
+
return {
|
|
96
|
+
server,
|
|
97
|
+
lifecycleManager: lifecycleManager,
|
|
98
|
+
performanceMonitor: performanceMonitor,
|
|
99
|
+
protocolManager
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Default MCP configuration for common use cases
|
|
105
|
+
*/ export const DefaultMCPConfigs = {
|
|
106
|
+
/**
|
|
107
|
+
* Development configuration with stdio transport
|
|
108
|
+
*/ development: {
|
|
109
|
+
transport: 'stdio',
|
|
110
|
+
enableMetrics: true,
|
|
111
|
+
auth: {
|
|
112
|
+
enabled: false,
|
|
113
|
+
method: 'token'
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
/**
|
|
117
|
+
* Production configuration with HTTP transport and authentication
|
|
118
|
+
*/ production: {
|
|
119
|
+
transport: 'http',
|
|
120
|
+
host: '0.0.0.0',
|
|
121
|
+
port: 3000,
|
|
122
|
+
tlsEnabled: true,
|
|
123
|
+
enableMetrics: true,
|
|
124
|
+
auth: {
|
|
125
|
+
enabled: true,
|
|
126
|
+
method: 'token'
|
|
127
|
+
},
|
|
128
|
+
loadBalancer: {
|
|
129
|
+
enabled: true,
|
|
130
|
+
maxRequestsPerSecond: 100,
|
|
131
|
+
maxConcurrentRequests: 50
|
|
132
|
+
},
|
|
133
|
+
sessionTimeout: 3600000,
|
|
134
|
+
maxSessions: 1000
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* Testing configuration with minimal features
|
|
138
|
+
*/ testing: {
|
|
139
|
+
transport: 'stdio',
|
|
140
|
+
enableMetrics: false,
|
|
141
|
+
auth: {
|
|
142
|
+
enabled: false,
|
|
143
|
+
method: 'token'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* MCP Utility Functions
|
|
149
|
+
*/ export const MCPUtils = {
|
|
150
|
+
/**
|
|
151
|
+
* Validate MCP protocol version
|
|
152
|
+
*/ isValidProtocolVersion (version) {
|
|
153
|
+
return typeof version.major === 'number' && typeof version.minor === 'number' && typeof version.patch === 'number' && version.major > 0;
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Compare two protocol versions
|
|
157
|
+
*/ compareVersions (a, b) {
|
|
158
|
+
if (a.major !== b.major) return a.major - b.major;
|
|
159
|
+
if (a.minor !== b.minor) return a.minor - b.minor;
|
|
160
|
+
return a.patch - b.patch;
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* Format protocol version as string
|
|
164
|
+
*/ formatVersion (version) {
|
|
165
|
+
return `${version.major}.${version.minor}.${version.patch}`;
|
|
166
|
+
},
|
|
167
|
+
/**
|
|
168
|
+
* Parse protocol version from string
|
|
169
|
+
*/ parseVersion (versionString) {
|
|
170
|
+
const parts = versionString.split('.').map((p)=>parseInt(p, 10));
|
|
171
|
+
if (parts.length !== 3 || parts.some((p)=>isNaN(p))) {
|
|
172
|
+
throw new Error(`Invalid version string: ${versionString}`);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
major: parts[0],
|
|
176
|
+
minor: parts[1],
|
|
177
|
+
patch: parts[2]
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
/**
|
|
181
|
+
* Generate a random session ID
|
|
182
|
+
*/ generateSessionId () {
|
|
183
|
+
return `mcp_session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
184
|
+
},
|
|
185
|
+
/**
|
|
186
|
+
* Generate a random request ID
|
|
187
|
+
*/ generateRequestId () {
|
|
188
|
+
return `mcp_req_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
5
|
+
import { ClaudeCodeMCPWrapper } from './claude-code-wrapper.js';
|
|
6
|
+
/**
|
|
7
|
+
* Integration script that connects the Claude-Flow MCP wrapper
|
|
8
|
+
* to the Claude Code MCP server
|
|
9
|
+
*/ export class MCPIntegration {
|
|
10
|
+
claudeCodeClient;
|
|
11
|
+
wrapper;
|
|
12
|
+
constructor(){
|
|
13
|
+
this.wrapper = new ClaudeCodeMCPWrapper();
|
|
14
|
+
}
|
|
15
|
+
async connectToClaudeCode() {
|
|
16
|
+
try {
|
|
17
|
+
// Start Claude Code MCP server process
|
|
18
|
+
const claudeCodeProcess = spawn('npx', [
|
|
19
|
+
'-y',
|
|
20
|
+
'@anthropic/claude-code',
|
|
21
|
+
'mcp'
|
|
22
|
+
], {
|
|
23
|
+
stdio: [
|
|
24
|
+
'pipe',
|
|
25
|
+
'pipe',
|
|
26
|
+
'pipe'
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
const transport = new StdioClientTransport({
|
|
30
|
+
command: 'npx',
|
|
31
|
+
args: [
|
|
32
|
+
'-y',
|
|
33
|
+
'@anthropic/claude-code',
|
|
34
|
+
'mcp'
|
|
35
|
+
]
|
|
36
|
+
});
|
|
37
|
+
this.claudeCodeClient = new Client({
|
|
38
|
+
name: 'claude-flow-wrapper-client',
|
|
39
|
+
version: '1.0.0'
|
|
40
|
+
}, {
|
|
41
|
+
capabilities: {}
|
|
42
|
+
});
|
|
43
|
+
await this.claudeCodeClient.connect(transport);
|
|
44
|
+
// Inject the client into the wrapper
|
|
45
|
+
this.wrapper.claudeCodeMCP = this.claudeCodeClient;
|
|
46
|
+
console.log('Connected to Claude Code MCP server');
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('Failed to connect to Claude Code MCP:', error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async start() {
|
|
53
|
+
// Connect to Claude Code MCP
|
|
54
|
+
await this.connectToClaudeCode();
|
|
55
|
+
// Start the wrapper server
|
|
56
|
+
await this.wrapper.run();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Update the wrapper to use the real Claude Code MCP client
|
|
60
|
+
export function injectClaudeCodeClient(wrapper, client) {
|
|
61
|
+
// Override the forwardToClaudeCode method
|
|
62
|
+
wrapper.forwardToClaudeCode = async function(toolName, args) {
|
|
63
|
+
try {
|
|
64
|
+
const result = await client.callTool(toolName, args);
|
|
65
|
+
return result;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: 'text',
|
|
71
|
+
text: `Error calling Claude Code tool ${toolName}: ${error instanceof Error ? error.message : String(error)}`
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
isError: true
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Main execution
|
|
80
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
81
|
+
const integration = new MCPIntegration();
|
|
82
|
+
integration.start().catch(console.error);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=integrate-wrapper.js.map
|