imcp 0.0.19 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/.roo/rules-code/rules.md +88 -0
  2. package/dist/cli/index.js +1 -45
  3. package/dist/core/installers/clients/BaseClientInstaller.d.ts +1 -5
  4. package/dist/core/installers/clients/BaseClientInstaller.js +40 -38
  5. package/dist/core/installers/clients/ClientInstaller.d.ts +9 -9
  6. package/dist/core/installers/clients/ClientInstaller.js +105 -99
  7. package/dist/core/installers/requirements/BaseInstaller.d.ts +9 -1
  8. package/dist/core/installers/requirements/CommandInstaller.d.ts +9 -1
  9. package/dist/core/installers/requirements/CommandInstaller.js +46 -12
  10. package/dist/core/installers/requirements/GeneralInstaller.d.ts +11 -1
  11. package/dist/core/installers/requirements/GeneralInstaller.js +46 -10
  12. package/dist/core/installers/requirements/InstallerFactory.d.ts +3 -1
  13. package/dist/core/installers/requirements/InstallerFactory.js +3 -2
  14. package/dist/core/installers/requirements/NpmInstaller.d.ts +4 -2
  15. package/dist/core/installers/requirements/NpmInstaller.js +38 -22
  16. package/dist/core/installers/requirements/PipInstaller.d.ts +3 -1
  17. package/dist/core/installers/requirements/PipInstaller.js +58 -36
  18. package/dist/core/installers/requirements/RequirementInstaller.d.ts +4 -1
  19. package/dist/core/loaders/InstallOperationManager.d.ts +115 -0
  20. package/dist/core/loaders/InstallOperationManager.js +311 -0
  21. package/dist/core/loaders/SystemSettingsManager.d.ts +54 -0
  22. package/dist/core/loaders/SystemSettingsManager.js +257 -0
  23. package/dist/core/metadatas/constants.d.ts +7 -0
  24. package/dist/core/metadatas/constants.js +7 -0
  25. package/dist/core/metadatas/recordingConstants.d.ts +44 -0
  26. package/dist/core/metadatas/recordingConstants.js +45 -0
  27. package/dist/core/metadatas/types.d.ts +21 -0
  28. package/dist/core/onboard/FeedOnboardService.d.ts +7 -3
  29. package/dist/core/onboard/FeedOnboardService.js +52 -5
  30. package/dist/core/onboard/InstallOperationManager.d.ts +23 -0
  31. package/dist/core/onboard/InstallOperationManager.js +144 -0
  32. package/dist/core/onboard/OnboardStatusManager.js +2 -1
  33. package/dist/core/validators/StdioServerValidator.js +4 -3
  34. package/dist/services/InstallationService.d.ts +2 -37
  35. package/dist/services/InstallationService.js +45 -313
  36. package/dist/services/MCPManager.d.ts +1 -1
  37. package/dist/services/MCPManager.js +53 -47
  38. package/dist/services/RequirementService.d.ts +85 -12
  39. package/dist/services/RequirementService.js +488 -49
  40. package/dist/services/ServerService.d.ts +0 -6
  41. package/dist/services/ServerService.js +0 -74
  42. package/dist/services/TelemetryService.d.ts +15 -0
  43. package/dist/services/TelemetryService.js +54 -0
  44. package/dist/utils/adoUtils.js +6 -3
  45. package/dist/utils/githubAuth.js +65 -0
  46. package/dist/utils/logger.d.ts +16 -0
  47. package/dist/utils/logger.js +78 -1
  48. package/dist/utils/macroExpressionUtils.js +3 -25
  49. package/dist/utils/osUtils.d.ts +22 -1
  50. package/dist/utils/osUtils.js +92 -1
  51. package/dist/utils/versionUtils.d.ts +20 -0
  52. package/dist/utils/versionUtils.js +76 -0
  53. package/dist/web/public/css/modal.css +292 -1
  54. package/dist/web/public/css/serverCategoryList.css +120 -0
  55. package/dist/web/public/css/serverDetails.css +14 -1
  56. package/dist/web/public/index.html +126 -21
  57. package/dist/web/public/js/flights/flights.js +1 -1
  58. package/dist/web/public/js/modal/index.js +8 -14
  59. package/dist/web/public/js/modal/installModal.js +3 -4
  60. package/dist/web/public/js/modal/installation.js +122 -137
  61. package/dist/web/public/js/modal/loadingModal.js +155 -25
  62. package/dist/web/public/js/modal/messageQueue.js +45 -101
  63. package/dist/web/public/js/modal/modalSetup.js +125 -43
  64. package/dist/web/public/js/modal/modalUtils.js +0 -12
  65. package/dist/web/public/js/modal.js +23 -10
  66. package/dist/web/public/js/onboard/formProcessor.js +18 -11
  67. package/dist/web/public/js/onboard/publishHandler.js +35 -3
  68. package/dist/web/public/js/onboard/templates.js +5 -1
  69. package/dist/web/public/js/onboard/uiHandlers.js +266 -39
  70. package/dist/web/public/js/onboard/validationHandlers.js +71 -39
  71. package/dist/web/public/js/serverCategoryDetails.js +60 -11
  72. package/dist/web/public/js/serverCategoryList.js +93 -9
  73. package/dist/web/public/js/settings.js +314 -0
  74. package/dist/web/public/onboard.html +2 -2
  75. package/dist/web/public/settings.html +135 -0
  76. package/dist/web/public/styles.css +32 -0
  77. package/dist/web/server.js +93 -1
  78. package/{src/web/public/js/onboard → docs}/ONBOARDING_PAGE_DESIGN.md +15 -125
  79. package/docs/Telemetry.md +136 -0
  80. package/memory-bank/activeContext.md +26 -0
  81. package/memory-bank/decisionLog.md +91 -0
  82. package/memory-bank/productContext.md +41 -0
  83. package/memory-bank/progress.md +35 -0
  84. package/memory-bank/systemPatterns.md +10 -0
  85. package/package.json +2 -1
  86. package/src/cli/index.ts +1 -48
  87. package/src/core/installers/clients/BaseClientInstaller.ts +64 -50
  88. package/src/core/installers/clients/ClientInstaller.ts +130 -130
  89. package/src/core/installers/requirements/BaseInstaller.ts +9 -1
  90. package/src/core/installers/requirements/CommandInstaller.ts +47 -13
  91. package/src/core/installers/requirements/GeneralInstaller.ts +48 -10
  92. package/src/core/installers/requirements/InstallerFactory.ts +4 -3
  93. package/src/core/installers/requirements/NpmInstaller.ts +90 -68
  94. package/src/core/installers/requirements/PipInstaller.ts +81 -55
  95. package/src/core/installers/requirements/RequirementInstaller.ts +4 -3
  96. package/src/core/loaders/InstallOperationManager.ts +367 -0
  97. package/src/core/loaders/SystemSettingsManager.ts +278 -0
  98. package/src/core/metadatas/constants.ts +9 -0
  99. package/src/core/metadatas/recordingConstants.ts +62 -0
  100. package/src/core/metadatas/types.ts +23 -0
  101. package/src/core/onboard/FeedOnboardService.ts +59 -5
  102. package/src/core/onboard/OnboardStatusManager.ts +2 -1
  103. package/src/core/validators/StdioServerValidator.ts +4 -3
  104. package/src/services/InstallationService.ts +54 -399
  105. package/src/services/MCPManager.ts +61 -64
  106. package/src/services/RequirementService.ts +564 -67
  107. package/src/services/ServerService.ts +0 -90
  108. package/src/services/TelemetryService.ts +59 -0
  109. package/src/utils/adoUtils.ts +6 -4
  110. package/src/utils/githubAuth.ts +84 -1
  111. package/src/utils/logger.ts +83 -1
  112. package/src/utils/macroExpressionUtils.ts +4 -21
  113. package/src/utils/osUtils.ts +92 -1
  114. package/src/utils/versionUtils.ts +98 -13
  115. package/src/web/public/css/modal.css +292 -1
  116. package/src/web/public/css/serverCategoryList.css +120 -0
  117. package/src/web/public/css/serverDetails.css +14 -1
  118. package/src/web/public/index.html +126 -21
  119. package/src/web/public/js/flights/flights.js +1 -1
  120. package/src/web/public/js/modal/index.js +8 -14
  121. package/src/web/public/js/modal/installModal.js +3 -4
  122. package/src/web/public/js/modal/installation.js +122 -137
  123. package/src/web/public/js/modal/loadingModal.js +155 -25
  124. package/src/web/public/js/modal/modalSetup.js +125 -43
  125. package/src/web/public/js/modal/modalUtils.js +0 -12
  126. package/src/web/public/js/modal.js +23 -10
  127. package/src/web/public/js/onboard/formProcessor.js +18 -11
  128. package/src/web/public/js/onboard/publishHandler.js +35 -3
  129. package/src/web/public/js/onboard/templates.js +5 -1
  130. package/src/web/public/js/onboard/uiHandlers.js +266 -39
  131. package/src/web/public/js/onboard/validationHandlers.js +71 -39
  132. package/src/web/public/js/serverCategoryDetails.js +60 -11
  133. package/src/web/public/js/serverCategoryList.js +93 -9
  134. package/src/web/public/js/settings.js +314 -0
  135. package/src/web/public/onboard.html +2 -2
  136. package/src/web/public/settings.html +135 -0
  137. package/src/web/public/styles.css +32 -0
  138. package/src/web/server.ts +96 -1
  139. package/dist/cli/commands/start.d.ts +0 -2
  140. package/dist/cli/commands/start.js +0 -32
  141. package/dist/cli/commands/sync.d.ts +0 -2
  142. package/dist/cli/commands/sync.js +0 -17
  143. package/dist/core/ConfigurationLoader.d.ts +0 -32
  144. package/dist/core/ConfigurationLoader.js +0 -236
  145. package/dist/core/ConfigurationProvider.d.ts +0 -35
  146. package/dist/core/ConfigurationProvider.js +0 -375
  147. package/dist/core/InstallationService.d.ts +0 -50
  148. package/dist/core/InstallationService.js +0 -350
  149. package/dist/core/MCPManager.d.ts +0 -28
  150. package/dist/core/MCPManager.js +0 -188
  151. package/dist/core/RequirementService.d.ts +0 -40
  152. package/dist/core/RequirementService.js +0 -110
  153. package/dist/core/ServerSchemaLoader.d.ts +0 -11
  154. package/dist/core/ServerSchemaLoader.js +0 -43
  155. package/dist/core/ServerSchemaProvider.d.ts +0 -17
  156. package/dist/core/ServerSchemaProvider.js +0 -120
  157. package/dist/core/constants.d.ts +0 -47
  158. package/dist/core/constants.js +0 -94
  159. package/dist/core/installers/BaseInstaller.d.ts +0 -74
  160. package/dist/core/installers/BaseInstaller.js +0 -253
  161. package/dist/core/installers/ClientInstaller.d.ts +0 -23
  162. package/dist/core/installers/ClientInstaller.js +0 -564
  163. package/dist/core/installers/CommandInstaller.d.ts +0 -37
  164. package/dist/core/installers/CommandInstaller.js +0 -173
  165. package/dist/core/installers/GeneralInstaller.d.ts +0 -33
  166. package/dist/core/installers/GeneralInstaller.js +0 -85
  167. package/dist/core/installers/InstallerFactory.d.ts +0 -54
  168. package/dist/core/installers/InstallerFactory.js +0 -97
  169. package/dist/core/installers/NpmInstaller.d.ts +0 -26
  170. package/dist/core/installers/NpmInstaller.js +0 -127
  171. package/dist/core/installers/PipInstaller.d.ts +0 -28
  172. package/dist/core/installers/PipInstaller.js +0 -127
  173. package/dist/core/installers/RequirementInstaller.d.ts +0 -33
  174. package/dist/core/installers/RequirementInstaller.js +0 -3
  175. package/dist/core/types.d.ts +0 -166
  176. package/dist/core/types.js +0 -16
  177. package/dist/services/InstallRequestValidator.d.ts +0 -21
  178. package/dist/services/InstallRequestValidator.js +0 -99
  179. package/dist/web/public/js/modal/installHandler.js +0 -227
  180. package/dist/web/public/js/modal/loadingUI.js +0 -74
  181. package/dist/web/public/js/modal/modalUI.js +0 -214
  182. package/dist/web/public/js/modal/version.js +0 -20
  183. package/src/web/public/js/modal/messageQueue.js +0 -112
@@ -0,0 +1,144 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { SETTINGS_DIR } from '../metadatas/constants.js';
4
+ import { Logger } from '../../utils/logger.js';
5
+ const INSTALL_STATUS_DIR = path.join(SETTINGS_DIR, 'install');
6
+ const INSTALL_OPERATION_STATUS_FILE = path.join(INSTALL_STATUS_DIR, 'InstallOperationStatus.json');
7
+ export class InstallOperationManager {
8
+ static instance;
9
+ installOperationStatus = {};
10
+ statusLock = Promise.resolve();
11
+ constructor() {
12
+ this.loadStatuses().catch(error => Logger.error('Failed to initialize InstallOperationManager:', error));
13
+ }
14
+ static getInstance() {
15
+ if (!InstallOperationManager.instance) {
16
+ InstallOperationManager.instance = new InstallOperationManager();
17
+ }
18
+ return InstallOperationManager.instance;
19
+ }
20
+ async withLock(operation) {
21
+ const current = this.statusLock;
22
+ let resolve;
23
+ this.statusLock = new Promise(r => resolve = r);
24
+ try {
25
+ await current;
26
+ return await operation();
27
+ }
28
+ finally {
29
+ resolve();
30
+ }
31
+ }
32
+ async loadStatuses() {
33
+ await this.withLock(async () => {
34
+ try {
35
+ await fs.mkdir(INSTALL_STATUS_DIR, { recursive: true });
36
+ const data = await fs.readFile(INSTALL_OPERATION_STATUS_FILE, 'utf-8');
37
+ this.installOperationStatus = JSON.parse(data);
38
+ }
39
+ catch (error) {
40
+ if (error.code === 'ENOENT') {
41
+ this.installOperationStatus = {};
42
+ await this.saveStatuses(); // Create the file if it doesn't exist
43
+ }
44
+ else {
45
+ Logger.error('Failed to load install operation statuses:', error);
46
+ this.installOperationStatus = {}; // Initialize with empty statuses in case of other errors
47
+ }
48
+ }
49
+ });
50
+ }
51
+ async saveStatuses() {
52
+ await fs.mkdir(INSTALL_STATUS_DIR, { recursive: true });
53
+ await fs.writeFile(INSTALL_OPERATION_STATUS_FILE, JSON.stringify(this.installOperationStatus, null, 2));
54
+ }
55
+ createOperationKey(categoryName, serverName) {
56
+ return `${categoryName}-${serverName}`;
57
+ }
58
+ async recordStep(categoryName, serverName, stepName, isSucceeded, message) {
59
+ return await this.withLock(async () => {
60
+ const operationKey = this.createOperationKey(categoryName, serverName);
61
+ let operationDetails = this.installOperationStatus[operationKey];
62
+ const newStep = {
63
+ name: stepName,
64
+ isSucceeded,
65
+ message,
66
+ timestamp: new Date().toISOString(),
67
+ };
68
+ if (!operationDetails) {
69
+ operationDetails = {
70
+ currentStep: stepName,
71
+ steps: [newStep],
72
+ lastUpdated: new Date().toISOString(),
73
+ error: !isSucceeded ? message : undefined,
74
+ overallStatus: isSucceeded ? 'in-progress' : 'failed',
75
+ };
76
+ }
77
+ else {
78
+ operationDetails.steps.push(newStep);
79
+ operationDetails.currentStep = stepName;
80
+ operationDetails.lastUpdated = new Date().toISOString();
81
+ if (!isSucceeded) {
82
+ operationDetails.overallStatus = 'failed';
83
+ if (!operationDetails.error) { // Store the first error
84
+ operationDetails.error = message;
85
+ }
86
+ }
87
+ else {
88
+ // If this step succeeded, check if all previous steps also succeeded.
89
+ // If a previous step failed, the overall status remains 'failed'.
90
+ // If all steps are successful so far, it's 'in-progress' unless it's a known completion step.
91
+ if (operationDetails.overallStatus !== 'failed') {
92
+ if (stepName.toLowerCase().includes('completed') || stepName.toLowerCase().includes('succeeded')) {
93
+ // Check if this is a "final" success step
94
+ const isFinalSuccess = operationDetails.steps.every(s => s.isSucceeded);
95
+ operationDetails.overallStatus = isFinalSuccess ? 'completed' : 'in-progress';
96
+ if (isFinalSuccess)
97
+ operationDetails.error = undefined; // Clear error on final success
98
+ }
99
+ else {
100
+ operationDetails.overallStatus = 'in-progress';
101
+ }
102
+ }
103
+ }
104
+ }
105
+ // Special handling for the "InstallCompleted" step or similar final step names
106
+ if (stepName === 'InstallCompleted') {
107
+ operationDetails.overallStatus = isSucceeded ? 'completed' : 'failed';
108
+ if (isSucceeded)
109
+ operationDetails.error = undefined;
110
+ }
111
+ this.installOperationStatus[operationKey] = operationDetails;
112
+ await this.saveStatuses();
113
+ return operationDetails;
114
+ });
115
+ }
116
+ /**
117
+ * Resets (deletes) the operation status for a given category and server.
118
+ * This is useful to call before starting a new installation attempt.
119
+ * @param categoryName The name of the category.
120
+ * @param serverName The name of the server.
121
+ */
122
+ async resetOperation(categoryName, serverName) {
123
+ await this.withLock(async () => {
124
+ const operationKey = this.createOperationKey(categoryName, serverName);
125
+ if (this.installOperationStatus[operationKey]) {
126
+ delete this.installOperationStatus[operationKey];
127
+ Logger.info(`Reset installation operation status for ${operationKey}`);
128
+ await this.saveStatuses();
129
+ }
130
+ });
131
+ }
132
+ async getDetails(categoryName, serverName) {
133
+ await this.loadStatuses(); // Ensure latest statuses are loaded
134
+ const operationKey = this.createOperationKey(categoryName, serverName);
135
+ return this.installOperationStatus[operationKey];
136
+ }
137
+ async getAllDetails() {
138
+ await this.loadStatuses();
139
+ return this.installOperationStatus;
140
+ }
141
+ }
142
+ // Export singleton instance
143
+ export const installOperationManager = InstallOperationManager.getInstance();
144
+ //# sourceMappingURL=InstallOperationManager.js.map
@@ -3,6 +3,7 @@ import path from 'path';
3
3
  import { SETTINGS_DIR } from '../metadatas/constants.js';
4
4
  import { OnboardingProcessStatus } from './OnboardStatus.js';
5
5
  import { Logger } from '../../utils/logger.js';
6
+ import * as RecordingConstants from '../metadatas/recordingConstants.js';
6
7
  const ONBOARD_STATUS_DIR = path.join(SETTINGS_DIR, 'onboard');
7
8
  const CATEGORY_OPERATIONS_STATUS_FILE = path.join(ONBOARD_STATUS_DIR, 'OnboardStatus.json');
8
9
  const FEED_CONFIG_DIR = path.join(ONBOARD_STATUS_DIR, 'feed_configs'); // Staging for feed configs during operation
@@ -267,7 +268,7 @@ export class OnboardStatusManager {
267
268
  feedName: categoryName,
268
269
  serverName,
269
270
  status: OnboardingProcessStatus.PENDING,
270
- steps: [{ stepName: 'Initiated', timestamp: new Date().toISOString() }],
271
+ steps: [{ stepName: RecordingConstants.STEP_INITIATED, timestamp: new Date().toISOString() }],
271
272
  lastUpdated: new Date().toISOString(),
272
273
  operationType,
273
274
  errorMessage: undefined,
@@ -6,6 +6,7 @@ import { MACRO_EXPRESSIONS, resolveNpmModulePath } from "../../utils/macroExpres
6
6
  import { getSystemPythonPackageDirectory } from "../../utils/osUtils.js";
7
7
  import { SETTINGS_DIR } from "../metadatas/constants.js";
8
8
  import path from "path";
9
+ import { InstallOperationManager } from "../loaders/InstallOperationManager.js";
9
10
  const execPromise = util.promisify(exec);
10
11
  /**
11
12
  * Validates MCP server configurations for stdio mode
@@ -45,7 +46,7 @@ export class StdioServerValidator {
45
46
  * @param requirement The requirement config to validate and install
46
47
  * @returns true if requirement is successfully installed/validated
47
48
  */
48
- async validateRequirement(requirement) {
49
+ async validateRequirement(requirement, recorder) {
49
50
  try {
50
51
  Logger.debug(`Validating/installing requirement: ${requirement.name}`);
51
52
  const installer = this.installerFactory.getInstaller(requirement);
@@ -55,7 +56,7 @@ export class StdioServerValidator {
55
56
  throw new Error(msg);
56
57
  }
57
58
  const targetDir = this._getRequirementFolderPath(requirement);
58
- const status = await installer.install(requirement, { settings: { folderName: targetDir } });
59
+ const status = await installer.install(requirement, recorder, { settings: { folderName: targetDir } });
59
60
  if (!status.installed) {
60
61
  const msg = `Failed to install requirement ${requirement.name}: ${status.error || 'Unknown error'}`;
61
62
  Logger.error(msg);
@@ -257,7 +258,7 @@ export class StdioServerValidator {
257
258
  version: req.version,
258
259
  type: 'npm' // Default to npm if not specified
259
260
  };
260
- const isValid = await this.validateRequirement(reqConfig);
261
+ const isValid = await this.validateRequirement(reqConfig, InstallOperationManager.getInstance(config.name, server.name));
261
262
  if (!isValid) {
262
263
  throw new Error(`Dependency validation failed for: ${req.name}`);
263
264
  }
@@ -3,48 +3,13 @@ import { ServerInstallOptions, ServerOperationResult } from '../core/metadatas/t
3
3
  * Handles the actual installation process for an MCP server.
4
4
  */
5
5
  export declare class InstallationService {
6
- private activeInstallations;
7
- private installerFactory;
8
6
  constructor();
9
- private generateOperationId;
10
7
  /**
11
- * Installs a server based on the provided options and feed configuration.
8
+ * Installs a server based on the provided options.
9
+ * @param categoryName The category name of the server.
12
10
  * @param serverName The name of the server to install.
13
11
  * @param options The installation options.
14
12
  * @returns A result object indicating success or failure.
15
13
  */
16
14
  install(categoryName: string, serverName: string, options: ServerInstallOptions): Promise<ServerOperationResult>;
17
- /**
18
- * Process requirement updates specified in serverInstallOptions
19
- * All updates are processed in parallel for maximum efficiency
20
- * @param categoryName The category name
21
- * @param serverName The server name
22
- * @param requirements The requirements to update
23
- */
24
- private processRequirementUpdates;
25
- /**
26
- * Checks and installs requirements for a server if needed
27
- * @param categoryName The category name
28
- * @param serverName The server name
29
- * @param options The installation options
30
- * @returns A failure result if requirements check fails, null if requirements are satisfied
31
- */
32
- private checkAndInstallRequirements;
33
- /**
34
- * Installs requirements in background without blocking the main thread
35
- * Requirements with the same order are installed in parallel
36
- */
37
- private installRequirementsInBackground;
38
- /**
39
- * Helper to update requirement status for failure case
40
- */
41
- private updateRequirementFailureStatus;
42
- /**
43
- * Helper to update requirement status for in-progress case
44
- */
45
- private updateRequirementProgressStatus;
46
- /**
47
- * Helper to update requirement status for completion case
48
- */
49
- private updateRequirementCompletionStatus;
50
15
  }
@@ -1,350 +1,82 @@
1
- import path from 'path';
2
- import { fileURLToPath } from 'url';
3
- import { exec } from 'child_process';
4
- import util from 'util';
5
- import { createInstallerFactory } from '../core/installers/index.js';
6
- import { SUPPORTED_CLIENTS } from '../core/metadatas/constants.js';
7
1
  import { ClientInstaller } from '../core/installers/clients/ClientInstaller.js';
8
2
  import { ConfigurationProvider } from '../core/loaders/ConfigurationProvider.js';
9
3
  import { Logger } from '../utils/logger.js';
10
- const execPromise = util.promisify(exec);
11
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
4
+ import { requirementService } from './RequirementService.js';
5
+ import { InstallOperationManager } from '../core/loaders/InstallOperationManager.js';
6
+ import * as RecordingConstants from '../core/metadatas/recordingConstants.js';
12
7
  /**
13
8
  * Handles the actual installation process for an MCP server.
14
9
  */
15
10
  export class InstallationService {
16
- activeInstallations = new Map();
17
- installerFactory;
18
11
  constructor() {
19
- this.installerFactory = createInstallerFactory();
20
- }
21
- generateOperationId() {
22
- return `install-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
12
+ // Constructor is now empty after removing installerFactory initialization
23
13
  }
24
14
  /**
25
- * Installs a server based on the provided options and feed configuration.
15
+ * Installs a server based on the provided options.
16
+ * @param categoryName The category name of the server.
26
17
  * @param serverName The name of the server to install.
27
18
  * @param options The installation options.
28
19
  * @returns A result object indicating success or failure.
29
20
  */
30
21
  async install(categoryName, serverName, options) {
22
+ // Reset any previous operation status for this server before starting a new one.
23
+ const recoder = await InstallOperationManager.getInstance(categoryName, serverName).resetOperation();
31
24
  const configProvider = ConfigurationProvider.getInstance();
32
- const clients = options.targetClients || Object.keys(SUPPORTED_CLIENTS);
25
+ const clients = options.targetClients || [];
33
26
  // Process updates for requirements if specified in options
34
- // Fire off requirement updates in the background without awaiting completion
35
27
  if (options.requirements && options.requirements.length > 0) {
36
- // Start the process but don't await it - it will run in the background
37
- this.processRequirementUpdates(categoryName, serverName, options)
38
- .catch(error => {
39
- console.error(`Error in background requirement updates: ${error instanceof Error ? error.message : String(error)}`);
28
+ recoder.recordingAsync(() => requirementService.processRequirementUpdates(categoryName, serverName, options), {
29
+ stepName: RecordingConstants.STEP_PROCESS_REQUIREMENT_UPDATES_SERVICE,
30
+ onError: (error) => {
31
+ const errorMsg = `Error in background requirement updates: ${error instanceof Error ? error.message : String(error)}`;
32
+ Logger.error(errorMsg);
33
+ return errorMsg;
34
+ },
35
+ onComplete: () => {
36
+ if (clients.length === 0)
37
+ recoder.markOverallStatus('completed', 'Requirement updates completed.');
38
+ }
40
39
  });
41
40
  }
42
- // Check if server is already ready
43
- const isReady = await configProvider.isServerReady(categoryName, serverName, clients);
41
+ if (!clients || clients.length === 0) {
42
+ const message = 'No clients specified for installation.';
43
+ return { success: true, message };
44
+ }
45
+ // Check if the server is already installed and ready
46
+ const readyMessage = 'Server and clients are already installed and ready';
47
+ const isReady = await recoder.recording(() => configProvider.isServerReady(categoryName, serverName, clients), {
48
+ stepName: RecordingConstants.STEP_CHECK_SERVER_READINESS,
49
+ inProgressMessage: 'Checking if server is already ready.',
50
+ endMessage: (ready) => ready ? 'Server and clients are already installed and ready' : 'Server is not ready. Proceeding with installation.',
51
+ });
44
52
  if (isReady) {
45
53
  return {
46
- success: true,
47
- message: 'Server and clients are already installed and ready',
54
+ success: true, message: readyMessage,
48
55
  status: [{
49
56
  status: 'completed',
50
57
  type: 'install',
51
58
  target: 'server',
52
- message: 'Server and clients are already installed and ready'
59
+ message: readyMessage,
53
60
  }]
54
61
  };
55
62
  }
56
63
  // Create new ClientInstaller instance for handling installation
57
64
  const clientInstaller = new ClientInstaller(categoryName, serverName, clients);
58
- const requirementsResult = await this.checkAndInstallRequirements(categoryName, serverName, options);
59
- if (requirementsResult) {
65
+ // Check and install requirements using RequirementService
66
+ const requirementsResult = await requirementService.checkAndInstallRequirements(categoryName, serverName, options);
67
+ // trigger a backend requirement check
68
+ await requirementService.checkServerRequirementForUpdateAsync(categoryName, serverName)
69
+ .then(() => {
70
+ Logger.info(`Requirement check for ${categoryName}:${serverName} completed successfully.`);
71
+ })
72
+ .catch((error) => {
73
+ Logger.error(`Requirement check for ${categoryName}:${serverName} failed: ${error instanceof Error ? error.message : String(error)}`);
74
+ });
75
+ if (requirementsResult && !requirementsResult.success) {
76
+ await recoder.recordStep('RequirementInstallationCheck', 'failed', requirementsResult.error?.message || requirementsResult.message || 'Requirement installation failed.');
60
77
  return requirementsResult;
61
78
  }
62
- // Process client installation regardless of requirements state
63
- // Each client installer will check requirements before actual installation
64
79
  return await clientInstaller.install(options);
65
80
  }
66
- /**
67
- * Process requirement updates specified in serverInstallOptions
68
- * All updates are processed in parallel for maximum efficiency
69
- * @param categoryName The category name
70
- * @param serverName The server name
71
- * @param requirements The requirements to update
72
- */
73
- async processRequirementUpdates(categoryName, serverName, options) {
74
- // Use UpdateCheckTracker to prevent concurrent updates
75
- const updateCheckTracker = await import('../utils/UpdateCheckTracker.js').then(m => m.updateCheckTracker);
76
- const operationKey = `requirement-updates-${categoryName}-${serverName}`;
77
- // Check if there's already an update operation in progress for this server
78
- const canProceed = await updateCheckTracker.startOperation(operationKey);
79
- if (!canProceed) {
80
- console.log(`Requirement updates for ${categoryName}/${serverName} already in progress, skipping`);
81
- return;
82
- }
83
- try {
84
- const configProvider = ConfigurationProvider.getInstance();
85
- const feedConfig = await configProvider.getFeedConfiguration(categoryName);
86
- if (!feedConfig) {
87
- console.error(`Feed configuration not found for category: ${categoryName}`);
88
- return;
89
- }
90
- // Import the RequirementService
91
- const { requirementService } = await import('./RequirementService.js');
92
- // Create an array of promises to update all requirements in parallel
93
- const updatePromises = options.requirements?.map(async (reqToUpdate) => {
94
- try {
95
- // Find the full requirement config
96
- const reqConfig = feedConfig.requirements?.find((r) => r.name === reqToUpdate.name);
97
- if (!reqConfig) {
98
- console.error(`Requirement configuration not found for: ${reqToUpdate.name}`);
99
- return;
100
- }
101
- // Get current status
102
- const currentStatus = await configProvider.getRequirementStatus(categoryName, reqToUpdate.name);
103
- if (!currentStatus) {
104
- console.error(`No current status found for requirement: ${reqToUpdate.name}`);
105
- return;
106
- }
107
- // Update requirement status to indicate update in progress
108
- await configProvider.updateRequirementStatus(categoryName, reqToUpdate.name, {
109
- ...currentStatus,
110
- name: reqToUpdate.name,
111
- type: currentStatus.type || 'unknown',
112
- installed: currentStatus.installed || false,
113
- inProgress: true,
114
- operationStatus: {
115
- status: 'in-progress',
116
- type: 'update',
117
- target: 'requirement',
118
- message: `Updating ${reqToUpdate.name} from ${currentStatus.version || 'unknown'} to ${reqToUpdate.version}`
119
- }
120
- });
121
- // For pip requirements, check if we have a stored pythonEnv
122
- if (reqConfig.type === 'pip' && currentStatus.pythonEnv && !options?.settings?.pythonEnv) {
123
- options = {
124
- ...options,
125
- settings: { ...options?.settings, pythonEnv: currentStatus.pythonEnv }
126
- };
127
- }
128
- // Update the requirement with options for pip environment
129
- const updatedStatus = await requirementService.updateRequirement(reqConfig, reqToUpdate.version, options);
130
- // Update requirement status
131
- await configProvider.updateRequirementStatus(categoryName, reqToUpdate.name, {
132
- ...updatedStatus,
133
- name: reqToUpdate.name,
134
- type: updatedStatus.type || currentStatus.type || 'unknown',
135
- installed: updatedStatus.installed,
136
- inProgress: false,
137
- operationStatus: {
138
- status: updatedStatus.installed ? 'completed' : 'failed',
139
- type: 'update',
140
- target: 'requirement',
141
- message: updatedStatus.installed
142
- ? `Successfully updated ${reqToUpdate.name} to version ${reqToUpdate.version}`
143
- : `Failed to update ${reqToUpdate.name} to version ${reqToUpdate.version}`
144
- },
145
- availableUpdate: updatedStatus.installed ? undefined : currentStatus.availableUpdate
146
- });
147
- console.log(`Requirement ${reqToUpdate.name} updated to version ${reqToUpdate.version}`);
148
- }
149
- catch (error) {
150
- console.error(`Error updating requirement ${reqToUpdate.name}:`, error);
151
- // Update status to indicate failure
152
- await configProvider.updateRequirementStatus(categoryName, reqToUpdate.name, {
153
- name: reqToUpdate.name,
154
- type: 'unknown',
155
- installed: false,
156
- inProgress: false,
157
- error: error instanceof Error ? error.message : String(error),
158
- operationStatus: {
159
- status: 'failed',
160
- type: 'update',
161
- target: 'requirement',
162
- message: `Error updating requirement: ${error instanceof Error ? error.message : String(error)}`
163
- }
164
- });
165
- }
166
- });
167
- // Wait for all updates to complete in parallel if there are any
168
- if (updatePromises) {
169
- await Promise.all(updatePromises);
170
- }
171
- }
172
- finally {
173
- // Always release the lock when done, even if there was an error
174
- await updateCheckTracker.endOperation(operationKey);
175
- }
176
- }
177
- /**
178
- * Checks and installs requirements for a server if needed
179
- * @param categoryName The category name
180
- * @param serverName The server name
181
- * @param options The installation options
182
- * @returns A failure result if requirements check fails, null if requirements are satisfied
183
- */
184
- async checkAndInstallRequirements(categoryName, serverName, options) {
185
- const configProvider = ConfigurationProvider.getInstance();
186
- // Get feed configuration to get requirements
187
- const feedConfig = await configProvider.getFeedConfiguration(categoryName);
188
- if (!feedConfig) {
189
- return {
190
- success: false,
191
- message: 'Feed configuration not found',
192
- status: [{
193
- status: 'failed',
194
- type: 'install',
195
- target: 'server',
196
- message: 'Feed configuration not found'
197
- }]
198
- };
199
- }
200
- // Find server config and verify requirements
201
- const serverConfig = feedConfig.mcpServers.find((s) => s.name === serverName);
202
- if (!serverConfig?.dependencies?.requirements) {
203
- Logger.debug(`No requirements for ${serverName}`);
204
- return null;
205
- }
206
- // Check all requirements installation status
207
- const requirementStatuses = await Promise.all(serverConfig.dependencies.requirements.map(async (req) => {
208
- const reqConfig = feedConfig.requirements?.find((r) => r.name === req.name) || {
209
- name: req.name,
210
- version: req.version,
211
- type: 'npm'
212
- };
213
- return await this.installerFactory.checkInstallation(reqConfig, options);
214
- }));
215
- // If all requirements are installed and ready, no need to proceed with installation
216
- if (requirementStatuses.every(status => status.installed)) {
217
- // Check if requirements are ready via ConfigurationProvider
218
- const requirementsReady = await configProvider.isRequirementsReady(categoryName, serverName);
219
- // Update requirement status if not ready
220
- if (!requirementsReady) {
221
- for (const status of requirementStatuses) {
222
- await configProvider.updateRequirementStatus(categoryName, status.name, status);
223
- }
224
- }
225
- return null;
226
- }
227
- // Sort requirements by order for installation
228
- const sortedRequirements = [...serverConfig.dependencies.requirements].sort((a, b) => {
229
- const orderA = a.order ?? Infinity;
230
- const orderB = b.order ?? Infinity;
231
- return orderA - orderB;
232
- });
233
- // Start requirements installation in background
234
- this.installRequirementsInBackground(categoryName, sortedRequirements, options)
235
- .catch(error => {
236
- Logger.error(`Error in background requirement installations: ${error instanceof Error ? error.message : String(error)}`);
237
- });
238
- // Return immediately while installation continues in background
239
- return null;
240
- }
241
- /**
242
- * Installs requirements in background without blocking the main thread
243
- * Requirements with the same order are installed in parallel
244
- */
245
- async installRequirementsInBackground(categoryName, sortedRequirements, options) {
246
- const configProvider = ConfigurationProvider.getInstance();
247
- const requirementGroups = sortedRequirements.reduce((groups, req) => {
248
- const order = req.order ?? Infinity;
249
- if (!groups[order]) {
250
- groups[order] = [];
251
- }
252
- groups[order].push(req);
253
- return groups;
254
- }, {});
255
- // Process each group in sequence, but requirements within group in parallel
256
- const orderKeys = Object.keys(requirementGroups).map(Number).sort((a, b) => a - b);
257
- for (const order of orderKeys) {
258
- const group = requirementGroups[order];
259
- await Promise.all(group.map(async (requirement) => {
260
- try {
261
- const feeds = await configProvider.getFeedConfiguration(categoryName);
262
- const requirementConfig = feeds?.requirements?.find((r) => r.name === requirement.name) || {
263
- name: requirement.name,
264
- version: requirement.version,
265
- type: 'npm'
266
- };
267
- // For pip requirements, check if we need to use stored pythonEnv
268
- const currentStatus = await configProvider.getRequirementStatus(categoryName, requirement.name);
269
- if (requirementConfig.type === 'pip' && currentStatus?.pythonEnv && !options?.settings?.pythonEnv) {
270
- options = {
271
- ...options,
272
- settings: { ...options?.settings, pythonEnv: currentStatus.pythonEnv }
273
- };
274
- }
275
- const installer = this.installerFactory.getInstaller(requirementConfig);
276
- if (!installer) {
277
- await this.updateRequirementFailureStatus(categoryName, requirement.name, requirementConfig.type, `No installer found for requirement type: ${requirementConfig.type}`);
278
- return;
279
- }
280
- const operationId = this.generateOperationId();
281
- await this.updateRequirementProgressStatus(categoryName, requirement.name, requirementConfig.type, operationId);
282
- const installStatus = await installer.install(requirementConfig, options);
283
- await this.updateRequirementCompletionStatus(categoryName, requirement.name, installStatus, operationId);
284
- }
285
- catch (error) {
286
- await this.updateRequirementFailureStatus(categoryName, requirement.name, 'unknown', error instanceof Error ? error.message : String(error));
287
- }
288
- }));
289
- }
290
- }
291
- /**
292
- * Helper to update requirement status for failure case
293
- */
294
- async updateRequirementFailureStatus(categoryName, requirementName, requirementType, errorMessage) {
295
- const configProvider = ConfigurationProvider.getInstance();
296
- await configProvider.updateRequirementStatus(categoryName, requirementName, {
297
- name: requirementName,
298
- type: requirementType,
299
- installed: false,
300
- error: errorMessage,
301
- operationStatus: {
302
- status: 'failed',
303
- type: 'install',
304
- target: 'requirement',
305
- message: `Error installing requirement: ${errorMessage}`,
306
- operationId: this.generateOperationId()
307
- }
308
- });
309
- }
310
- /**
311
- * Helper to update requirement status for in-progress case
312
- */
313
- async updateRequirementProgressStatus(categoryName, requirementName, requirementType, operationId) {
314
- const configProvider = ConfigurationProvider.getInstance();
315
- await configProvider.updateRequirementStatus(categoryName, requirementName, {
316
- name: requirementName,
317
- type: requirementType,
318
- installed: false,
319
- inProgress: true,
320
- operationStatus: {
321
- status: 'in-progress',
322
- type: 'install',
323
- target: 'requirement',
324
- message: `Installing requirement: ${requirementName}`,
325
- operationId
326
- }
327
- });
328
- }
329
- /**
330
- * Helper to update requirement status for completion case
331
- */
332
- async updateRequirementCompletionStatus(categoryName, requirementName, installStatus, operationId) {
333
- const configProvider = ConfigurationProvider.getInstance();
334
- await configProvider.updateRequirementStatus(categoryName, requirementName, {
335
- ...installStatus,
336
- operationStatus: {
337
- status: installStatus.installed ? 'completed' : 'failed',
338
- type: 'install',
339
- target: 'requirement',
340
- message: installStatus.installed
341
- ? `Requirement ${requirementName} installed successfully`
342
- : `Failed to install ${requirementName}`,
343
- operationId
344
- }
345
- });
346
- }
347
81
  }
348
- // Export a singleton instance (optional)
349
- // export const installationService = new InstallationService();
350
82
  //# sourceMappingURL=InstallationService.js.map
@@ -6,6 +6,7 @@ export declare class MCPManager extends EventEmitter {
6
6
  private configProvider;
7
7
  private feedOnboardService;
8
8
  private schemaProvider;
9
+ private requirementsService;
9
10
  constructor();
10
11
  syncFeeds(): Promise<void>;
11
12
  initialize(feedFile?: string, schemasDirectory?: string): Promise<void>;
@@ -14,7 +15,6 @@ export declare class MCPManager extends EventEmitter {
14
15
  getServerMcpConfig(categoryName: string, serverName: string): Promise<import("../core/metadatas/types.js").McpConfig | undefined>;
15
16
  installServer(categoryName: string, serverName: string, requestOptions?: ServerInstallOptions): Promise<ServerOperationResult>;
16
17
  uninstallServer(categoryName: string, serverName: string, options?: ServerUninstallOptions): Promise<ServerOperationResult>;
17
- updateRequirement(categoryName: string, serverName: string, requirementName: string, updateVersion: string): Promise<ServerOperationResult>;
18
18
  /**
19
19
  * Onboards a new feed configuration
20
20
  * @param config The feed configuration to onboard