imcp 0.1.1 → 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 (111) hide show
  1. package/dist/cli/index.js +1 -45
  2. package/dist/core/installers/clients/BaseClientInstaller.d.ts +1 -5
  3. package/dist/core/installers/clients/BaseClientInstaller.js +40 -38
  4. package/dist/core/installers/clients/ClientInstaller.d.ts +9 -9
  5. package/dist/core/installers/clients/ClientInstaller.js +105 -99
  6. package/dist/core/installers/requirements/BaseInstaller.d.ts +9 -1
  7. package/dist/core/installers/requirements/CommandInstaller.d.ts +9 -1
  8. package/dist/core/installers/requirements/CommandInstaller.js +46 -12
  9. package/dist/core/installers/requirements/GeneralInstaller.d.ts +11 -1
  10. package/dist/core/installers/requirements/GeneralInstaller.js +46 -10
  11. package/dist/core/installers/requirements/InstallerFactory.d.ts +3 -1
  12. package/dist/core/installers/requirements/InstallerFactory.js +3 -2
  13. package/dist/core/installers/requirements/NpmInstaller.d.ts +4 -2
  14. package/dist/core/installers/requirements/NpmInstaller.js +38 -22
  15. package/dist/core/installers/requirements/PipInstaller.d.ts +3 -1
  16. package/dist/core/installers/requirements/PipInstaller.js +58 -36
  17. package/dist/core/installers/requirements/RequirementInstaller.d.ts +4 -1
  18. package/dist/core/loaders/InstallOperationManager.d.ts +115 -0
  19. package/dist/core/loaders/InstallOperationManager.js +311 -0
  20. package/dist/core/loaders/SystemSettingsManager.d.ts +54 -0
  21. package/dist/core/loaders/SystemSettingsManager.js +257 -0
  22. package/dist/core/metadatas/recordingConstants.d.ts +44 -0
  23. package/dist/core/metadatas/recordingConstants.js +45 -0
  24. package/dist/core/metadatas/types.d.ts +21 -0
  25. package/dist/core/onboard/InstallOperationManager.d.ts +23 -0
  26. package/dist/core/onboard/InstallOperationManager.js +144 -0
  27. package/dist/core/onboard/OnboardStatusManager.js +2 -1
  28. package/dist/core/validators/StdioServerValidator.js +4 -3
  29. package/dist/services/InstallationService.d.ts +2 -37
  30. package/dist/services/InstallationService.js +45 -313
  31. package/dist/services/MCPManager.d.ts +1 -1
  32. package/dist/services/MCPManager.js +4 -58
  33. package/dist/services/RequirementService.d.ts +85 -12
  34. package/dist/services/RequirementService.js +488 -49
  35. package/dist/services/ServerService.d.ts +0 -6
  36. package/dist/services/ServerService.js +0 -74
  37. package/dist/utils/adoUtils.js +6 -3
  38. package/dist/utils/logger.js +1 -1
  39. package/dist/utils/macroExpressionUtils.js +3 -25
  40. package/dist/utils/osUtils.d.ts +22 -1
  41. package/dist/utils/osUtils.js +92 -1
  42. package/dist/utils/versionUtils.d.ts +20 -1
  43. package/dist/utils/versionUtils.js +51 -4
  44. package/dist/web/public/css/modal.css +292 -1
  45. package/dist/web/public/css/serverDetails.css +14 -1
  46. package/dist/web/public/index.html +122 -20
  47. package/dist/web/public/js/flights/flights.js +1 -0
  48. package/dist/web/public/js/modal/index.js +8 -14
  49. package/dist/web/public/js/modal/installModal.js +3 -4
  50. package/dist/web/public/js/modal/installation.js +122 -137
  51. package/dist/web/public/js/modal/loadingModal.js +155 -25
  52. package/dist/web/public/js/modal/messageQueue.js +45 -101
  53. package/dist/web/public/js/modal/modalSetup.js +125 -43
  54. package/dist/web/public/js/modal/modalUtils.js +0 -12
  55. package/dist/web/public/js/modal.js +23 -10
  56. package/dist/web/public/js/onboard/publishHandler.js +22 -20
  57. package/dist/web/public/js/serverCategoryDetails.js +60 -11
  58. package/dist/web/public/js/serverCategoryList.js +2 -2
  59. package/dist/web/public/js/settings.js +314 -0
  60. package/dist/web/public/settings.html +135 -0
  61. package/dist/web/public/styles.css +32 -0
  62. package/dist/web/server.js +82 -0
  63. package/memory-bank/activeContext.md +13 -1
  64. package/memory-bank/decisionLog.md +63 -0
  65. package/memory-bank/progress.md +30 -0
  66. package/memory-bank/systemPatterns.md +7 -0
  67. package/package.json +1 -1
  68. package/src/cli/index.ts +1 -48
  69. package/src/core/installers/clients/BaseClientInstaller.ts +64 -50
  70. package/src/core/installers/clients/ClientInstaller.ts +130 -130
  71. package/src/core/installers/requirements/BaseInstaller.ts +9 -1
  72. package/src/core/installers/requirements/CommandInstaller.ts +47 -13
  73. package/src/core/installers/requirements/GeneralInstaller.ts +48 -10
  74. package/src/core/installers/requirements/InstallerFactory.ts +4 -3
  75. package/src/core/installers/requirements/NpmInstaller.ts +90 -68
  76. package/src/core/installers/requirements/PipInstaller.ts +81 -55
  77. package/src/core/installers/requirements/RequirementInstaller.ts +4 -3
  78. package/src/core/loaders/InstallOperationManager.ts +367 -0
  79. package/src/core/loaders/SystemSettingsManager.ts +278 -0
  80. package/src/core/metadatas/recordingConstants.ts +62 -0
  81. package/src/core/metadatas/types.ts +23 -0
  82. package/src/core/onboard/OnboardStatusManager.ts +2 -1
  83. package/src/core/validators/StdioServerValidator.ts +4 -3
  84. package/src/services/InstallationService.ts +54 -399
  85. package/src/services/MCPManager.ts +4 -77
  86. package/src/services/RequirementService.ts +564 -67
  87. package/src/services/ServerService.ts +0 -90
  88. package/src/utils/adoUtils.ts +6 -4
  89. package/src/utils/logger.ts +1 -1
  90. package/src/utils/macroExpressionUtils.ts +4 -21
  91. package/src/utils/osUtils.ts +92 -1
  92. package/src/utils/versionUtils.ts +71 -19
  93. package/src/web/public/css/modal.css +292 -1
  94. package/src/web/public/css/serverDetails.css +14 -1
  95. package/src/web/public/index.html +122 -20
  96. package/src/web/public/js/flights/flights.js +1 -1
  97. package/src/web/public/js/modal/index.js +8 -14
  98. package/src/web/public/js/modal/installModal.js +3 -4
  99. package/src/web/public/js/modal/installation.js +122 -137
  100. package/src/web/public/js/modal/loadingModal.js +155 -25
  101. package/src/web/public/js/modal/modalSetup.js +125 -43
  102. package/src/web/public/js/modal/modalUtils.js +0 -12
  103. package/src/web/public/js/modal.js +23 -10
  104. package/src/web/public/js/onboard/publishHandler.js +22 -20
  105. package/src/web/public/js/serverCategoryDetails.js +60 -11
  106. package/src/web/public/js/serverCategoryList.js +2 -2
  107. package/src/web/public/js/settings.js +314 -0
  108. package/src/web/public/settings.html +135 -0
  109. package/src/web/public/styles.css +32 -0
  110. package/src/web/server.ts +85 -0
  111. package/src/web/public/js/modal/messageQueue.js +0 -112
@@ -1,13 +1,21 @@
1
1
  import { createInstallerFactory } from '../core/installers/index.js';
2
2
  import { exec } from 'child_process';
3
3
  import util from 'util';
4
+ import { configProvider, ConfigurationProvider } from '../core/loaders/ConfigurationProvider.js';
5
+ import { Logger } from '../utils/logger.js';
6
+ import { updateCheckTracker } from '../utils/UpdateCheckTracker.js';
7
+ import { InstallOperationManager } from '../core/loaders/InstallOperationManager.js';
8
+ import * as RecordingConstants from '../core/metadatas/recordingConstants.js';
9
+ import { systemSettingsManager } from '../core/loaders/SystemSettingsManager.js';
4
10
  /**
5
11
  * Service responsible for managing requirements installation and status
6
12
  */
7
13
  export class RequirementService {
8
14
  static instance;
9
- installerFactory = createInstallerFactory(util.promisify(exec));
10
- constructor() { }
15
+ installerFactory;
16
+ constructor() {
17
+ this.installerFactory = createInstallerFactory(util.promisify(exec));
18
+ }
11
19
  /**
12
20
  * Get the singleton instance of RequirementService
13
21
  * @returns The RequirementService instance
@@ -18,76 +26,227 @@ export class RequirementService {
18
26
  }
19
27
  return RequirementService.instance;
20
28
  }
29
+ generateOperationId() {
30
+ return `install-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
31
+ }
21
32
  /**
22
- * Check the installation status of a requirement
23
- * @param requirement The requirement to check
24
- * @returns The installation status
33
+ * Checks and installs requirements for a server if needed.
34
+ * @param categoryName The category name.
35
+ * @param serverName The server name.
36
+ * @param options The installation options.
37
+ * @returns A failure result if requirements check fails, null if requirements are satisfied or installation started in background.
25
38
  */
26
- async checkRequirementStatus(requirement, options) {
27
- // Validate requirement
28
- this.validateRequirement(requirement);
29
- // Check the installation status
30
- return await this.installerFactory.checkInstallation(requirement, options);
39
+ async checkAndInstallRequirements(categoryName, serverName, options) {
40
+ const recoder = InstallOperationManager.getInstance(categoryName, serverName);
41
+ return recoder.recording(async () => {
42
+ const configProvider = ConfigurationProvider.getInstance();
43
+ const feedConfig = await configProvider.getFeedConfiguration(categoryName);
44
+ if (!feedConfig) {
45
+ const errorMsg = 'Feed configuration not found';
46
+ // No need to record step here, recoder.recording will handle failure
47
+ return {
48
+ success: false, message: errorMsg,
49
+ status: [{ status: 'failed', type: 'install', target: 'server', message: errorMsg }]
50
+ };
51
+ }
52
+ const serverConfig = feedConfig.mcpServers.find((s) => s.name === serverName);
53
+ if (!serverConfig?.dependencies?.requirements || serverConfig.dependencies.requirements.length === 0) {
54
+ const msg = `No requirements for ${serverName} in category ${categoryName}`;
55
+ Logger.debug(msg);
56
+ await recoder.recordStep(RecordingConstants.STEP_CHECKING_REQUIREMENT_STATUS, 'completed', msg);
57
+ return null;
58
+ }
59
+ const ready = await recoder.recording(async () => {
60
+ await recoder.recordStep(RecordingConstants.STEP_CHECKING_REQUIREMENT_STATUS, 'in-progress', 'Checking status of all requirements.');
61
+ const requirementStatuses = await Promise.all(serverConfig.dependencies.requirements.map(async (req) => {
62
+ const reqConfig = feedConfig.requirements?.find((r) => r.name === req.name) || {
63
+ name: req.name, version: req.version, type: 'npm' // Default to npm if not fully defined
64
+ };
65
+ return await this.installerFactory.checkInstallation(reqConfig, options);
66
+ }));
67
+ const requirementsReady = await configProvider.isRequirementsReady(categoryName, serverName);
68
+ for (const status of requirementStatuses) {
69
+ if (status.installed && !requirementsReady) {
70
+ await configProvider.updateRequirementStatus(categoryName, status.name, { ...status, installed: true });
71
+ }
72
+ else if (!status.installed && requirementsReady) {
73
+ await configProvider.updateRequirementStatus(categoryName, status.name, { ...status, installed: false });
74
+ }
75
+ }
76
+ return requirementStatuses.every(status => status.installed);
77
+ }, {
78
+ stepName: RecordingConstants.STEP_CHECKING_REQUIREMENT_STATUS,
79
+ inProgressMessage: `Checking status of all requirements for ${serverName}`,
80
+ endMessage: (ready) => ready ? `Requirements for ${serverName} in ${categoryName} are already installed.` : 'Requirements check completed. Some requirements need installation.',
81
+ });
82
+ // If requirements are already installed, return null
83
+ if (ready)
84
+ return null;
85
+ const sortedRequirements = [...serverConfig.dependencies.requirements].sort((a, b) => {
86
+ const orderA = a.order ?? Infinity;
87
+ const orderB = b.order ?? Infinity;
88
+ return orderA - orderB;
89
+ });
90
+ // Use recordingAsync for the background task
91
+ recoder.recordingAsync(() => this.installRequirementsInBackground(categoryName, serverName, feedConfig, sortedRequirements, options, recoder), {
92
+ stepName: RecordingConstants.STEP_INSTALLING_REQUIREMENTS_IN_BACKGROUND,
93
+ inProgressMessage: 'Starting background installation of requirements.',
94
+ endMessage: () => 'Background installation of requirements completed.',
95
+ onError: (err) => {
96
+ const errorMsg = `Error in background requirement installations for ${serverName} in ${categoryName}: ${err instanceof Error ? err.message : String(err)}`;
97
+ Logger.error(errorMsg);
98
+ return errorMsg; // This message will be recorded for the 'failed' step
99
+ }
100
+ });
101
+ // The main operation returns null as installation is happening in background
102
+ return null;
103
+ }, {
104
+ stepName: RecordingConstants.STEP_CHECK_AND_INSTALL_REQUIREMENTS,
105
+ inProgressMessage: `Checking and installing requirements for ${serverName}`,
106
+ endMessage: (result) => result?.success === false ? `Requirement check/install failed: ${result.message}` : `Requirement check and install process for ${serverName} completed.`,
107
+ onResult: (result) => result === null || result.success !== false // Success if null (bg install) or result.success is not false
108
+ });
31
109
  }
32
110
  /**
33
- * Check if updates are available for a requirement
34
- * @param requirement The requirement to check for updates
35
- * @returns Updated status with available updates information
111
+ * Installs requirements in background without blocking the main thread.
112
+ * Requirements with the same order are installed in parallel.
113
+ * @param categoryName The category name.
114
+ * @param feedConfig The feed configuration.
115
+ * @param sortedRequirements Array of requirements sorted by order.
116
+ * @param options The installation options.
36
117
  */
37
- async checkRequirementForUpdates(requirement, currentStatus) {
38
- // Validate requirement
39
- this.validateRequirement(requirement);
40
- // Get current status
41
- // Check for updates using the appropriate installer
42
- const installer = this.installerFactory.getInstaller(requirement);
43
- if (!installer || !installer.supportCheckUpdates()) {
44
- return currentStatus;
118
+ async installRequirementsInBackground(categoryName, serverName, feedConfig, sortedRequirements, options, recoder // Added recoder parameter
119
+ ) {
120
+ const configProvider = ConfigurationProvider.getInstance();
121
+ const requirementGroups = sortedRequirements.reduce((groups, req) => {
122
+ const order = req.order ?? Infinity;
123
+ if (!groups[order]) {
124
+ groups[order] = [];
125
+ }
126
+ groups[order].push(req);
127
+ return groups;
128
+ }, {});
129
+ const orderKeys = Object.keys(requirementGroups).map(Number).sort((a, b) => a - b);
130
+ for (const order of orderKeys) {
131
+ const group = requirementGroups[order];
132
+ await Promise.all(group.map(async (requirement) => {
133
+ const stepName = `InstallRequirement_${requirement.name}`;
134
+ return recoder.recording(async () => {
135
+ let requirementConfig = feedConfig.requirements?.find((r) => r.name === requirement.name);
136
+ if (!requirementConfig) {
137
+ requirementConfig = { name: requirement.name, version: requirement.version, type: 'npm' }; // Default
138
+ const warnMsg = `Requirement ${requirement.name} not found in feed's requirements definitions for category ${categoryName}. Using default config.`;
139
+ Logger.warn(warnMsg);
140
+ // This case is a "completion" of this specific step with a warning, not a failure.
141
+ // The recording will mark it completed, and the message will be this warning.
142
+ return { installed: true, message: warnMsg, type: requirementConfig.type, name: requirement.name, version: requirement.version };
143
+ }
144
+ let currentOptions = { ...options };
145
+ const currentStatus = await configProvider.getRequirementStatus(categoryName, requirement.name);
146
+ if (requirementConfig.type === 'pip' && currentStatus?.pythonEnv && !currentOptions?.settings?.pythonEnv) {
147
+ currentOptions = {
148
+ ...currentOptions,
149
+ settings: { ...currentOptions?.settings, pythonEnv: currentStatus.pythonEnv }
150
+ };
151
+ }
152
+ const installer = this.installerFactory.getInstaller(requirementConfig);
153
+ if (!installer) {
154
+ const errorMsg = `No installer found for requirement type: ${requirementConfig.type}`;
155
+ await this.updateRequirementFailureStatus(categoryName, requirement.name, requirementConfig.type, errorMsg);
156
+ throw new Error(errorMsg); // Caught by recoder.recording
157
+ }
158
+ const operationId = this.generateOperationId();
159
+ await this.updateRequirementProgressStatus(categoryName, requirement.name, requirementConfig.type, operationId);
160
+ const installStatus = await installer.install(requirementConfig, recoder, currentOptions);
161
+ const success = installStatus.installed;
162
+ const message = success ? `Requirement ${requirement.name} installed successfully` : `Failed to install ${requirement.name}: ${installStatus.error || 'Unknown error'}`;
163
+ await this.updateRequirementCompletionStatus(categoryName, requirement.name, installStatus, operationId);
164
+ if (!success) {
165
+ throw new Error(message); // Caught by recoder.recording
166
+ }
167
+ return { ...installStatus, message };
168
+ }, {
169
+ stepName: stepName,
170
+ inProgressMessage: `Starting installation of ${requirement.name}`,
171
+ onResult: (status) => status.installed,
172
+ endMessage: (status) => status.message // Use the message from the installStatus
173
+ });
174
+ }));
45
175
  }
46
- // Pass pythonEnv from currentStatus if it exists for pip packages
47
- const options = requirement.type === 'pip' && currentStatus.pythonEnv
48
- ? { settings: { pythonEnv: currentStatus.pythonEnv } }
49
- : undefined;
50
- const status = await this.checkRequirementStatus(requirement, options);
51
- return await installer.checkForUpdates(requirement, status);
52
176
  }
53
177
  /**
54
- * Update a requirement to a new version
55
- * @param requirement The requirement configuration
56
- * @param updateVersion The version to update to
57
- * @returns The updated requirement status
178
+ * Helper to update requirement status for failure case.
179
+ * @param categoryName The category name.
180
+ * @param requirementName The name of the requirement.
181
+ * @param requirementType The type of the requirement.
182
+ * @param errorMessage The error message.
58
183
  */
59
- async updateRequirement(requirement, updateVersion, options) {
60
- // Validate requirement
61
- this.validateRequirement(requirement);
62
- // Create an updated requirement with the new version
63
- const updatedRequirement = {
64
- ...requirement,
65
- version: requirement.version.includes('latest') ? requirement.version : updateVersion,
66
- };
67
- // Install the updated version
68
- return await this.installerFactory.install(updatedRequirement, options);
184
+ async updateRequirementFailureStatus(categoryName, requirementName, requirementType, errorMessage) {
185
+ const configProvider = ConfigurationProvider.getInstance();
186
+ await configProvider.updateRequirementStatus(categoryName, requirementName, {
187
+ name: requirementName, type: requirementType, installed: false, error: errorMessage,
188
+ operationStatus: {
189
+ status: 'failed', type: 'install', target: 'requirement',
190
+ message: `Error installing requirement: ${errorMessage}`,
191
+ operationId: this.generateOperationId()
192
+ }
193
+ });
194
+ }
195
+ /**
196
+ * Helper to update requirement status for in-progress case.
197
+ * @param categoryName The category name.
198
+ * @param requirementName The name of the requirement.
199
+ * @param requirementType The type of the requirement.
200
+ * @param operationId The operation ID.
201
+ */
202
+ async updateRequirementProgressStatus(categoryName, requirementName, requirementType, operationId) {
203
+ const configProvider = ConfigurationProvider.getInstance();
204
+ await configProvider.updateRequirementStatus(categoryName, requirementName, {
205
+ name: requirementName, type: requirementType, installed: false, inProgress: true,
206
+ operationStatus: {
207
+ status: 'in-progress', type: 'install', target: 'requirement',
208
+ message: `Installing requirement: ${requirementName}`, operationId
209
+ }
210
+ });
211
+ }
212
+ /**
213
+ * Helper to update requirement status for completion case.
214
+ * @param categoryName The category name.
215
+ * @param requirementName The name of the requirement.
216
+ * @param installStatus The installation status.
217
+ * @param operationId The operation ID.
218
+ */
219
+ async updateRequirementCompletionStatus(categoryName, requirementName, installStatus, operationId) {
220
+ const configProvider = ConfigurationProvider.getInstance();
221
+ await configProvider.updateRequirementStatus(categoryName, requirementName, {
222
+ ...installStatus,
223
+ operationStatus: {
224
+ status: installStatus.installed ? 'completed' : 'failed',
225
+ type: 'install', target: 'requirement',
226
+ message: installStatus.installed
227
+ ? `Requirement ${requirementName} installed successfully`
228
+ : `Failed to install ${requirementName}`,
229
+ operationId
230
+ }
231
+ });
69
232
  }
70
233
  /**
71
- * Validate a requirement configuration
72
- * @param requirement The requirement to validate
73
- * @throws Error if the requirement is invalid
234
+ * Validate a requirement configuration.
235
+ * @param requirement The requirement to validate.
236
+ * @throws Error if the requirement is invalid.
74
237
  */
75
238
  validateRequirement(requirement) {
76
- // Ensure requirement has required fields
77
239
  if (!requirement.name) {
78
240
  throw new Error('Requirement name is required');
79
241
  }
80
242
  if (!requirement.type) {
81
243
  throw new Error('Requirement type is required');
82
244
  }
83
- // For type 'other', registry must be specified
84
245
  if (requirement.type === 'other' && !requirement.registry) {
85
246
  throw new Error('Registry must be specified for requirement type "other"');
86
247
  }
87
- // Validate registry configuration if provided
88
248
  if (requirement.registry) {
89
249
  const { githubRelease, artifacts } = requirement.registry;
90
- // Validate GitHub release configuration
91
250
  if (githubRelease) {
92
251
  if (!githubRelease.repository) {
93
252
  throw new Error('Repository is required for GitHub release registry');
@@ -96,7 +255,6 @@ export class RequirementService {
96
255
  throw new Error('Asset name is required for GitHub release registry');
97
256
  }
98
257
  }
99
- // Validate artifacts registry configuration
100
258
  if (artifacts) {
101
259
  if (!artifacts.registryUrl) {
102
260
  throw new Error('Registry URL is required for artifacts registry');
@@ -104,6 +262,287 @@ export class RequirementService {
104
262
  }
105
263
  }
106
264
  }
265
+ /**
266
+ * Check for updates to requirements for all server categories
267
+ * This method is called periodically to check for updates
268
+ */
269
+ async checkRequirementForUpdateAsync() {
270
+ const allCategories = await configProvider.getServerCategories();
271
+ allCategories.forEach(async (serverCategory) => {
272
+ // Start async check for requirement updates if one isn't already in progress
273
+ if (serverCategory && serverCategory.feedConfiguration && serverCategory.name) {
274
+ // Check if update is already in progress using the tracker
275
+ const shouldCheckForUpdates = await updateCheckTracker.startOperation(serverCategory.name);
276
+ if (shouldCheckForUpdates) {
277
+ Logger.info(`Checking the status of requirements in ${serverCategory.name}`);
278
+ this.checkRequirementsForUpdateInternal(serverCategory).catch(error => {
279
+ // Ensure we mark the operation as complete on error
280
+ if (serverCategory.name) {
281
+ updateCheckTracker.endOperation(serverCategory.name)
282
+ .catch(lockError => console.error(`Failed to mark update check as complete: ${lockError.message}`));
283
+ }
284
+ Logger.error(`Error checking requirements for updates: ${error.message}`);
285
+ });
286
+ }
287
+ else {
288
+ Logger.debug(`Update check already in progress for ${serverCategory.name}, skipping`);
289
+ }
290
+ }
291
+ });
292
+ }
293
+ /**
294
+ * Check for updates to requirements for a specific server category
295
+ * @param categoryName The name of the server category
296
+ * @param serverName The name of the server (optional)
297
+ */
298
+ async checkServerRequirementForUpdateAsync(categoryName, serverName) {
299
+ const serverCategory = await configProvider.getServerCategory(categoryName);
300
+ if (!serverCategory) {
301
+ Logger.error(`Server category ${categoryName} not found`);
302
+ return;
303
+ }
304
+ const shouldCheckForUpdates = await updateCheckTracker.startOperation(`${serverCategory.name}:${serverName}`);
305
+ if (shouldCheckForUpdates) {
306
+ this.checkRequirementsForUpdateInternal(serverCategory, serverName)
307
+ .then(() => {
308
+ // Mark the operation as complete
309
+ updateCheckTracker.endOperation(`${serverCategory.name}:${serverName}`)
310
+ .catch(lockError => console.error(`Failed to mark update check as complete: ${lockError.message}`));
311
+ })
312
+ .catch(error => {
313
+ // Ensure we mark the operation as complete on error
314
+ updateCheckTracker.endOperation(`${serverCategory.name}:${serverName}`)
315
+ .catch(lockError => console.error(`Failed to mark update check as complete: ${lockError.message}`));
316
+ Logger.error(`Error checking requirements for updates: ${error.message}`);
317
+ });
318
+ }
319
+ }
320
+ /**
321
+ * Check for updates to requirements for a server category
322
+ * @param serverCategory The server category to check
323
+ * @param serverName The name of the server (optional). When serverName is provided, check the requirement always
324
+ * @private
325
+ */
326
+ async checkRequirementsForUpdateInternal(serverCategory, serverName) {
327
+ if (!serverCategory.name || !serverCategory.feedConfiguration?.requirements?.length) {
328
+ return;
329
+ }
330
+ try {
331
+ for (const requirement of serverCategory.feedConfiguration.requirements) {
332
+ if (requirement.version.includes('latest')) {
333
+ // Get current status if available
334
+ const currentStatus = serverCategory.installationStatus?.requirementsStatus[requirement.name];
335
+ if (!currentStatus)
336
+ continue;
337
+ let providedServerName = serverName;
338
+ if (providedServerName) {
339
+ // If serverName is provided, check if the requirement is associated with that server
340
+ Logger.debug(`Checking whether requirement ${requirement.name} has update for server ${serverName}`);
341
+ const serverConfig = serverCategory.feedConfiguration.mcpServers.find((s) => s.name === serverName);
342
+ if (!serverConfig?.dependencies?.requirements?.some((r) => r.name == requirement.name)) {
343
+ Logger.debug(`Requirement ${requirement.name} is not associated with server ${serverName}. Skipping update check.`);
344
+ continue;
345
+ }
346
+ }
347
+ else {
348
+ providedServerName = serverCategory.feedConfiguration.mcpServers.find((s) => s.dependencies?.requirements?.some((r) => r.name == requirement.name))?.name;
349
+ }
350
+ if (!providedServerName) {
351
+ // We need to find the server name for the requirement, if not able to find, skip as the requirement is not associated with any server
352
+ Logger.debug(`No server using requirement ${requirement.name}. Skipping update check.`);
353
+ continue;
354
+ }
355
+ // Check for updates
356
+ const updatedStatus = await this.checkRequirementForUpdates(requirement, currentStatus, serverCategory.name, providedServerName);
357
+ // If update information is found, update the configuration
358
+ if (updatedStatus.availableUpdate && serverCategory.name) {
359
+ await configProvider.updateRequirementStatus(serverCategory.name, requirement.name, updatedStatus);
360
+ // Also update the in-memory status for immediate use
361
+ if (serverCategory.installationStatus?.requirementsStatus) {
362
+ serverCategory.installationStatus.requirementsStatus[requirement.name] = updatedStatus;
363
+ }
364
+ }
365
+ currentStatus.lastCheckTime = new Date().toISOString();
366
+ await configProvider.updateRequirementStatus(serverCategory.name, requirement.name, currentStatus);
367
+ if (serverCategory.installationStatus?.requirementsStatus) {
368
+ serverCategory.installationStatus.requirementsStatus[requirement.name] = updatedStatus;
369
+ }
370
+ }
371
+ }
372
+ }
373
+ catch (error) {
374
+ Logger.error(`Error checking requirements for updates: ${error instanceof Error ? error.message : String(error)}`);
375
+ throw error; // Re-throw the error to be handled by the caller
376
+ }
377
+ }
378
+ /**
379
+ * Check the installation status of a requirement
380
+ * @param requirement The requirement to check
381
+ * @param options Optional installation options
382
+ * @returns The installation status
383
+ */
384
+ async checkRequirementStatus(requirement, options) {
385
+ this.validateRequirement(requirement);
386
+ return await this.installerFactory.checkInstallation(requirement, options);
387
+ }
388
+ /**
389
+ * Check if updates are available for a requirement
390
+ * @param requirement The requirement to check for updates
391
+ * @param currentStatus The current status of the requirement
392
+ * @param categoryName The category name
393
+ * @param serverName The server name (optional)
394
+ * @returns Updated status with available updates information
395
+ */
396
+ async checkRequirementForUpdates(requirement, currentStatus, categoryName, serverName) {
397
+ this.validateRequirement(requirement);
398
+ const installer = this.installerFactory.getInstaller(requirement);
399
+ if (!installer || !installer.supportCheckUpdates()) {
400
+ return currentStatus;
401
+ }
402
+ var systemSettings = await systemSettingsManager.getSystemSettings();
403
+ const options = requirement.type === 'pip'
404
+ ? { settings: { pythonEnv: systemSettings.pythonEnvs?.[`${categoryName}:${serverName}`] || systemSettings.pythonEnvs?.system || currentStatus.pythonEnv } }
405
+ : undefined;
406
+ const status = await this.checkRequirementStatus(requirement, options);
407
+ return await installer.checkForUpdates(requirement, status);
408
+ }
409
+ /**
410
+ * Process requirement updates specified in serverInstallOptions.
411
+ * All updates are processed in parallel for maximum efficiency.
412
+ * @param categoryName The category name.
413
+ * @param serverName The server name.
414
+ * @param options The installation options.
415
+ */
416
+ async processRequirementUpdates(categoryName, serverName, options) {
417
+ const operationKey = `requirement-updates-${categoryName}-${serverName}`;
418
+ const canProceed = await updateCheckTracker.startOperation(operationKey);
419
+ if (!canProceed) {
420
+ Logger.info(`Requirement updates for ${categoryName}/${serverName} already in progress, skipping`);
421
+ return;
422
+ }
423
+ const recoder = InstallOperationManager.getInstance(categoryName, serverName);
424
+ try {
425
+ await recoder.recording(async () => {
426
+ const configProvider = ConfigurationProvider.getInstance();
427
+ const feedConfig = await configProvider.getFeedConfiguration(categoryName);
428
+ if (!feedConfig) {
429
+ const errorMsg = `Feed configuration not found for category: ${categoryName}`;
430
+ Logger.error(errorMsg);
431
+ throw new Error(errorMsg); // This will be caught by recoder.recording
432
+ }
433
+ const updatePromises = options.requirements?.map(async (reqToUpdate) => {
434
+ const stepName = `${RecordingConstants.STEP_INSTALL_REQUIREMENT_PREFIX}: ${reqToUpdate.name}`;
435
+ return recoder.recording(async () => {
436
+ let reqConfig;
437
+ let currentStatus;
438
+ try {
439
+ reqConfig = feedConfig.requirements?.find((r) => r.name === reqToUpdate.name);
440
+ if (!reqConfig) {
441
+ const errorMsg = `Requirement configuration not found for: ${reqToUpdate.name}`;
442
+ Logger.error(errorMsg);
443
+ await configProvider.updateRequirementStatus(categoryName, reqToUpdate.name, {
444
+ name: reqToUpdate.name, type: 'unknown', installed: false, inProgress: false,
445
+ error: errorMsg,
446
+ operationStatus: { status: 'failed', type: 'update', target: 'requirement', message: errorMsg }
447
+ });
448
+ throw new Error(errorMsg);
449
+ }
450
+ currentStatus = await configProvider.getRequirementStatus(categoryName, reqToUpdate.name);
451
+ if (!currentStatus) {
452
+ const errorMsg = `No current status found for requirement: ${reqToUpdate.name}`;
453
+ Logger.error(errorMsg);
454
+ await configProvider.updateRequirementStatus(categoryName, reqToUpdate.name, {
455
+ name: reqToUpdate.name, type: reqConfig.type, installed: false, inProgress: false,
456
+ error: errorMsg,
457
+ operationStatus: { status: 'failed', type: 'update', target: 'requirement', message: errorMsg }
458
+ });
459
+ throw new Error(errorMsg);
460
+ }
461
+ Logger.info(`Updating ${reqToUpdate.name} from ${currentStatus.version || 'unknown'} to ${reqToUpdate.version}`);
462
+ await configProvider.updateRequirementStatus(categoryName, reqToUpdate.name, {
463
+ ...currentStatus, name: reqToUpdate.name,
464
+ type: currentStatus.type || reqConfig.type || 'unknown',
465
+ installed: currentStatus.installed || false, inProgress: true,
466
+ operationStatus: {
467
+ status: 'in-progress', type: 'update', target: 'requirement',
468
+ message: `Updating ${reqToUpdate.name} from ${currentStatus.version || 'unknown'} to ${reqToUpdate.version}`
469
+ }
470
+ });
471
+ let currentOptions = { ...options };
472
+ if (reqConfig.type === 'pip' && currentStatus.pythonEnv && !currentOptions?.settings?.pythonEnv) {
473
+ currentOptions = {
474
+ ...currentOptions,
475
+ settings: { ...currentOptions?.settings, pythonEnv: currentStatus.pythonEnv }
476
+ };
477
+ }
478
+ const updatedStatus = await this.updateRequirement(reqConfig, reqToUpdate.version, recoder, currentOptions);
479
+ const successMessage = `Successfully updated ${reqToUpdate.name} to version ${reqToUpdate.version}`;
480
+ const failureMessage = `Failed to update ${reqToUpdate.name} to version ${reqToUpdate.version}. Error: ${updatedStatus.error || 'Unknown'}`;
481
+ await configProvider.updateRequirementStatus(categoryName, reqToUpdate.name, {
482
+ ...updatedStatus, name: reqToUpdate.name,
483
+ type: updatedStatus.type || currentStatus.type || reqConfig.type || 'unknown',
484
+ installed: updatedStatus.installed, inProgress: false,
485
+ operationStatus: {
486
+ status: updatedStatus.installed ? 'completed' : 'failed',
487
+ type: 'update', target: 'requirement',
488
+ message: updatedStatus.installed ? successMessage : failureMessage
489
+ },
490
+ availableUpdate: updatedStatus.installed ? undefined : currentStatus.availableUpdate
491
+ });
492
+ if (!updatedStatus.installed) {
493
+ Logger.error(failureMessage);
494
+ throw new Error(failureMessage);
495
+ }
496
+ Logger.info(successMessage);
497
+ return updatedStatus;
498
+ }
499
+ catch (error) {
500
+ const errorMsg = `Error updating requirement ${reqToUpdate.name}: ${error instanceof Error ? error.message : String(error)}`;
501
+ Logger.error(errorMsg);
502
+ await configProvider.updateRequirementStatus(categoryName, reqToUpdate.name, {
503
+ name: reqToUpdate.name,
504
+ type: reqConfig?.type || currentStatus?.type || 'unknown',
505
+ installed: false, inProgress: false,
506
+ error: error instanceof Error ? error.message : String(error),
507
+ operationStatus: { status: 'failed', type: 'update', target: 'requirement', message: errorMsg }
508
+ });
509
+ throw error; // Re-throw to be handled by recoder.recording
510
+ }
511
+ }, {
512
+ stepName: stepName,
513
+ inProgressMessage: `Processing update for requirement ${reqToUpdate.name}`,
514
+ onResult: (status) => status.installed, // status is the returned updatedStatus
515
+ });
516
+ });
517
+ if (updatePromises) {
518
+ await Promise.all(updatePromises);
519
+ }
520
+ }, {
521
+ stepName: RecordingConstants.STEP_PROCESS_REQUIREMENT_UPDATES,
522
+ inProgressMessage: `Starting to process requirement updates for ${serverName}`,
523
+ // If fn() succeeds, data is void. If fn() throws, recording() uses the error message.
524
+ endMessage: () => `Finished processing requirement updates for ${serverName}`
525
+ });
526
+ }
527
+ finally {
528
+ await updateCheckTracker.endOperation(operationKey);
529
+ }
530
+ }
531
+ /**
532
+ * Update a requirement to a new version
533
+ * @param requirement The requirement configuration
534
+ * @param updateVersion The version to update to
535
+ * @param options Optional installation options
536
+ * @returns The updated requirement status
537
+ */
538
+ async updateRequirement(requirement, updateVersion, recorder, options) {
539
+ this.validateRequirement(requirement);
540
+ const updatedRequirement = {
541
+ ...requirement,
542
+ version: requirement.version.includes('latest') ? requirement.version : updateVersion,
543
+ };
544
+ return await this.installerFactory.install(updatedRequirement, recorder, options);
545
+ }
107
546
  }
108
547
  // Export a singleton instance
109
548
  export const requirementService = RequirementService.getInstance();
@@ -14,12 +14,6 @@ export declare class ServerService {
14
14
  * Gets a server by name
15
15
  */
16
16
  getServerCategory(categoryName: string): Promise<MCPServerCategory | undefined>;
17
- /**
18
- * Check for updates to requirements for a server category
19
- * @param serverCategory The server category to check
20
- * @private
21
- */
22
- private checkRequirementsForUpdate;
23
17
  /**
24
18
  * Gets the schema for a specific server in a category
25
19
  */