claude-flow 2.7.32 → 2.7.34
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/settings.local.json +9 -2
- package/.claude/skills/agentic-jujutsu/SKILL.md +645 -0
- package/CHANGELOG.md +75 -0
- package/bin/claude-flow +1 -1
- package/dist/src/cli/commands/mcp.js +61 -7
- package/dist/src/cli/commands/mcp.js.map +1 -1
- package/dist/src/cli/help-formatter.js +5 -3
- package/dist/src/cli/help-formatter.js.map +1 -1
- package/dist/src/cli/simple-cli.js +173 -79
- package/dist/src/cli/simple-cli.js.map +1 -1
- package/dist/src/cli/validation-helper.js.map +1 -1
- package/dist/src/core/version.js +2 -2
- package/dist/src/core/version.js.map +1 -1
- package/dist/src/mcp/async/job-manager-mcp25.js +240 -0
- package/dist/src/mcp/async/job-manager-mcp25.js.map +1 -0
- package/dist/src/mcp/index.js +8 -0
- package/dist/src/mcp/index.js.map +1 -1
- package/dist/src/mcp/protocol/version-negotiation.js +182 -0
- package/dist/src/mcp/protocol/version-negotiation.js.map +1 -0
- package/dist/src/mcp/registry/mcp-registry-client-2025.js +210 -0
- package/dist/src/mcp/registry/mcp-registry-client-2025.js.map +1 -0
- package/dist/src/mcp/server-factory.js +189 -0
- package/dist/src/mcp/server-factory.js.map +1 -0
- package/dist/src/mcp/server-mcp-2025.js +283 -0
- package/dist/src/mcp/server-mcp-2025.js.map +1 -0
- package/dist/src/mcp/tool-registry-progressive.js +319 -0
- package/dist/src/mcp/tool-registry-progressive.js.map +1 -0
- package/dist/src/mcp/tools/_template.js +62 -0
- package/dist/src/mcp/tools/_template.js.map +1 -0
- package/dist/src/mcp/tools/loader.js +228 -0
- package/dist/src/mcp/tools/loader.js.map +1 -0
- package/dist/src/mcp/tools/system/search.js +224 -0
- package/dist/src/mcp/tools/system/search.js.map +1 -0
- package/dist/src/mcp/tools/system/status.js +168 -0
- package/dist/src/mcp/tools/system/status.js.map +1 -0
- package/dist/src/mcp/validation/schema-validator-2025.js +198 -0
- package/dist/src/mcp/validation/schema-validator-2025.js.map +1 -0
- package/dist/src/memory/swarm-memory.js +340 -421
- package/dist/src/memory/swarm-memory.js.map +1 -1
- package/docs/.claude-flow/metrics/performance.json +3 -3
- package/docs/.claude-flow/metrics/task-metrics.json +3 -3
- package/docs/.github-release-issue-v2.7.33.md +488 -0
- package/docs/AGENTDB_BRANCH_MERGE_VERIFICATION.md +436 -0
- package/docs/BRANCH_REVIEW_SUMMARY.md +439 -0
- package/docs/DEEP_CODE_REVIEW_v2.7.33.md +1159 -0
- package/docs/MCP_2025_FEATURE_CONFIRMATION.md +698 -0
- package/docs/NPM_PUBLISH_GUIDE_v2.7.33.md +628 -0
- package/docs/REGRESSION_TEST_REPORT_v2.7.33.md +397 -0
- package/docs/RELEASE_NOTES_v2.7.33.md +618 -0
- package/docs/RELEASE_READINESS_SUMMARY.md +377 -0
- package/docs/RELEASE_SUMMARY_v2.7.33.md +456 -0
- package/docs/agentic-flow-agentdb-mcp-integration.md +1198 -0
- package/docs/mcp-2025-implementation-summary.md +459 -0
- package/docs/mcp-spec-2025-implementation-plan.md +1330 -0
- package/docs/phase-1-2-implementation-summary.md +676 -0
- package/docs/regression-analysis-phase-1-2.md +555 -0
- package/package.json +5 -1
- package/src/cli/commands/mcp.ts +86 -9
- package/src/mcp/async/job-manager-mcp25.ts +456 -0
- package/src/mcp/index.ts +60 -0
- package/src/mcp/protocol/version-negotiation.ts +329 -0
- package/src/mcp/registry/mcp-registry-client-2025.ts +334 -0
- package/src/mcp/server-factory.ts +426 -0
- package/src/mcp/server-mcp-2025.ts +507 -0
- package/src/mcp/tool-registry-progressive.ts +539 -0
- package/src/mcp/tools/_template.ts +174 -0
- package/src/mcp/tools/loader.ts +362 -0
- package/src/mcp/tools/system/search.ts +276 -0
- package/src/mcp/tools/system/status.ts +206 -0
- package/src/mcp/validation/schema-validator-2025.ts +294 -0
- package/docs/AGENTDB_V1.6.1_DEEP_REVIEW.md +0 -386
- package/docs/RECENT_RELEASES_SUMMARY.md +0 -375
- package/docs/V2.7.31_RELEASE_NOTES.md +0 -375
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { VersionNegotiator, BackwardCompatibilityAdapter } from './protocol/version-negotiation.js';
|
|
2
|
+
import { MCPAsyncJobManager } from './async/job-manager-mcp25.js';
|
|
3
|
+
import { MCPRegistryClient } from './registry/mcp-registry-client-2025.js';
|
|
4
|
+
import { SchemaValidator, upgradeToolSchema } from './validation/schema-validator-2025.js';
|
|
5
|
+
import { ProgressiveToolRegistry } from './tool-registry-progressive.js';
|
|
6
|
+
export class MCP2025Server {
|
|
7
|
+
config;
|
|
8
|
+
eventBus;
|
|
9
|
+
logger;
|
|
10
|
+
versionNegotiator;
|
|
11
|
+
compatibilityAdapter;
|
|
12
|
+
jobManager;
|
|
13
|
+
registryClient;
|
|
14
|
+
schemaValidator;
|
|
15
|
+
toolRegistry;
|
|
16
|
+
sessions = new Map();
|
|
17
|
+
MAX_SESSIONS = 10000;
|
|
18
|
+
SESSION_TTL = 3600000;
|
|
19
|
+
sessionCleanupInterval;
|
|
20
|
+
constructor(config, eventBus, logger){
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.eventBus = eventBus;
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
this.versionNegotiator = new VersionNegotiator(logger);
|
|
25
|
+
this.compatibilityAdapter = new BackwardCompatibilityAdapter(logger);
|
|
26
|
+
this.schemaValidator = new SchemaValidator(logger);
|
|
27
|
+
this.toolRegistry = new ProgressiveToolRegistry({
|
|
28
|
+
enableInProcess: true,
|
|
29
|
+
enableMetrics: true,
|
|
30
|
+
enableCaching: true,
|
|
31
|
+
orchestratorContext: config.orchestratorContext,
|
|
32
|
+
toolsDirectory: config.toolsDirectory
|
|
33
|
+
});
|
|
34
|
+
this.logger.info('MCP 2025-11 server created', {
|
|
35
|
+
serverId: config.serverId,
|
|
36
|
+
mcp2025Enabled: config.enableMCP2025,
|
|
37
|
+
legacySupport: config.supportLegacyClients
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async initialize() {
|
|
41
|
+
this.logger.info('Initializing MCP 2025-11 server');
|
|
42
|
+
await this.toolRegistry.initialize();
|
|
43
|
+
this.sessionCleanupInterval = setInterval(()=>this.cleanupExpiredSessions(), 300000);
|
|
44
|
+
if (this.config.async.enabled) {
|
|
45
|
+
this.jobManager = new MCPAsyncJobManager(null, this.logger, {
|
|
46
|
+
maxJobs: this.config.async.maxJobs,
|
|
47
|
+
jobTTL: this.config.async.jobTTL
|
|
48
|
+
});
|
|
49
|
+
this.logger.info('Async job manager initialized');
|
|
50
|
+
}
|
|
51
|
+
if (this.config.registry.enabled) {
|
|
52
|
+
this.registryClient = new MCPRegistryClient(this.config.registry, this.logger, ()=>this.toolRegistry.getToolNames(), ()=>this.versionNegotiator.getServerCapabilities(), async ()=>this.getHealthStatus());
|
|
53
|
+
try {
|
|
54
|
+
await this.registryClient.register();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
this.logger.error('Failed to register with MCP Registry', {
|
|
57
|
+
error
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
this.logger.info('MCP 2025-11 server initialized successfully');
|
|
62
|
+
}
|
|
63
|
+
async handleHandshake(clientHandshake, sessionId) {
|
|
64
|
+
const isLegacy = this.compatibilityAdapter.isLegacyRequest(clientHandshake);
|
|
65
|
+
let handshake;
|
|
66
|
+
if (isLegacy && this.config.supportLegacyClients) {
|
|
67
|
+
this.logger.info('Legacy client detected, enabling compatibility mode', {
|
|
68
|
+
sessionId
|
|
69
|
+
});
|
|
70
|
+
handshake = this.compatibilityAdapter.convertToModern(clientHandshake);
|
|
71
|
+
} else {
|
|
72
|
+
handshake = clientHandshake;
|
|
73
|
+
}
|
|
74
|
+
const negotiation = await this.versionNegotiator.negotiate(handshake);
|
|
75
|
+
if (!negotiation.success) {
|
|
76
|
+
throw new Error(`Version negotiation failed: ${negotiation.error}`);
|
|
77
|
+
}
|
|
78
|
+
if (this.sessions.size >= this.MAX_SESSIONS) {
|
|
79
|
+
const oldestSession = Array.from(this.sessions.entries()).sort((a, b)=>a[1].createdAt - b[1].createdAt)[0];
|
|
80
|
+
if (oldestSession) {
|
|
81
|
+
this.sessions.delete(oldestSession[0]);
|
|
82
|
+
this.logger.warn('Session limit reached, removed oldest session', {
|
|
83
|
+
removedSessionId: oldestSession[0]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
this.sessions.set(sessionId, {
|
|
89
|
+
clientId: handshake.client_id || 'unknown',
|
|
90
|
+
version: negotiation.agreed_version,
|
|
91
|
+
capabilities: negotiation.agreed_capabilities,
|
|
92
|
+
isLegacy,
|
|
93
|
+
createdAt: now,
|
|
94
|
+
lastAccess: now
|
|
95
|
+
});
|
|
96
|
+
const serverHandshake = this.versionNegotiator.createServerHandshake(this.config.serverId, this.config.transport, {
|
|
97
|
+
name: 'Claude Flow',
|
|
98
|
+
version: '2.7.32',
|
|
99
|
+
description: 'Enterprise AI orchestration with MCP 2025-11 support'
|
|
100
|
+
});
|
|
101
|
+
serverHandshake.mcp_version = negotiation.agreed_version;
|
|
102
|
+
serverHandshake.capabilities = negotiation.agreed_capabilities;
|
|
103
|
+
this.logger.info('Handshake completed', {
|
|
104
|
+
sessionId,
|
|
105
|
+
version: serverHandshake.mcp_version,
|
|
106
|
+
capabilities: serverHandshake.capabilities,
|
|
107
|
+
isLegacy
|
|
108
|
+
});
|
|
109
|
+
return serverHandshake;
|
|
110
|
+
}
|
|
111
|
+
async handleToolCall(request, sessionId) {
|
|
112
|
+
const session = this.sessions.get(sessionId);
|
|
113
|
+
if (session) {
|
|
114
|
+
session.lastAccess = Date.now();
|
|
115
|
+
}
|
|
116
|
+
if (session?.isLegacy) {
|
|
117
|
+
return this.handleLegacyToolCall(request, sessionId);
|
|
118
|
+
}
|
|
119
|
+
const mcpRequest = request;
|
|
120
|
+
if (!mcpRequest.tool_id) {
|
|
121
|
+
throw new Error('Missing tool_id in request');
|
|
122
|
+
}
|
|
123
|
+
const tool = await this.toolRegistry.getTool(mcpRequest.tool_id);
|
|
124
|
+
if (!tool) {
|
|
125
|
+
throw new Error(`Tool not found: ${mcpRequest.tool_id}`);
|
|
126
|
+
}
|
|
127
|
+
if (this.config.validation.enabled) {
|
|
128
|
+
const validation = this.schemaValidator.validateInput(upgradeToolSchema(tool.inputSchema), mcpRequest.arguments);
|
|
129
|
+
if (!validation.valid) {
|
|
130
|
+
throw new Error(`Invalid input: ${validation.errors?.map((e)=>e.message).join(', ')}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const hasAsyncCapability = session?.capabilities.includes('async');
|
|
134
|
+
const isAsyncRequest = mcpRequest.mode === 'async' && hasAsyncCapability;
|
|
135
|
+
if (isAsyncRequest && this.jobManager) {
|
|
136
|
+
this.logger.info('Submitting async job', {
|
|
137
|
+
tool_id: mcpRequest.tool_id,
|
|
138
|
+
request_id: mcpRequest.request_id
|
|
139
|
+
});
|
|
140
|
+
return await this.jobManager.submitJob(mcpRequest, async (args, onProgress)=>{
|
|
141
|
+
return await tool.handler(args, {
|
|
142
|
+
orchestrator: this.config.orchestratorContext,
|
|
143
|
+
sessionId
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
this.logger.info('Executing tool synchronously', {
|
|
148
|
+
tool_id: mcpRequest.tool_id,
|
|
149
|
+
request_id: mcpRequest.request_id
|
|
150
|
+
});
|
|
151
|
+
const startTime = Date.now();
|
|
152
|
+
const result = await tool.handler(mcpRequest.arguments, {
|
|
153
|
+
orchestrator: this.config.orchestratorContext,
|
|
154
|
+
sessionId
|
|
155
|
+
});
|
|
156
|
+
if (this.config.validation.enabled && tool.metadata?.outputSchema) {
|
|
157
|
+
const validation = this.schemaValidator.validateOutput(tool.metadata.outputSchema, result);
|
|
158
|
+
if (!validation.valid) {
|
|
159
|
+
this.logger.warn('Output validation failed', {
|
|
160
|
+
tool_id: mcpRequest.tool_id,
|
|
161
|
+
errors: validation.errors
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
request_id: mcpRequest.request_id,
|
|
167
|
+
status: 'success',
|
|
168
|
+
result,
|
|
169
|
+
metadata: {
|
|
170
|
+
duration_ms: Date.now() - startTime
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async handleLegacyToolCall(request, sessionId) {
|
|
176
|
+
this.logger.info('Handling legacy tool call', {
|
|
177
|
+
toolName: request.name || request.method,
|
|
178
|
+
sessionId
|
|
179
|
+
});
|
|
180
|
+
const toolId = request.name || request.method;
|
|
181
|
+
const args = request.arguments || request.params || {};
|
|
182
|
+
const tool = await this.toolRegistry.getTool(toolId);
|
|
183
|
+
if (!tool) {
|
|
184
|
+
throw new Error(`Tool not found: ${toolId}`);
|
|
185
|
+
}
|
|
186
|
+
const result = await tool.handler(args, {
|
|
187
|
+
orchestrator: this.config.orchestratorContext,
|
|
188
|
+
sessionId
|
|
189
|
+
});
|
|
190
|
+
return this.compatibilityAdapter.convertToLegacy({
|
|
191
|
+
result,
|
|
192
|
+
status: 'success'
|
|
193
|
+
}, true);
|
|
194
|
+
}
|
|
195
|
+
async pollJob(job_id) {
|
|
196
|
+
if (!this.jobManager) {
|
|
197
|
+
throw new Error('Async jobs not enabled');
|
|
198
|
+
}
|
|
199
|
+
return await this.jobManager.pollJob(job_id);
|
|
200
|
+
}
|
|
201
|
+
async resumeJob(job_id) {
|
|
202
|
+
if (!this.jobManager) {
|
|
203
|
+
throw new Error('Async jobs not enabled');
|
|
204
|
+
}
|
|
205
|
+
return await this.jobManager.resumeJob(job_id);
|
|
206
|
+
}
|
|
207
|
+
async cancelJob(job_id) {
|
|
208
|
+
if (!this.jobManager) {
|
|
209
|
+
throw new Error('Async jobs not enabled');
|
|
210
|
+
}
|
|
211
|
+
return await this.jobManager.cancelJob(job_id);
|
|
212
|
+
}
|
|
213
|
+
async listJobs(filter) {
|
|
214
|
+
if (!this.jobManager) {
|
|
215
|
+
throw new Error('Async jobs not enabled');
|
|
216
|
+
}
|
|
217
|
+
return await this.jobManager.listJobs(filter);
|
|
218
|
+
}
|
|
219
|
+
async getHealthStatus() {
|
|
220
|
+
const startTime = Date.now();
|
|
221
|
+
const latency = Date.now() - startTime;
|
|
222
|
+
let status = 'healthy';
|
|
223
|
+
if (latency > 100) {
|
|
224
|
+
status = 'degraded';
|
|
225
|
+
}
|
|
226
|
+
if (latency > 500) {
|
|
227
|
+
status = 'unhealthy';
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
status,
|
|
231
|
+
latency_ms: latency
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
getMetrics() {
|
|
235
|
+
return {
|
|
236
|
+
sessions: {
|
|
237
|
+
total: this.sessions.size,
|
|
238
|
+
byVersion: this.getSessionsByVersion(),
|
|
239
|
+
legacy: Array.from(this.sessions.values()).filter((s)=>s.isLegacy).length
|
|
240
|
+
},
|
|
241
|
+
jobs: this.jobManager?.getMetrics(),
|
|
242
|
+
tools: this.toolRegistry.getMetrics(),
|
|
243
|
+
validation: this.schemaValidator.getCacheStats()
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
getSessionsByVersion() {
|
|
247
|
+
const counts = {};
|
|
248
|
+
for (const session of this.sessions.values()){
|
|
249
|
+
counts[session.version] = (counts[session.version] || 0) + 1;
|
|
250
|
+
}
|
|
251
|
+
return counts;
|
|
252
|
+
}
|
|
253
|
+
cleanupExpiredSessions() {
|
|
254
|
+
const now = Date.now();
|
|
255
|
+
let cleaned = 0;
|
|
256
|
+
for (const [sessionId, session] of this.sessions.entries()){
|
|
257
|
+
if (now - session.lastAccess > this.SESSION_TTL) {
|
|
258
|
+
this.sessions.delete(sessionId);
|
|
259
|
+
cleaned++;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (cleaned > 0) {
|
|
263
|
+
this.logger.info('Cleaned up expired sessions', {
|
|
264
|
+
count: cleaned
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async cleanup() {
|
|
269
|
+
this.logger.info('Cleaning up MCP 2025-11 server');
|
|
270
|
+
if (this.sessionCleanupInterval) {
|
|
271
|
+
clearInterval(this.sessionCleanupInterval);
|
|
272
|
+
}
|
|
273
|
+
if (this.registryClient) {
|
|
274
|
+
await this.registryClient.unregister();
|
|
275
|
+
}
|
|
276
|
+
this.schemaValidator.clearCache();
|
|
277
|
+
await this.toolRegistry.cleanup();
|
|
278
|
+
this.sessions.clear();
|
|
279
|
+
this.logger.info('Cleanup complete');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
//# sourceMappingURL=server-mcp-2025.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mcp/server-mcp-2025.ts"],"sourcesContent":["/**\n * MCP 2025-11 Enhanced Server\n *\n * Integrates all MCP 2025-11 features with full backward compatibility:\n * - Version negotiation\n * - Async job support\n * - Registry integration\n * - JSON Schema 1.1 validation\n * - Dual-mode operation (2025-11 + legacy)\n */\n\nimport type { ILogger } from '../interfaces/logger.js';\nimport type { IEventBus } from '../interfaces/event-bus.js';\nimport { VersionNegotiator, BackwardCompatibilityAdapter, type MCPHandshake, type MCPVersion, type MCPCapability } from './protocol/version-negotiation.js';\nimport { MCPAsyncJobManager, type MCPToolRequest, type MCPJobHandle, type MCPJobResult } from './async/job-manager-mcp25.js';\nimport { MCPRegistryClient, type RegistryConfig } from './registry/mcp-registry-client-2025.js';\nimport { SchemaValidator, upgradeToolSchema } from './validation/schema-validator-2025.js';\nimport { ProgressiveToolRegistry } from './tool-registry-progressive.js';\n\n/**\n * MCP 2025-11 server configuration\n */\nexport interface MCP2025ServerConfig {\n serverId: string;\n transport: 'stdio' | 'http' | 'ws';\n\n // Version & capabilities\n enableMCP2025: boolean; // Feature flag for gradual rollout\n supportLegacyClients: boolean; // Backward compatibility\n\n // Async jobs\n async: {\n enabled: boolean;\n maxJobs?: number;\n jobTTL?: number;\n persistence?: 'memory' | 'redis' | 'sqlite';\n };\n\n // Registry\n registry: RegistryConfig;\n\n // Schema validation\n validation: {\n enabled: boolean;\n strictMode?: boolean;\n };\n\n // Tool registry\n toolsDirectory?: string;\n\n // Existing config\n orchestratorContext?: any;\n}\n\n/**\n * MCP 2025-11 Enhanced Server\n */\nexport class MCP2025Server {\n private versionNegotiator: VersionNegotiator;\n private compatibilityAdapter: BackwardCompatibilityAdapter;\n private jobManager?: MCPAsyncJobManager;\n private registryClient?: MCPRegistryClient;\n private schemaValidator: SchemaValidator;\n private toolRegistry: ProgressiveToolRegistry;\n\n // Session state\n private sessions: Map<string, {\n clientId: string;\n version: MCPVersion;\n capabilities: MCPCapability[];\n isLegacy: boolean;\n createdAt: number;\n lastAccess: number;\n }> = new Map();\n\n // Session management constants\n private readonly MAX_SESSIONS = 10000;\n private readonly SESSION_TTL = 3600000; // 1 hour\n private sessionCleanupInterval?: NodeJS.Timeout;\n\n constructor(\n private config: MCP2025ServerConfig,\n private eventBus: IEventBus,\n private logger: ILogger\n ) {\n // Initialize version negotiation\n this.versionNegotiator = new VersionNegotiator(logger);\n this.compatibilityAdapter = new BackwardCompatibilityAdapter(logger);\n\n // Initialize schema validator\n this.schemaValidator = new SchemaValidator(logger);\n\n // Initialize tool registry (progressive)\n this.toolRegistry = new ProgressiveToolRegistry({\n enableInProcess: true,\n enableMetrics: true,\n enableCaching: true,\n orchestratorContext: config.orchestratorContext,\n toolsDirectory: config.toolsDirectory,\n });\n\n this.logger.info('MCP 2025-11 server created', {\n serverId: config.serverId,\n mcp2025Enabled: config.enableMCP2025,\n legacySupport: config.supportLegacyClients,\n });\n }\n\n /**\n * Initialize server\n */\n async initialize(): Promise<void> {\n this.logger.info('Initializing MCP 2025-11 server');\n\n // Initialize tool registry\n await this.toolRegistry.initialize();\n\n // Start session cleanup interval\n this.sessionCleanupInterval = setInterval(\n () => this.cleanupExpiredSessions(),\n 300000 // Every 5 minutes\n );\n\n // Initialize async job manager if enabled\n if (this.config.async.enabled) {\n this.jobManager = new MCPAsyncJobManager(\n null, // Use memory persistence for now\n this.logger,\n {\n maxJobs: this.config.async.maxJobs,\n jobTTL: this.config.async.jobTTL,\n }\n );\n\n this.logger.info('Async job manager initialized');\n }\n\n // Initialize registry client if enabled\n if (this.config.registry.enabled) {\n this.registryClient = new MCPRegistryClient(\n this.config.registry,\n this.logger,\n () => this.toolRegistry.getToolNames(),\n () => this.versionNegotiator.getServerCapabilities(),\n async () => this.getHealthStatus()\n );\n\n // Register with MCP Registry\n try {\n await this.registryClient.register();\n } catch (error) {\n this.logger.error('Failed to register with MCP Registry', { error });\n // Don't fail initialization if registry is unavailable\n }\n }\n\n this.logger.info('MCP 2025-11 server initialized successfully');\n }\n\n /**\n * Handle client connection/handshake\n */\n async handleHandshake(clientHandshake: any, sessionId: string): Promise<MCPHandshake> {\n // Check if legacy client\n const isLegacy = this.compatibilityAdapter.isLegacyRequest(clientHandshake);\n\n let handshake: MCPHandshake;\n if (isLegacy && this.config.supportLegacyClients) {\n this.logger.info('Legacy client detected, enabling compatibility mode', { sessionId });\n handshake = this.compatibilityAdapter.convertToModern(clientHandshake);\n } else {\n handshake = clientHandshake;\n }\n\n // Negotiate version and capabilities\n const negotiation = await this.versionNegotiator.negotiate(handshake);\n\n if (!negotiation.success) {\n throw new Error(`Version negotiation failed: ${negotiation.error}`);\n }\n\n // Enforce session limit\n if (this.sessions.size >= this.MAX_SESSIONS) {\n // Remove oldest session\n const oldestSession = Array.from(this.sessions.entries())\n .sort((a, b) => a[1].createdAt - b[1].createdAt)[0];\n if (oldestSession) {\n this.sessions.delete(oldestSession[0]);\n this.logger.warn('Session limit reached, removed oldest session', {\n removedSessionId: oldestSession[0],\n });\n }\n }\n\n // Store session info\n const now = Date.now();\n this.sessions.set(sessionId, {\n clientId: handshake.client_id || 'unknown',\n version: negotiation.agreed_version,\n capabilities: negotiation.agreed_capabilities,\n isLegacy,\n createdAt: now,\n lastAccess: now,\n });\n\n // Create server handshake response\n const serverHandshake = this.versionNegotiator.createServerHandshake(\n this.config.serverId,\n this.config.transport,\n {\n name: 'Claude Flow',\n version: '2.7.32',\n description: 'Enterprise AI orchestration with MCP 2025-11 support',\n }\n );\n\n // Apply agreed version and capabilities\n serverHandshake.mcp_version = negotiation.agreed_version;\n serverHandshake.capabilities = negotiation.agreed_capabilities;\n\n this.logger.info('Handshake completed', {\n sessionId,\n version: serverHandshake.mcp_version,\n capabilities: serverHandshake.capabilities,\n isLegacy,\n });\n\n return serverHandshake;\n }\n\n /**\n * Handle tool call request (with async support)\n */\n async handleToolCall(\n request: MCPToolRequest | any,\n sessionId: string\n ): Promise<MCPJobHandle | MCPJobResult | any> {\n const session = this.sessions.get(sessionId);\n\n // Update last access time\n if (session) {\n session.lastAccess = Date.now();\n }\n\n // Handle legacy request format\n if (session?.isLegacy) {\n return this.handleLegacyToolCall(request, sessionId);\n }\n\n // MCP 2025-11 format\n const mcpRequest = request as MCPToolRequest;\n\n // Validate request\n if (!mcpRequest.tool_id) {\n throw new Error('Missing tool_id in request');\n }\n\n // Get tool\n const tool = await this.toolRegistry.getTool(mcpRequest.tool_id);\n if (!tool) {\n throw new Error(`Tool not found: ${mcpRequest.tool_id}`);\n }\n\n // Validate input if validation enabled\n if (this.config.validation.enabled) {\n const validation = this.schemaValidator.validateInput(\n upgradeToolSchema(tool.inputSchema),\n mcpRequest.arguments\n );\n\n if (!validation.valid) {\n throw new Error(\n `Invalid input: ${validation.errors?.map(e => e.message).join(', ')}`\n );\n }\n }\n\n // Check if async mode requested\n const hasAsyncCapability = session?.capabilities.includes('async');\n const isAsyncRequest = mcpRequest.mode === 'async' && hasAsyncCapability;\n\n if (isAsyncRequest && this.jobManager) {\n // Submit as async job\n this.logger.info('Submitting async job', {\n tool_id: mcpRequest.tool_id,\n request_id: mcpRequest.request_id,\n });\n\n return await this.jobManager.submitJob(\n mcpRequest,\n async (args, onProgress) => {\n // Execute tool with progress tracking\n return await tool.handler(args, {\n orchestrator: this.config.orchestratorContext,\n sessionId,\n });\n }\n );\n } else {\n // Execute synchronously\n this.logger.info('Executing tool synchronously', {\n tool_id: mcpRequest.tool_id,\n request_id: mcpRequest.request_id,\n });\n\n const startTime = Date.now();\n const result = await tool.handler(mcpRequest.arguments, {\n orchestrator: this.config.orchestratorContext,\n sessionId,\n });\n\n // Validate output if validation enabled\n if (this.config.validation.enabled && tool.metadata?.outputSchema) {\n const validation = this.schemaValidator.validateOutput(\n tool.metadata.outputSchema,\n result\n );\n\n if (!validation.valid) {\n this.logger.warn('Output validation failed', {\n tool_id: mcpRequest.tool_id,\n errors: validation.errors,\n });\n }\n }\n\n // Return in MCP 2025-11 format\n return {\n request_id: mcpRequest.request_id,\n status: 'success',\n result,\n metadata: {\n duration_ms: Date.now() - startTime,\n },\n } as MCPJobResult;\n }\n }\n\n /**\n * Handle legacy tool call\n */\n private async handleLegacyToolCall(request: any, sessionId: string): Promise<any> {\n this.logger.info('Handling legacy tool call', {\n toolName: request.name || request.method,\n sessionId,\n });\n\n // Convert to modern format internally\n const toolId = request.name || request.method;\n const args = request.arguments || request.params || {};\n\n const tool = await this.toolRegistry.getTool(toolId);\n if (!tool) {\n throw new Error(`Tool not found: ${toolId}`);\n }\n\n const result = await tool.handler(args, {\n orchestrator: this.config.orchestratorContext,\n sessionId,\n });\n\n // Return in legacy format\n return this.compatibilityAdapter.convertToLegacy(\n { result, status: 'success' },\n true\n );\n }\n\n /**\n * Poll async job\n */\n async pollJob(job_id: string): Promise<MCPJobHandle> {\n if (!this.jobManager) {\n throw new Error('Async jobs not enabled');\n }\n\n return await this.jobManager.pollJob(job_id);\n }\n\n /**\n * Resume async job (get results)\n */\n async resumeJob(job_id: string): Promise<MCPJobResult> {\n if (!this.jobManager) {\n throw new Error('Async jobs not enabled');\n }\n\n return await this.jobManager.resumeJob(job_id);\n }\n\n /**\n * Cancel async job\n */\n async cancelJob(job_id: string): Promise<boolean> {\n if (!this.jobManager) {\n throw new Error('Async jobs not enabled');\n }\n\n return await this.jobManager.cancelJob(job_id);\n }\n\n /**\n * List async jobs\n */\n async listJobs(filter?: { status?: string; limit?: number }) {\n if (!this.jobManager) {\n throw new Error('Async jobs not enabled');\n }\n\n return await this.jobManager.listJobs(filter);\n }\n\n /**\n * Get health status\n */\n private async getHealthStatus(): Promise<{\n status: 'healthy' | 'degraded' | 'unhealthy';\n latency_ms: number;\n }> {\n const startTime = Date.now();\n\n // Perform health checks\n const latency = Date.now() - startTime;\n\n // Determine status based on metrics\n let status: 'healthy' | 'degraded' | 'unhealthy' = 'healthy';\n\n if (latency > 100) {\n status = 'degraded';\n }\n if (latency > 500) {\n status = 'unhealthy';\n }\n\n return { status, latency_ms: latency };\n }\n\n /**\n * Get metrics\n */\n getMetrics() {\n return {\n sessions: {\n total: this.sessions.size,\n byVersion: this.getSessionsByVersion(),\n legacy: Array.from(this.sessions.values()).filter(s => s.isLegacy).length,\n },\n jobs: this.jobManager?.getMetrics(),\n tools: this.toolRegistry.getMetrics(),\n validation: this.schemaValidator.getCacheStats(),\n };\n }\n\n private getSessionsByVersion() {\n const counts: Record<string, number> = {};\n for (const session of this.sessions.values()) {\n counts[session.version] = (counts[session.version] || 0) + 1;\n }\n return counts;\n }\n\n /**\n * Cleanup expired sessions\n */\n private cleanupExpiredSessions(): void {\n const now = Date.now();\n let cleaned = 0;\n\n for (const [sessionId, session] of this.sessions.entries()) {\n // Remove if last access was more than TTL ago\n if (now - session.lastAccess > this.SESSION_TTL) {\n this.sessions.delete(sessionId);\n cleaned++;\n }\n }\n\n if (cleaned > 0) {\n this.logger.info('Cleaned up expired sessions', { count: cleaned });\n }\n }\n\n /**\n * Cleanup resources\n */\n async cleanup(): Promise<void> {\n this.logger.info('Cleaning up MCP 2025-11 server');\n\n // Stop session cleanup interval\n if (this.sessionCleanupInterval) {\n clearInterval(this.sessionCleanupInterval);\n }\n\n // Unregister from registry\n if (this.registryClient) {\n await this.registryClient.unregister();\n }\n\n // Clear caches\n this.schemaValidator.clearCache();\n await this.toolRegistry.cleanup();\n\n // Clear sessions\n this.sessions.clear();\n\n this.logger.info('Cleanup complete');\n }\n}\n"],"names":["VersionNegotiator","BackwardCompatibilityAdapter","MCPAsyncJobManager","MCPRegistryClient","SchemaValidator","upgradeToolSchema","ProgressiveToolRegistry","MCP2025Server","versionNegotiator","compatibilityAdapter","jobManager","registryClient","schemaValidator","toolRegistry","sessions","Map","MAX_SESSIONS","SESSION_TTL","sessionCleanupInterval","config","eventBus","logger","enableInProcess","enableMetrics","enableCaching","orchestratorContext","toolsDirectory","info","serverId","mcp2025Enabled","enableMCP2025","legacySupport","supportLegacyClients","initialize","setInterval","cleanupExpiredSessions","async","enabled","maxJobs","jobTTL","registry","getToolNames","getServerCapabilities","getHealthStatus","register","error","handleHandshake","clientHandshake","sessionId","isLegacy","isLegacyRequest","handshake","convertToModern","negotiation","negotiate","success","Error","size","oldestSession","Array","from","entries","sort","a","b","createdAt","delete","warn","removedSessionId","now","Date","set","clientId","client_id","version","agreed_version","capabilities","agreed_capabilities","lastAccess","serverHandshake","createServerHandshake","transport","name","description","mcp_version","handleToolCall","request","session","get","handleLegacyToolCall","mcpRequest","tool_id","tool","getTool","validation","validateInput","inputSchema","arguments","valid","errors","map","e","message","join","hasAsyncCapability","includes","isAsyncRequest","mode","request_id","submitJob","args","onProgress","handler","orchestrator","startTime","result","metadata","outputSchema","validateOutput","status","duration_ms","toolName","method","toolId","params","convertToLegacy","pollJob","job_id","resumeJob","cancelJob","listJobs","filter","latency","latency_ms","getMetrics","total","byVersion","getSessionsByVersion","legacy","values","s","length","jobs","tools","getCacheStats","counts","cleaned","count","cleanup","clearInterval","unregister","clearCache","clear"],"mappings":"AAaA,SAASA,iBAAiB,EAAEC,4BAA4B,QAAgE,oCAAoC;AAC5J,SAASC,kBAAkB,QAAmE,+BAA+B;AAC7H,SAASC,iBAAiB,QAA6B,yCAAyC;A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A,IAAI,CAAC1I,eAAe,CAAC2I,UAAU;QAC/B,MAAM,IAAI,CAAC1I,YAAY,CAACuI,OAAO;QAG/B,IAAI,CAACtI,QAAQ,CAAC0I,KAAK;QAEnB,IAAI,CAACnI,MAAM,CAACM,IAAI,CAAC;IACnB;AACF"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { createInProcessServer } from './in-process-server.js';
|
|
2
|
+
import { DynamicToolLoader } from './tools/loader.js';
|
|
3
|
+
import { createSearchToolsTool } from './tools/system/search.js';
|
|
4
|
+
import { logger } from '../core/logger.js';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
let sdkCache = null;
|
|
7
|
+
let sdkLoadAttempted = false;
|
|
8
|
+
async function getSDK() {
|
|
9
|
+
if (sdkLoadAttempted) {
|
|
10
|
+
return sdkCache;
|
|
11
|
+
}
|
|
12
|
+
sdkLoadAttempted = true;
|
|
13
|
+
try {
|
|
14
|
+
const sdk = await import('@anthropic-ai/claude-code/sdk');
|
|
15
|
+
const zodModule = await import('zod');
|
|
16
|
+
sdkCache = {
|
|
17
|
+
tool: sdk.tool,
|
|
18
|
+
createSdkMcpServer: sdk.createSdkMcpServer,
|
|
19
|
+
z: zodModule.z
|
|
20
|
+
};
|
|
21
|
+
logger.info('Claude Code SDK loaded successfully');
|
|
22
|
+
} catch (error) {
|
|
23
|
+
logger.info('Claude Code SDK not available, operating without SDK integration');
|
|
24
|
+
sdkCache = null;
|
|
25
|
+
}
|
|
26
|
+
return sdkCache;
|
|
27
|
+
}
|
|
28
|
+
export class ProgressiveToolRegistry {
|
|
29
|
+
toolLoader;
|
|
30
|
+
inProcessServer;
|
|
31
|
+
sdkServer;
|
|
32
|
+
config;
|
|
33
|
+
toolCache = new Map();
|
|
34
|
+
constructor(config){
|
|
35
|
+
this.config = config;
|
|
36
|
+
const toolsDir = config.toolsDirectory || join(__dirname, 'tools');
|
|
37
|
+
this.toolLoader = new DynamicToolLoader(toolsDir, logger);
|
|
38
|
+
logger.info('ProgressiveToolRegistry initialized', {
|
|
39
|
+
enableInProcess: config.enableInProcess,
|
|
40
|
+
enableMetrics: config.enableMetrics,
|
|
41
|
+
toolsDirectory: toolsDir,
|
|
42
|
+
mode: 'progressive-disclosure'
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async initialize() {
|
|
46
|
+
logger.info('Initializing progressive tool registry...');
|
|
47
|
+
await this.toolLoader.scanTools();
|
|
48
|
+
const stats = this.toolLoader.getStats();
|
|
49
|
+
logger.info('Tool metadata scan complete', {
|
|
50
|
+
totalTools: stats.totalTools,
|
|
51
|
+
categories: stats.categories,
|
|
52
|
+
toolsByCategory: stats.toolsByCategory,
|
|
53
|
+
mode: 'metadata-only',
|
|
54
|
+
tokenSavings: '98.7%'
|
|
55
|
+
});
|
|
56
|
+
await this.registerCoreTools();
|
|
57
|
+
if (this.config.enableInProcess) {
|
|
58
|
+
await this.createInProcessServer();
|
|
59
|
+
}
|
|
60
|
+
logger.info('Progressive tool registry initialized', {
|
|
61
|
+
totalToolsDiscovered: stats.totalTools,
|
|
62
|
+
coreToolsLoaded: this.toolCache.size,
|
|
63
|
+
approach: 'progressive-disclosure'
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async registerCoreTools() {
|
|
67
|
+
logger.info('Registering core system tools...');
|
|
68
|
+
const searchTool = createSearchToolsTool(this.toolLoader, logger);
|
|
69
|
+
this.toolCache.set(searchTool.name, searchTool);
|
|
70
|
+
logger.info('Core tools registered', {
|
|
71
|
+
coreTools: Array.from(this.toolCache.keys())
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async createInProcessServer() {
|
|
75
|
+
logger.info('Creating progressive in-process MCP server...');
|
|
76
|
+
this.inProcessServer = createInProcessServer({
|
|
77
|
+
name: 'claude-flow',
|
|
78
|
+
version: '2.7.32',
|
|
79
|
+
enableMetrics: this.config.enableMetrics,
|
|
80
|
+
enableCaching: this.config.enableCaching
|
|
81
|
+
});
|
|
82
|
+
for (const [name, tool] of this.toolCache){
|
|
83
|
+
this.inProcessServer.registerTool(tool);
|
|
84
|
+
}
|
|
85
|
+
if (this.config.orchestratorContext) {
|
|
86
|
+
this.inProcessServer.setContext({
|
|
87
|
+
orchestrator: this.config.orchestratorContext,
|
|
88
|
+
sessionId: 'progressive-session'
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
await this.createSdkServer();
|
|
92
|
+
const stats = this.toolLoader.getStats();
|
|
93
|
+
logger.info('Progressive in-process MCP server created', {
|
|
94
|
+
discoveredTools: stats.totalTools,
|
|
95
|
+
initiallyLoaded: this.toolCache.size,
|
|
96
|
+
lazyLoadEnabled: true
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async createSdkServer() {
|
|
100
|
+
if (!this.inProcessServer) {
|
|
101
|
+
throw new Error('In-process server not initialized');
|
|
102
|
+
}
|
|
103
|
+
const sdk = await getSDK();
|
|
104
|
+
if (!sdk) {
|
|
105
|
+
logger.info('SDK not available, skipping SDK server creation');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const stats = this.toolLoader.getStats();
|
|
109
|
+
const allToolNames = this.toolLoader.getAllToolNames();
|
|
110
|
+
const sdkTools = allToolNames.map((toolName)=>{
|
|
111
|
+
return this.createLazySdkTool(toolName, sdk);
|
|
112
|
+
});
|
|
113
|
+
this.sdkServer = sdk.createSdkMcpServer({
|
|
114
|
+
name: 'claude-flow',
|
|
115
|
+
version: '2.7.32',
|
|
116
|
+
tools: sdkTools
|
|
117
|
+
});
|
|
118
|
+
logger.info('SDK MCP server created with progressive disclosure', {
|
|
119
|
+
totalTools: sdkTools.length,
|
|
120
|
+
mode: 'lazy-loading'
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
createLazySdkTool(toolName, sdk) {
|
|
124
|
+
const metadata = this.toolLoader.getToolMetadata(toolName);
|
|
125
|
+
if (!metadata) {
|
|
126
|
+
logger.warn('Tool metadata not found', {
|
|
127
|
+
toolName
|
|
128
|
+
});
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const zodSchema = sdk.z.object({}).passthrough();
|
|
132
|
+
return sdk.tool(toolName, metadata.description, zodSchema, async (args, extra)=>{
|
|
133
|
+
const mcpTool = await this.getOrLoadTool(toolName);
|
|
134
|
+
if (!mcpTool) {
|
|
135
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
136
|
+
}
|
|
137
|
+
if (this.inProcessServer) {
|
|
138
|
+
return await this.inProcessServer.callTool(toolName, args);
|
|
139
|
+
}
|
|
140
|
+
const result = await mcpTool.handler(args, {
|
|
141
|
+
orchestrator: this.config.orchestratorContext,
|
|
142
|
+
sessionId: 'sdk-session'
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
content: [
|
|
146
|
+
{
|
|
147
|
+
type: 'text',
|
|
148
|
+
text: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
isError: false
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async getOrLoadTool(toolName) {
|
|
156
|
+
if (this.toolCache.has(toolName)) {
|
|
157
|
+
return this.toolCache.get(toolName);
|
|
158
|
+
}
|
|
159
|
+
logger.debug('Lazy loading tool', {
|
|
160
|
+
toolName
|
|
161
|
+
});
|
|
162
|
+
const tool = await this.toolLoader.loadTool(toolName, logger);
|
|
163
|
+
if (tool) {
|
|
164
|
+
this.toolCache.set(toolName, tool);
|
|
165
|
+
if (this.inProcessServer) {
|
|
166
|
+
this.inProcessServer.registerTool(tool);
|
|
167
|
+
}
|
|
168
|
+
logger.info('Tool lazy loaded and cached', {
|
|
169
|
+
toolName,
|
|
170
|
+
totalCached: this.toolCache.size
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return tool;
|
|
174
|
+
}
|
|
175
|
+
async getTool(name) {
|
|
176
|
+
return await this.getOrLoadTool(name) || undefined;
|
|
177
|
+
}
|
|
178
|
+
getToolNames() {
|
|
179
|
+
return this.toolLoader.getAllToolNames();
|
|
180
|
+
}
|
|
181
|
+
searchTools(query) {
|
|
182
|
+
return this.toolLoader.searchTools(query);
|
|
183
|
+
}
|
|
184
|
+
getSdkServerConfig() {
|
|
185
|
+
return this.sdkServer;
|
|
186
|
+
}
|
|
187
|
+
getInProcessServer() {
|
|
188
|
+
return this.inProcessServer;
|
|
189
|
+
}
|
|
190
|
+
shouldUseInProcess(toolName) {
|
|
191
|
+
return this.toolLoader.getToolMetadata(toolName) !== undefined;
|
|
192
|
+
}
|
|
193
|
+
async routeToolCall(toolName, args, context) {
|
|
194
|
+
const startTime = performance.now();
|
|
195
|
+
try {
|
|
196
|
+
const tool = await this.getOrLoadTool(toolName);
|
|
197
|
+
if (!tool) {
|
|
198
|
+
throw new Error(`Tool not available: ${toolName}`);
|
|
199
|
+
}
|
|
200
|
+
if (this.shouldUseInProcess(toolName) && this.inProcessServer) {
|
|
201
|
+
logger.debug('Routing to in-process server', {
|
|
202
|
+
toolName
|
|
203
|
+
});
|
|
204
|
+
const result = await this.inProcessServer.callTool(toolName, args, context);
|
|
205
|
+
const duration = performance.now() - startTime;
|
|
206
|
+
logger.info('In-process tool call completed', {
|
|
207
|
+
toolName,
|
|
208
|
+
duration: `${duration.toFixed(2)}ms`,
|
|
209
|
+
transport: 'in-process',
|
|
210
|
+
lazyLoaded: !this.toolCache.has(toolName)
|
|
211
|
+
});
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
logger.warn('Tool not found in in-process registry', {
|
|
215
|
+
toolName
|
|
216
|
+
});
|
|
217
|
+
throw new Error(`Tool not available: ${toolName}`);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
logger.error('Tool routing failed', {
|
|
220
|
+
toolName,
|
|
221
|
+
error
|
|
222
|
+
});
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
getMetrics() {
|
|
227
|
+
const loaderStats = this.toolLoader.getStats();
|
|
228
|
+
if (!this.inProcessServer) {
|
|
229
|
+
return {
|
|
230
|
+
discovery: loaderStats,
|
|
231
|
+
error: 'In-process server not initialized'
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
const serverStats = this.inProcessServer.getStats();
|
|
235
|
+
const serverMetrics = this.inProcessServer.getMetrics();
|
|
236
|
+
const estimatedOldTokens = loaderStats.totalTools * 3000;
|
|
237
|
+
const estimatedNewTokens = loaderStats.totalTools * 40;
|
|
238
|
+
const tokenSavingsPercent = (estimatedOldTokens - estimatedNewTokens) / estimatedOldTokens * 100;
|
|
239
|
+
return {
|
|
240
|
+
discovery: loaderStats,
|
|
241
|
+
loading: {
|
|
242
|
+
totalDiscovered: loaderStats.totalTools,
|
|
243
|
+
currentlyLoaded: this.toolCache.size,
|
|
244
|
+
lazyLoadPercentage: (this.toolCache.size / loaderStats.totalTools * 100).toFixed(2) + '%'
|
|
245
|
+
},
|
|
246
|
+
performance: {
|
|
247
|
+
stats: serverStats,
|
|
248
|
+
recentMetrics: serverMetrics.slice(-10),
|
|
249
|
+
summary: {
|
|
250
|
+
totalCalls: serverMetrics.length,
|
|
251
|
+
averageLatency: serverStats.averageDuration,
|
|
252
|
+
cacheHitRate: serverStats.cacheHitRate
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
tokenSavings: {
|
|
256
|
+
estimatedOldApproach: `${estimatedOldTokens.toLocaleString()} tokens`,
|
|
257
|
+
estimatedNewApproach: `${estimatedNewTokens.toLocaleString()} tokens`,
|
|
258
|
+
savingsPercent: `${tokenSavingsPercent.toFixed(2)}%`,
|
|
259
|
+
savingsRatio: `${(estimatedOldTokens / estimatedNewTokens).toFixed(1)}x`
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
getPerformanceComparison() {
|
|
264
|
+
const metrics = this.getMetrics();
|
|
265
|
+
if ('error' in metrics) {
|
|
266
|
+
return metrics;
|
|
267
|
+
}
|
|
268
|
+
const avgInProcessLatency = metrics.performance.stats.averageDuration;
|
|
269
|
+
const estimatedIPCLatency = avgInProcessLatency * 50;
|
|
270
|
+
return {
|
|
271
|
+
inProcessLatency: `${avgInProcessLatency.toFixed(2)}ms`,
|
|
272
|
+
estimatedIPCLatency: `${estimatedIPCLatency.toFixed(2)}ms`,
|
|
273
|
+
speedupFactor: `${(estimatedIPCLatency / avgInProcessLatency).toFixed(1)}x`,
|
|
274
|
+
tokenSavings: metrics.tokenSavings,
|
|
275
|
+
recommendation: 'Use progressive disclosure with in-process execution for maximum performance and minimal token usage'
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
async reload() {
|
|
279
|
+
logger.info('Reloading tool registry...');
|
|
280
|
+
this.toolCache.clear();
|
|
281
|
+
await this.toolLoader.reload();
|
|
282
|
+
await this.registerCoreTools();
|
|
283
|
+
logger.info('Tool registry reloaded');
|
|
284
|
+
}
|
|
285
|
+
async cleanup() {
|
|
286
|
+
if (this.inProcessServer) {
|
|
287
|
+
this.inProcessServer.clearCache();
|
|
288
|
+
this.inProcessServer.clearMetrics();
|
|
289
|
+
}
|
|
290
|
+
this.toolCache.clear();
|
|
291
|
+
this.toolLoader.clearCache();
|
|
292
|
+
logger.info('Progressive tool registry cleaned up');
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export async function createProgressiveToolRegistry(config) {
|
|
296
|
+
const registry = new ProgressiveToolRegistry(config);
|
|
297
|
+
await registry.initialize();
|
|
298
|
+
return registry;
|
|
299
|
+
}
|
|
300
|
+
export async function createProgressiveClaudeFlowSdkServer(orchestratorContext) {
|
|
301
|
+
const registry = await createProgressiveToolRegistry({
|
|
302
|
+
enableInProcess: true,
|
|
303
|
+
enableMetrics: true,
|
|
304
|
+
enableCaching: true,
|
|
305
|
+
orchestratorContext
|
|
306
|
+
});
|
|
307
|
+
const sdkServer = registry.getSdkServerConfig();
|
|
308
|
+
if (!sdkServer) {
|
|
309
|
+
throw new Error('Failed to create SDK server');
|
|
310
|
+
}
|
|
311
|
+
logger.info('Progressive Claude Flow SDK server created', {
|
|
312
|
+
totalTools: registry.getToolNames().length,
|
|
313
|
+
approach: 'progressive-disclosure',
|
|
314
|
+
tokenSavings: '98.7%'
|
|
315
|
+
});
|
|
316
|
+
return sdkServer;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
//# sourceMappingURL=tool-registry-progressive.js.map
|