swarmdo 1.45.0 → 1.54.1
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/helpers/hook-handler.cjs +16 -0
- package/.claude/helpers/router.cjs +27 -1
- package/.claude/settings.local.json +7 -0
- package/README.md +6 -2
- package/package.json +1 -1
- package/v3/@swarmdo/cli/dist/src/agent-bridge/bridge.d.ts +104 -0
- package/v3/@swarmdo/cli/dist/src/agent-bridge/bridge.js +133 -0
- package/v3/@swarmdo/cli/dist/src/commands/agent.js +133 -1
- package/v3/@swarmdo/cli/dist/src/commands/config.js +32 -1
- package/v3/@swarmdo/cli/dist/src/commands/hidden-coupling.d.ts +19 -0
- package/v3/@swarmdo/cli/dist/src/commands/hidden-coupling.js +92 -0
- package/v3/@swarmdo/cli/dist/src/commands/index.js +14 -4
- package/v3/@swarmdo/cli/dist/src/commands/ownership.d.ts +18 -0
- package/v3/@swarmdo/cli/dist/src/commands/ownership.js +88 -0
- package/v3/@swarmdo/cli/dist/src/commands/pack.js +4 -4
- package/v3/@swarmdo/cli/dist/src/commands/standup.d.ts +18 -0
- package/v3/@swarmdo/cli/dist/src/commands/standup.js +116 -0
- package/v3/@swarmdo/cli/dist/src/commands/swarm.js +29 -0
- package/v3/@swarmdo/cli/dist/src/config-lint/commands-lint.d.ts +31 -0
- package/v3/@swarmdo/cli/dist/src/config-lint/commands-lint.js +127 -0
- package/v3/@swarmdo/cli/dist/src/config-lint/lint.d.ts +5 -0
- package/v3/@swarmdo/cli/dist/src/config-lint/lint.js +4 -0
- package/v3/@swarmdo/cli/dist/src/coupling/hidden.d.ts +45 -0
- package/v3/@swarmdo/cli/dist/src/coupling/hidden.js +66 -0
- package/v3/@swarmdo/cli/dist/src/init/helpers-generator.js +41 -1
- package/v3/@swarmdo/cli/dist/src/mcp-client.js +2 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/agent-tools.js +166 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/index.d.ts +1 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/index.js +1 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/ownership-tools.d.ts +14 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/ownership-tools.js +51 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/profiles.js +1 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/swarm-tools.d.ts +33 -0
- package/v3/@swarmdo/cli/dist/src/mcp-tools/swarm-tools.js +73 -38
- package/v3/@swarmdo/cli/dist/src/ownership/ownership.d.ts +61 -0
- package/v3/@swarmdo/cli/dist/src/ownership/ownership.js +151 -0
- package/v3/@swarmdo/cli/dist/src/pack/pack.d.ts +1 -1
- package/v3/@swarmdo/cli/dist/src/pack/pack.js +12 -4
- package/v3/@swarmdo/cli/dist/src/redact/redact.js +28 -9
- package/v3/@swarmdo/cli/dist/src/standup/standup.d.ts +83 -0
- package/v3/@swarmdo/cli/dist/src/standup/standup.js +157 -0
- package/v3/@swarmdo/cli/package.json +1 -1
- package/v3/@swarmdo/cli-core/dist/src/index.js +1 -1
- package/v3/@swarmdo/codex/dist/cli.js +0 -0
- package/v3/@swarmdo/hooks/dist/cli/guidance-cli.js +0 -0
- package/v3/@swarmdo/hooks/dist/statusline/index.d.ts +3 -3
- package/v3/@swarmdo/hooks/dist/statusline/index.js +3 -3
- package/v3/@swarmdo/integration/dist/__tests__/agentic-flow-agent.test.js +1 -4
- package/v3/@swarmdo/neural/dist/flash-attention.d.ts +1 -1
- package/v3/@swarmdo/neural/dist/flash-attention.js +1 -1
- package/v3/@swarmdo/plugin-agent-federation/dist/plugin.js +1 -1
- package/v3/@swarmdo/plugin-agent-federation/dist/transport/midstream-aware-loader.js +2 -2
- package/v3/@swarmdo/plugin-iot-cognitum/dist/application/index.d.ts +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/application/index.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/application/iot-coordinator.d.ts +138 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/application/iot-coordinator.js +418 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/bin.d.ts +15 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/bin.js +240 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/cli-commands.d.ts +7 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/cli-commands.js +508 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-agent.d.ts +54 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-agent.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-fleet.d.ts +46 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-fleet.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-trust-level.d.ts +18 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/device-trust-level.js +28 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/index.d.ts +5 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/index.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/telemetry.d.ts +35 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/entities/telemetry.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/device-repository.d.ts +11 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/device-repository.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/fleet-repository.d.ts +9 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/fleet-repository.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/index.d.ts +5 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/index.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/telemetry-repository.d.ts +12 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/telemetry-repository.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/trust-history-repository.d.ts +19 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/repositories/trust-history-repository.js +2 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/anomaly-detection-service.d.ts +44 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/anomaly-detection-service.js +117 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/device-lifecycle-service.d.ts +70 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/device-lifecycle-service.js +194 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/firmware-orchestration-service.d.ts +69 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/firmware-orchestration-service.js +139 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/fleet-topology-service.d.ts +34 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/fleet-topology-service.js +101 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/index.d.ts +10 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/index.js +10 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/mesh-service.d.ts +64 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/mesh-service.js +70 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/sona-integration-service.d.ts +44 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/sona-integration-service.js +79 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-ingestion-service.d.ts +37 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-ingestion-service.js +39 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-service.d.ts +67 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/telemetry-service.js +58 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/witness-verification-service.d.ts +45 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/domain/services/witness-verification-service.js +63 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/index.d.ts +26 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/index.js +17 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/agentdb-telemetry-repository.d.ts +51 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/agentdb-telemetry-repository.js +110 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-device-repository.d.ts +13 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-device-repository.js +25 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-fleet-repository.d.ts +11 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-fleet-repository.js +19 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-trust-history-repository.d.ts +11 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/in-memory-trust-history-repository.js +27 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/index.d.ts +6 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/index.js +6 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/seed-client-factory.d.ts +41 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/infrastructure/seed-client-factory.js +64 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/mcp-tools.d.ts +8 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/mcp-tools.js +703 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/plugin.d.ts +23 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/plugin.js +239 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/anomaly-scan-worker.d.ts +17 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/anomaly-scan-worker.js +42 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/firmware-watch-worker.d.ts +18 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/firmware-watch-worker.js +45 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/health-probe-worker.d.ts +19 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/health-probe-worker.js +50 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/mesh-sync-worker.d.ts +19 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/mesh-sync-worker.js +47 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/telemetry-ingest-worker.d.ts +17 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/telemetry-ingest-worker.js +40 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/witness-audit-worker.d.ts +18 -0
- package/v3/@swarmdo/plugin-iot-cognitum/dist/workers/witness-audit-worker.js +51 -0
- package/v3/@swarmdo/providers/dist/swarmvector-provider.d.ts +1 -1
- package/v3/@swarmdo/providers/dist/swarmvector-provider.js +1 -1
- package/v3/@swarmdo/security/dist/input-validator.d.ts +6 -6
- package/v3/@swarmdo/shared/dist/hooks/safety/git-commit.js +1 -1
- package/v3/@swarmdo/shared/dist/mcp/transport/http.js +1 -8
- package/v3/@swarmdo/testing/dist/fixtures/agent-fixtures.d.ts +214 -0
- package/v3/@swarmdo/testing/dist/fixtures/agent-fixtures.js +595 -0
- package/v3/@swarmdo/testing/dist/fixtures/agents.d.ts +76 -0
- package/v3/@swarmdo/testing/dist/fixtures/agents.js +158 -0
- package/v3/@swarmdo/testing/dist/fixtures/configurations.d.ts +157 -0
- package/v3/@swarmdo/testing/dist/fixtures/configurations.js +337 -0
- package/v3/@swarmdo/testing/dist/fixtures/index.d.ts +10 -0
- package/v3/@swarmdo/testing/dist/fixtures/index.js +17 -0
- package/v3/@swarmdo/testing/dist/fixtures/mcp-fixtures.d.ts +329 -0
- package/v3/@swarmdo/testing/dist/fixtures/mcp-fixtures.js +714 -0
- package/v3/@swarmdo/testing/dist/fixtures/memory-entries.d.ts +159 -0
- package/v3/@swarmdo/testing/dist/fixtures/memory-entries.js +262 -0
- package/v3/@swarmdo/testing/dist/fixtures/memory-fixtures.d.ts +290 -0
- package/v3/@swarmdo/testing/dist/fixtures/memory-fixtures.js +547 -0
- package/v3/@swarmdo/testing/dist/fixtures/swarm-fixtures.d.ts +289 -0
- package/v3/@swarmdo/testing/dist/fixtures/swarm-fixtures.js +534 -0
- package/v3/@swarmdo/testing/dist/fixtures/tasks.d.ts +106 -0
- package/v3/@swarmdo/testing/dist/fixtures/tasks.js +229 -0
- package/v3/@swarmdo/testing/dist/helpers/assertion-helpers.d.ts +213 -0
- package/v3/@swarmdo/testing/dist/helpers/assertion-helpers.js +435 -0
- package/v3/@swarmdo/testing/dist/helpers/assertions.d.ts +135 -0
- package/v3/@swarmdo/testing/dist/helpers/assertions.js +217 -0
- package/v3/@swarmdo/testing/dist/helpers/create-mock.d.ts +96 -0
- package/v3/@swarmdo/testing/dist/helpers/create-mock.js +164 -0
- package/v3/@swarmdo/testing/dist/helpers/index.d.ts +14 -0
- package/v3/@swarmdo/testing/dist/helpers/index.js +22 -0
- package/v3/@swarmdo/testing/dist/helpers/mock-factory.d.ts +323 -0
- package/v3/@swarmdo/testing/dist/helpers/mock-factory.js +350 -0
- package/v3/@swarmdo/testing/dist/helpers/setup-teardown.d.ts +271 -0
- package/v3/@swarmdo/testing/dist/helpers/setup-teardown.js +446 -0
- package/v3/@swarmdo/testing/dist/helpers/swarm-instance.d.ts +142 -0
- package/v3/@swarmdo/testing/dist/helpers/swarm-instance.js +205 -0
- package/v3/@swarmdo/testing/dist/helpers/test-application.d.ts +190 -0
- package/v3/@swarmdo/testing/dist/helpers/test-application.js +138 -0
- package/v3/@swarmdo/testing/dist/helpers/test-utils.d.ts +274 -0
- package/v3/@swarmdo/testing/dist/helpers/test-utils.js +456 -0
- package/v3/@swarmdo/testing/dist/index.d.ts +42 -0
- package/v3/@swarmdo/testing/dist/index.js +66 -0
- package/v3/@swarmdo/testing/dist/mocks/index.d.ts +8 -0
- package/v3/@swarmdo/testing/dist/mocks/index.js +10 -0
- package/v3/@swarmdo/testing/dist/mocks/mock-mcp-client.d.ts +206 -0
- package/v3/@swarmdo/testing/dist/mocks/mock-mcp-client.js +575 -0
- package/v3/@swarmdo/testing/dist/mocks/mock-services.d.ts +287 -0
- package/v3/@swarmdo/testing/dist/mocks/mock-services.js +563 -0
- package/v3/@swarmdo/testing/dist/regression/api-contract.d.ts +109 -0
- package/v3/@swarmdo/testing/dist/regression/api-contract.js +374 -0
- package/v3/@swarmdo/testing/dist/regression/index.d.ts +18 -0
- package/v3/@swarmdo/testing/dist/regression/index.js +18 -0
- package/v3/@swarmdo/testing/dist/regression/integration-regression.d.ts +67 -0
- package/v3/@swarmdo/testing/dist/regression/integration-regression.js +334 -0
- package/v3/@swarmdo/testing/dist/regression/performance-baseline.d.ts +106 -0
- package/v3/@swarmdo/testing/dist/regression/performance-baseline.js +268 -0
- package/v3/@swarmdo/testing/dist/regression/regression-runner.d.ts +124 -0
- package/v3/@swarmdo/testing/dist/regression/regression-runner.js +227 -0
- package/v3/@swarmdo/testing/dist/regression/security-regression.d.ts +73 -0
- package/v3/@swarmdo/testing/dist/regression/security-regression.js +258 -0
- package/v3/@swarmdo/testing/dist/setup.d.ts +43 -0
- package/v3/@swarmdo/testing/dist/setup.js +91 -0
- package/v3/@swarmdo/testing/dist/v2-compat/api-compat.test.d.ts +10 -0
- package/v3/@swarmdo/testing/dist/v2-compat/api-compat.test.js +433 -0
- package/v3/@swarmdo/testing/dist/v2-compat/cli-compat.test.d.ts +10 -0
- package/v3/@swarmdo/testing/dist/v2-compat/cli-compat.test.js +352 -0
- package/v3/@swarmdo/testing/dist/v2-compat/compatibility-validator.d.ts +206 -0
- package/v3/@swarmdo/testing/dist/v2-compat/compatibility-validator.js +839 -0
- package/v3/@swarmdo/testing/dist/v2-compat/hooks-compat.test.d.ts +10 -0
- package/v3/@swarmdo/testing/dist/v2-compat/hooks-compat.test.js +428 -0
- package/v3/@swarmdo/testing/dist/v2-compat/index.d.ts +38 -0
- package/v3/@swarmdo/testing/dist/v2-compat/index.js +41 -0
- package/v3/@swarmdo/testing/dist/v2-compat/mcp-compat.test.d.ts +10 -0
- package/v3/@swarmdo/testing/dist/v2-compat/mcp-compat.test.js +419 -0
- package/v3/@swarmdo/testing/dist/v2-compat/report-generator.d.ts +34 -0
- package/v3/@swarmdo/testing/dist/v2-compat/report-generator.js +372 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @swarmdo/testing - Mock MCP Client
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive mock MCP client for testing CLI and server interactions.
|
|
5
|
+
* Simulates full MCP protocol behavior with request/response tracking.
|
|
6
|
+
*/
|
|
7
|
+
import { vi } from 'vitest';
|
|
8
|
+
/**
|
|
9
|
+
* Mock MCP Client with full protocol simulation
|
|
10
|
+
*/
|
|
11
|
+
export class MockMCPClient {
|
|
12
|
+
_connected = false;
|
|
13
|
+
_session = null;
|
|
14
|
+
_tools = new Map();
|
|
15
|
+
_resources = new Map();
|
|
16
|
+
_prompts = new Map();
|
|
17
|
+
_requestHistory = [];
|
|
18
|
+
_responseHistory = [];
|
|
19
|
+
_toolHandlers = new Map();
|
|
20
|
+
_errorSimulation = null;
|
|
21
|
+
_latencySimulation = 0;
|
|
22
|
+
// Mock methods for verification
|
|
23
|
+
connect = vi.fn(async () => {
|
|
24
|
+
if (this._errorSimulation?.onConnect) {
|
|
25
|
+
throw new Error(this._errorSimulation.onConnect);
|
|
26
|
+
}
|
|
27
|
+
await this.simulateLatency();
|
|
28
|
+
this._connected = true;
|
|
29
|
+
this._session = {
|
|
30
|
+
sessionId: `session-${Date.now()}`,
|
|
31
|
+
clientInfo: {
|
|
32
|
+
name: 'mock-client',
|
|
33
|
+
version: '1.0.0',
|
|
34
|
+
},
|
|
35
|
+
capabilities: {
|
|
36
|
+
tools: true,
|
|
37
|
+
resources: true,
|
|
38
|
+
prompts: true,
|
|
39
|
+
},
|
|
40
|
+
startedAt: new Date(),
|
|
41
|
+
lastActivity: new Date(),
|
|
42
|
+
requestCount: 0,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
disconnect = vi.fn(async () => {
|
|
46
|
+
if (this._errorSimulation?.onDisconnect) {
|
|
47
|
+
throw new Error(this._errorSimulation.onDisconnect);
|
|
48
|
+
}
|
|
49
|
+
this._connected = false;
|
|
50
|
+
this._session = null;
|
|
51
|
+
});
|
|
52
|
+
callTool = vi.fn(async (name, params) => {
|
|
53
|
+
this.ensureConnected();
|
|
54
|
+
const request = {
|
|
55
|
+
id: `req-${Date.now()}`,
|
|
56
|
+
method: 'tools/call',
|
|
57
|
+
params: { name, arguments: params },
|
|
58
|
+
timestamp: new Date(),
|
|
59
|
+
};
|
|
60
|
+
this._requestHistory.push(request);
|
|
61
|
+
if (this._session) {
|
|
62
|
+
this._session.requestCount++;
|
|
63
|
+
this._session.lastActivity = new Date();
|
|
64
|
+
}
|
|
65
|
+
await this.simulateLatency();
|
|
66
|
+
// Check for error simulation
|
|
67
|
+
if (this._errorSimulation?.onToolCall?.[name]) {
|
|
68
|
+
const error = this._errorSimulation.onToolCall[name];
|
|
69
|
+
const response = {
|
|
70
|
+
id: request.id,
|
|
71
|
+
error: typeof error === 'string' ? { code: -32000, message: error } : error,
|
|
72
|
+
timestamp: new Date(),
|
|
73
|
+
};
|
|
74
|
+
this._responseHistory.push(response);
|
|
75
|
+
throw new MCPClientError(response.error.message, response.error.code);
|
|
76
|
+
}
|
|
77
|
+
// Check for custom handler
|
|
78
|
+
const handler = this._toolHandlers.get(name);
|
|
79
|
+
if (handler) {
|
|
80
|
+
const result = await handler(params);
|
|
81
|
+
const response = {
|
|
82
|
+
id: request.id,
|
|
83
|
+
result,
|
|
84
|
+
timestamp: new Date(),
|
|
85
|
+
};
|
|
86
|
+
this._responseHistory.push(response);
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
// Check for registered tool
|
|
90
|
+
const tool = this._tools.get(name);
|
|
91
|
+
if (!tool) {
|
|
92
|
+
const response = {
|
|
93
|
+
id: request.id,
|
|
94
|
+
error: { code: -32601, message: `Tool not found: ${name}` },
|
|
95
|
+
timestamp: new Date(),
|
|
96
|
+
};
|
|
97
|
+
this._responseHistory.push(response);
|
|
98
|
+
throw new MCPClientError(`Tool not found: ${name}`, -32601);
|
|
99
|
+
}
|
|
100
|
+
// Default success response
|
|
101
|
+
const result = {
|
|
102
|
+
content: [{ type: 'text', text: JSON.stringify({ success: true, tool: name, params }) }],
|
|
103
|
+
};
|
|
104
|
+
const response = {
|
|
105
|
+
id: request.id,
|
|
106
|
+
result,
|
|
107
|
+
timestamp: new Date(),
|
|
108
|
+
};
|
|
109
|
+
this._responseHistory.push(response);
|
|
110
|
+
return result;
|
|
111
|
+
});
|
|
112
|
+
listTools = vi.fn(async () => {
|
|
113
|
+
this.ensureConnected();
|
|
114
|
+
await this.simulateLatency();
|
|
115
|
+
return Array.from(this._tools.values());
|
|
116
|
+
});
|
|
117
|
+
readResource = vi.fn(async (uri) => {
|
|
118
|
+
this.ensureConnected();
|
|
119
|
+
const request = {
|
|
120
|
+
id: `req-${Date.now()}`,
|
|
121
|
+
method: 'resources/read',
|
|
122
|
+
params: { uri },
|
|
123
|
+
timestamp: new Date(),
|
|
124
|
+
};
|
|
125
|
+
this._requestHistory.push(request);
|
|
126
|
+
await this.simulateLatency();
|
|
127
|
+
const resource = this._resources.get(uri);
|
|
128
|
+
if (!resource) {
|
|
129
|
+
throw new MCPClientError(`Resource not found: ${uri}`, -32002);
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
type: 'resource',
|
|
133
|
+
resource: {
|
|
134
|
+
uri,
|
|
135
|
+
mimeType: resource.mimeType,
|
|
136
|
+
text: JSON.stringify({ name: resource.name, description: resource.description }),
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
listResources = vi.fn(async () => {
|
|
141
|
+
this.ensureConnected();
|
|
142
|
+
await this.simulateLatency();
|
|
143
|
+
return Array.from(this._resources.values());
|
|
144
|
+
});
|
|
145
|
+
getPrompt = vi.fn(async (name, args) => {
|
|
146
|
+
this.ensureConnected();
|
|
147
|
+
const prompt = this._prompts.get(name);
|
|
148
|
+
if (!prompt) {
|
|
149
|
+
throw new MCPClientError(`Prompt not found: ${name}`, -32003);
|
|
150
|
+
}
|
|
151
|
+
await this.simulateLatency();
|
|
152
|
+
return {
|
|
153
|
+
messages: [
|
|
154
|
+
{
|
|
155
|
+
role: 'user',
|
|
156
|
+
content: { type: 'text', text: `Prompt: ${name}\nArgs: ${JSON.stringify(args)}` },
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
listPrompts = vi.fn(async () => {
|
|
162
|
+
this.ensureConnected();
|
|
163
|
+
await this.simulateLatency();
|
|
164
|
+
return Array.from(this._prompts.values());
|
|
165
|
+
});
|
|
166
|
+
isConnected = vi.fn(() => this._connected);
|
|
167
|
+
getSession = vi.fn(() => this._session);
|
|
168
|
+
/**
|
|
169
|
+
* Register a tool
|
|
170
|
+
*/
|
|
171
|
+
registerTool(tool) {
|
|
172
|
+
this._tools.set(tool.name, tool);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Register multiple tools
|
|
176
|
+
*/
|
|
177
|
+
registerTools(tools) {
|
|
178
|
+
for (const tool of tools) {
|
|
179
|
+
this.registerTool(tool);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Register a custom tool handler
|
|
184
|
+
*/
|
|
185
|
+
setToolHandler(name, handler) {
|
|
186
|
+
this._toolHandlers.set(name, handler);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Register a resource
|
|
190
|
+
*/
|
|
191
|
+
registerResource(resource) {
|
|
192
|
+
this._resources.set(resource.uri, resource);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Register multiple resources
|
|
196
|
+
*/
|
|
197
|
+
registerResources(resources) {
|
|
198
|
+
for (const resource of resources) {
|
|
199
|
+
this.registerResource(resource);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Register a prompt
|
|
204
|
+
*/
|
|
205
|
+
registerPrompt(prompt) {
|
|
206
|
+
this._prompts.set(prompt.name, prompt);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Register multiple prompts
|
|
210
|
+
*/
|
|
211
|
+
registerPrompts(prompts) {
|
|
212
|
+
for (const prompt of prompts) {
|
|
213
|
+
this.registerPrompt(prompt);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Configure error simulation
|
|
218
|
+
*/
|
|
219
|
+
simulateErrors(config) {
|
|
220
|
+
this._errorSimulation = config;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Configure latency simulation
|
|
224
|
+
*/
|
|
225
|
+
setLatency(ms) {
|
|
226
|
+
this._latencySimulation = ms;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get request history
|
|
230
|
+
*/
|
|
231
|
+
getRequestHistory() {
|
|
232
|
+
return [...this._requestHistory];
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Get response history
|
|
236
|
+
*/
|
|
237
|
+
getResponseHistory() {
|
|
238
|
+
return [...this._responseHistory];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Get last request
|
|
242
|
+
*/
|
|
243
|
+
getLastRequest() {
|
|
244
|
+
return this._requestHistory[this._requestHistory.length - 1];
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get last response
|
|
248
|
+
*/
|
|
249
|
+
getLastResponse() {
|
|
250
|
+
return this._responseHistory[this._responseHistory.length - 1];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Clear history
|
|
254
|
+
*/
|
|
255
|
+
clearHistory() {
|
|
256
|
+
this._requestHistory = [];
|
|
257
|
+
this._responseHistory = [];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Reset client to initial state
|
|
261
|
+
*/
|
|
262
|
+
reset() {
|
|
263
|
+
this._connected = false;
|
|
264
|
+
this._session = null;
|
|
265
|
+
this._tools.clear();
|
|
266
|
+
this._resources.clear();
|
|
267
|
+
this._prompts.clear();
|
|
268
|
+
this._requestHistory = [];
|
|
269
|
+
this._responseHistory = [];
|
|
270
|
+
this._toolHandlers.clear();
|
|
271
|
+
this._errorSimulation = null;
|
|
272
|
+
this._latencySimulation = 0;
|
|
273
|
+
vi.clearAllMocks();
|
|
274
|
+
}
|
|
275
|
+
ensureConnected() {
|
|
276
|
+
if (!this._connected) {
|
|
277
|
+
throw new MCPClientError('Not connected', -32000);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
async simulateLatency() {
|
|
281
|
+
if (this._latencySimulation > 0) {
|
|
282
|
+
await new Promise(resolve => setTimeout(resolve, this._latencySimulation));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Mock MCP Server for testing server-side behavior
|
|
288
|
+
*/
|
|
289
|
+
export class MockMCPServer {
|
|
290
|
+
_running = false;
|
|
291
|
+
_config = null;
|
|
292
|
+
_tools = new Map();
|
|
293
|
+
_resources = new Map();
|
|
294
|
+
_prompts = new Map();
|
|
295
|
+
_connections = [];
|
|
296
|
+
_requestLog = [];
|
|
297
|
+
_errorCount = 0;
|
|
298
|
+
start = vi.fn(async (config) => {
|
|
299
|
+
this._config = config;
|
|
300
|
+
this._running = true;
|
|
301
|
+
// Register configured tools/resources/prompts
|
|
302
|
+
if (config.tools) {
|
|
303
|
+
for (const tool of config.tools) {
|
|
304
|
+
this._tools.set(tool.name, tool);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (config.resources) {
|
|
308
|
+
for (const resource of config.resources) {
|
|
309
|
+
this._resources.set(resource.uri, resource);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (config.prompts) {
|
|
313
|
+
for (const prompt of config.prompts) {
|
|
314
|
+
this._prompts.set(prompt.name, prompt);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
stop = vi.fn(async () => {
|
|
319
|
+
for (const conn of this._connections) {
|
|
320
|
+
await conn.close();
|
|
321
|
+
}
|
|
322
|
+
this._connections = [];
|
|
323
|
+
this._running = false;
|
|
324
|
+
});
|
|
325
|
+
handleRequest = vi.fn(async (request) => {
|
|
326
|
+
this._requestLog.push(request);
|
|
327
|
+
try {
|
|
328
|
+
switch (request.method) {
|
|
329
|
+
case 'tools/call':
|
|
330
|
+
return this.handleToolCall(request);
|
|
331
|
+
case 'resources/read':
|
|
332
|
+
return this.handleResourceRead(request);
|
|
333
|
+
case 'prompts/get':
|
|
334
|
+
return this.handlePromptGet(request);
|
|
335
|
+
case 'tools/list':
|
|
336
|
+
return { id: request.id, result: Array.from(this._tools.values()), timestamp: new Date() };
|
|
337
|
+
case 'resources/list':
|
|
338
|
+
return { id: request.id, result: Array.from(this._resources.values()), timestamp: new Date() };
|
|
339
|
+
case 'prompts/list':
|
|
340
|
+
return { id: request.id, result: Array.from(this._prompts.values()), timestamp: new Date() };
|
|
341
|
+
default:
|
|
342
|
+
throw new MCPClientError(`Unknown method: ${request.method}`, -32601);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
this._errorCount++;
|
|
347
|
+
return {
|
|
348
|
+
id: request.id,
|
|
349
|
+
error: { code: -32000, message: error.message },
|
|
350
|
+
timestamp: new Date(),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
registerTool = vi.fn((tool) => {
|
|
355
|
+
this._tools.set(tool.name, tool);
|
|
356
|
+
});
|
|
357
|
+
registerResource = vi.fn((resource) => {
|
|
358
|
+
this._resources.set(resource.uri, resource);
|
|
359
|
+
});
|
|
360
|
+
registerPrompt = vi.fn((prompt) => {
|
|
361
|
+
this._prompts.set(prompt.name, prompt);
|
|
362
|
+
});
|
|
363
|
+
getStatus = vi.fn(() => ({
|
|
364
|
+
running: this._running,
|
|
365
|
+
transport: this._config?.transport.type ?? 'stdio',
|
|
366
|
+
connectedClients: this._connections.length,
|
|
367
|
+
toolsRegistered: this._tools.size,
|
|
368
|
+
resourcesRegistered: this._resources.size,
|
|
369
|
+
promptsRegistered: this._prompts.size,
|
|
370
|
+
requestsHandled: this._requestLog.length,
|
|
371
|
+
errorsCount: this._errorCount,
|
|
372
|
+
uptime: this._running ? Date.now() : 0,
|
|
373
|
+
}));
|
|
374
|
+
/**
|
|
375
|
+
* Simulate a client connection
|
|
376
|
+
*/
|
|
377
|
+
acceptConnection() {
|
|
378
|
+
const conn = new MockMCPConnection(this);
|
|
379
|
+
this._connections.push(conn);
|
|
380
|
+
return conn;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get request log
|
|
384
|
+
*/
|
|
385
|
+
getRequestLog() {
|
|
386
|
+
return [...this._requestLog];
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Reset server
|
|
390
|
+
*/
|
|
391
|
+
reset() {
|
|
392
|
+
this._running = false;
|
|
393
|
+
this._config = null;
|
|
394
|
+
this._tools.clear();
|
|
395
|
+
this._resources.clear();
|
|
396
|
+
this._prompts.clear();
|
|
397
|
+
this._connections = [];
|
|
398
|
+
this._requestLog = [];
|
|
399
|
+
this._errorCount = 0;
|
|
400
|
+
vi.clearAllMocks();
|
|
401
|
+
}
|
|
402
|
+
handleToolCall(request) {
|
|
403
|
+
const { name, arguments: params } = request.params;
|
|
404
|
+
const tool = this._tools.get(name);
|
|
405
|
+
if (!tool) {
|
|
406
|
+
return {
|
|
407
|
+
id: request.id,
|
|
408
|
+
error: { code: -32601, message: `Tool not found: ${name}` },
|
|
409
|
+
timestamp: new Date(),
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
id: request.id,
|
|
414
|
+
result: {
|
|
415
|
+
content: [{ type: 'text', text: JSON.stringify({ success: true, tool: name }) }],
|
|
416
|
+
},
|
|
417
|
+
timestamp: new Date(),
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
handleResourceRead(request) {
|
|
421
|
+
const { uri } = request.params;
|
|
422
|
+
const resource = this._resources.get(uri);
|
|
423
|
+
if (!resource) {
|
|
424
|
+
return {
|
|
425
|
+
id: request.id,
|
|
426
|
+
error: { code: -32002, message: `Resource not found: ${uri}` },
|
|
427
|
+
timestamp: new Date(),
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
id: request.id,
|
|
432
|
+
result: {
|
|
433
|
+
type: 'resource',
|
|
434
|
+
resource: { uri, mimeType: resource.mimeType, text: '{}' },
|
|
435
|
+
},
|
|
436
|
+
timestamp: new Date(),
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
handlePromptGet(request) {
|
|
440
|
+
const { name } = request.params;
|
|
441
|
+
const prompt = this._prompts.get(name);
|
|
442
|
+
if (!prompt) {
|
|
443
|
+
return {
|
|
444
|
+
id: request.id,
|
|
445
|
+
error: { code: -32003, message: `Prompt not found: ${name}` },
|
|
446
|
+
timestamp: new Date(),
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
id: request.id,
|
|
451
|
+
result: {
|
|
452
|
+
messages: [{ role: 'user', content: { type: 'text', text: `Prompt: ${name}` } }],
|
|
453
|
+
},
|
|
454
|
+
timestamp: new Date(),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Mock MCP Connection
|
|
460
|
+
*/
|
|
461
|
+
export class MockMCPConnection {
|
|
462
|
+
_open = true;
|
|
463
|
+
_server;
|
|
464
|
+
constructor(server) {
|
|
465
|
+
this._server = server;
|
|
466
|
+
}
|
|
467
|
+
send = vi.fn(async (request) => {
|
|
468
|
+
if (!this._open) {
|
|
469
|
+
throw new MCPClientError('Connection closed', -32000);
|
|
470
|
+
}
|
|
471
|
+
return this._server.handleRequest(request);
|
|
472
|
+
});
|
|
473
|
+
close = vi.fn(async () => {
|
|
474
|
+
this._open = false;
|
|
475
|
+
});
|
|
476
|
+
isOpen() {
|
|
477
|
+
return this._open;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* MCP Client Error
|
|
482
|
+
*/
|
|
483
|
+
export class MCPClientError extends Error {
|
|
484
|
+
code;
|
|
485
|
+
constructor(message, code) {
|
|
486
|
+
super(message);
|
|
487
|
+
this.code = code;
|
|
488
|
+
this.name = 'MCPClientError';
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Create a pre-configured mock MCP client with standard tools
|
|
493
|
+
*/
|
|
494
|
+
export function createStandardMockMCPClient() {
|
|
495
|
+
const client = new MockMCPClient();
|
|
496
|
+
// Register standard Swarmdo tools
|
|
497
|
+
client.registerTool({
|
|
498
|
+
name: 'swarm_init',
|
|
499
|
+
description: 'Initialize a new swarm',
|
|
500
|
+
inputSchema: {
|
|
501
|
+
type: 'object',
|
|
502
|
+
properties: {
|
|
503
|
+
topology: { type: 'string' },
|
|
504
|
+
maxAgents: { type: 'number' },
|
|
505
|
+
},
|
|
506
|
+
required: ['topology'],
|
|
507
|
+
},
|
|
508
|
+
});
|
|
509
|
+
client.registerTool({
|
|
510
|
+
name: 'agent_spawn',
|
|
511
|
+
description: 'Spawn a new agent',
|
|
512
|
+
inputSchema: {
|
|
513
|
+
type: 'object',
|
|
514
|
+
properties: {
|
|
515
|
+
type: { type: 'string' },
|
|
516
|
+
name: { type: 'string' },
|
|
517
|
+
},
|
|
518
|
+
required: ['type'],
|
|
519
|
+
},
|
|
520
|
+
});
|
|
521
|
+
client.registerTool({
|
|
522
|
+
name: 'task_orchestrate',
|
|
523
|
+
description: 'Orchestrate a task',
|
|
524
|
+
inputSchema: {
|
|
525
|
+
type: 'object',
|
|
526
|
+
properties: {
|
|
527
|
+
taskName: { type: 'string' },
|
|
528
|
+
taskType: { type: 'string' },
|
|
529
|
+
},
|
|
530
|
+
required: ['taskName', 'taskType'],
|
|
531
|
+
},
|
|
532
|
+
});
|
|
533
|
+
client.registerTool({
|
|
534
|
+
name: 'memory_store',
|
|
535
|
+
description: 'Store a value in memory',
|
|
536
|
+
inputSchema: {
|
|
537
|
+
type: 'object',
|
|
538
|
+
properties: {
|
|
539
|
+
key: { type: 'string' },
|
|
540
|
+
value: { type: 'object' },
|
|
541
|
+
},
|
|
542
|
+
required: ['key', 'value'],
|
|
543
|
+
},
|
|
544
|
+
});
|
|
545
|
+
client.registerTool({
|
|
546
|
+
name: 'memory_search',
|
|
547
|
+
description: 'Search memory',
|
|
548
|
+
inputSchema: {
|
|
549
|
+
type: 'object',
|
|
550
|
+
properties: {
|
|
551
|
+
query: { type: 'string' },
|
|
552
|
+
topK: { type: 'number' },
|
|
553
|
+
},
|
|
554
|
+
required: ['query'],
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
return client;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Create a mock MCP client that simulates failures
|
|
561
|
+
*/
|
|
562
|
+
export function createFailingMockMCPClient(errorConfig) {
|
|
563
|
+
const client = new MockMCPClient();
|
|
564
|
+
client.simulateErrors(errorConfig);
|
|
565
|
+
return client;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Create a mock MCP client with latency
|
|
569
|
+
*/
|
|
570
|
+
export function createSlowMockMCPClient(latencyMs) {
|
|
571
|
+
const client = new MockMCPClient();
|
|
572
|
+
client.setLatency(latencyMs);
|
|
573
|
+
return client;
|
|
574
|
+
}
|
|
575
|
+
//# sourceMappingURL=mock-mcp-client.js.map
|