imcp 0.0.14 → 0.0.16

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 (136) hide show
  1. package/dist/core/ConfigurationProvider.d.ts +1 -0
  2. package/dist/core/ConfigurationProvider.js +15 -0
  3. package/dist/core/InstallationService.js +2 -7
  4. package/dist/core/MCPManager.d.ts +11 -2
  5. package/dist/core/MCPManager.js +24 -1
  6. package/dist/core/RequirementService.js +2 -8
  7. package/dist/core/installers/clients/BaseClientInstaller.d.ts +51 -0
  8. package/dist/core/installers/clients/BaseClientInstaller.js +160 -0
  9. package/dist/core/installers/clients/ClientInstaller.d.ts +16 -9
  10. package/dist/core/installers/clients/ClientInstaller.js +80 -527
  11. package/dist/core/installers/clients/ClientInstallerFactory.d.ts +20 -0
  12. package/dist/core/installers/clients/ClientInstallerFactory.js +37 -0
  13. package/dist/core/installers/clients/ClineInstaller.d.ts +18 -0
  14. package/dist/core/installers/clients/ClineInstaller.js +124 -0
  15. package/dist/core/installers/clients/GithubCopilotInstaller.d.ts +34 -0
  16. package/dist/core/installers/clients/GithubCopilotInstaller.js +162 -0
  17. package/dist/core/installers/clients/MSRooCodeInstaller.d.ts +15 -0
  18. package/dist/core/installers/clients/MSRooCodeInstaller.js +122 -0
  19. package/dist/core/installers/requirements/BaseInstaller.d.ts +11 -34
  20. package/dist/core/installers/requirements/BaseInstaller.js +5 -116
  21. package/dist/core/installers/requirements/CommandInstaller.d.ts +6 -1
  22. package/dist/core/installers/requirements/CommandInstaller.js +7 -0
  23. package/dist/core/installers/requirements/GeneralInstaller.d.ts +6 -1
  24. package/dist/core/installers/requirements/GeneralInstaller.js +9 -4
  25. package/dist/core/installers/requirements/NpmInstaller.d.ts +46 -7
  26. package/dist/core/installers/requirements/NpmInstaller.js +150 -58
  27. package/dist/core/installers/requirements/PipInstaller.d.ts +9 -0
  28. package/dist/core/installers/requirements/PipInstaller.js +66 -28
  29. package/dist/core/onboard/FeedOnboardService.d.ts +50 -13
  30. package/dist/core/onboard/FeedOnboardService.js +263 -88
  31. package/dist/core/onboard/OnboardProcessor.d.ts +79 -0
  32. package/dist/core/onboard/OnboardProcessor.js +290 -0
  33. package/dist/core/onboard/OnboardStatus.d.ts +49 -0
  34. package/dist/core/onboard/OnboardStatus.js +10 -0
  35. package/dist/core/onboard/OnboardStatusManager.d.ts +57 -0
  36. package/dist/core/onboard/OnboardStatusManager.js +176 -0
  37. package/dist/core/types.d.ts +4 -5
  38. package/dist/core/validators/FeedValidator.d.ts +8 -1
  39. package/dist/core/validators/FeedValidator.js +60 -7
  40. package/dist/core/validators/IServerValidator.d.ts +19 -0
  41. package/dist/core/validators/IServerValidator.js +2 -0
  42. package/dist/core/validators/SSEServerValidator.d.ts +15 -0
  43. package/dist/core/validators/SSEServerValidator.js +39 -0
  44. package/dist/core/validators/ServerValidatorFactory.d.ts +24 -0
  45. package/dist/core/validators/ServerValidatorFactory.js +45 -0
  46. package/dist/core/validators/StdioServerValidator.d.ts +46 -0
  47. package/dist/core/validators/StdioServerValidator.js +229 -0
  48. package/dist/services/InstallRequestValidator.d.ts +1 -1
  49. package/dist/services/ServerService.d.ts +9 -6
  50. package/dist/services/ServerService.js +18 -7
  51. package/dist/utils/adoUtils.d.ts +29 -0
  52. package/dist/utils/adoUtils.js +252 -0
  53. package/dist/utils/clientUtils.d.ts +0 -7
  54. package/dist/utils/clientUtils.js +0 -42
  55. package/dist/utils/githubUtils.d.ts +10 -0
  56. package/dist/utils/githubUtils.js +22 -0
  57. package/dist/utils/macroExpressionUtils.d.ts +38 -0
  58. package/dist/utils/macroExpressionUtils.js +116 -0
  59. package/dist/utils/osUtils.d.ts +4 -20
  60. package/dist/utils/osUtils.js +78 -23
  61. package/dist/web/contract/serverContract.d.ts +3 -1
  62. package/dist/web/public/css/notifications.css +48 -17
  63. package/dist/web/public/css/onboard.css +66 -3
  64. package/dist/web/public/index.html +84 -16
  65. package/dist/web/public/js/api.js +3 -6
  66. package/dist/web/public/js/flights/flights.js +127 -0
  67. package/dist/web/public/js/modal/installation.js +5 -5
  68. package/dist/web/public/js/modal/modalSetup.js +3 -2
  69. package/dist/web/public/js/notifications.js +66 -27
  70. package/dist/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +338 -0
  71. package/dist/web/public/js/onboard/formProcessor.js +810 -255
  72. package/dist/web/public/js/onboard/index.js +328 -85
  73. package/dist/web/public/js/onboard/publishHandler.js +132 -0
  74. package/dist/web/public/js/onboard/state.js +61 -17
  75. package/dist/web/public/js/onboard/templates.js +217 -249
  76. package/dist/web/public/js/onboard/uiHandlers.js +679 -117
  77. package/dist/web/public/js/onboard/validationHandlers.js +378 -0
  78. package/dist/web/public/js/serverCategoryList.js +15 -2
  79. package/dist/web/public/onboard.html +191 -45
  80. package/dist/web/public/styles.css +91 -1
  81. package/dist/web/server.d.ts +0 -10
  82. package/dist/web/server.js +131 -22
  83. package/package.json +2 -2
  84. package/src/core/ConfigurationProvider.ts +15 -0
  85. package/src/core/InstallationService.ts +2 -7
  86. package/src/core/MCPManager.ts +26 -1
  87. package/src/core/RequirementService.ts +2 -9
  88. package/src/core/installers/clients/BaseClientInstaller.ts +196 -0
  89. package/src/core/installers/clients/ClientInstaller.ts +97 -608
  90. package/src/core/installers/clients/ClientInstallerFactory.ts +43 -0
  91. package/src/core/installers/clients/ClineInstaller.ts +135 -0
  92. package/src/core/installers/clients/GithubCopilotInstaller.ts +179 -0
  93. package/src/core/installers/clients/MSRooCodeInstaller.ts +133 -0
  94. package/src/core/installers/requirements/BaseInstaller.ts +13 -136
  95. package/src/core/installers/requirements/CommandInstaller.ts +9 -1
  96. package/src/core/installers/requirements/GeneralInstaller.ts +11 -4
  97. package/src/core/installers/requirements/NpmInstaller.ts +178 -61
  98. package/src/core/installers/requirements/PipInstaller.ts +68 -29
  99. package/src/core/onboard/FeedOnboardService.ts +346 -0
  100. package/src/core/onboard/OnboardProcessor.ts +305 -0
  101. package/src/core/onboard/OnboardStatus.ts +55 -0
  102. package/src/core/onboard/OnboardStatusManager.ts +188 -0
  103. package/src/core/types.ts +4 -5
  104. package/src/core/validators/FeedValidator.ts +79 -0
  105. package/src/core/validators/IServerValidator.ts +21 -0
  106. package/src/core/validators/SSEServerValidator.ts +43 -0
  107. package/src/core/validators/ServerValidatorFactory.ts +51 -0
  108. package/src/core/validators/StdioServerValidator.ts +259 -0
  109. package/src/services/InstallRequestValidator.ts +1 -1
  110. package/src/services/ServerService.ts +22 -7
  111. package/src/utils/adoUtils.ts +291 -0
  112. package/src/utils/clientUtils.ts +0 -44
  113. package/src/utils/githubUtils.ts +24 -0
  114. package/src/utils/macroExpressionUtils.ts +121 -0
  115. package/src/utils/osUtils.ts +89 -24
  116. package/src/web/contract/serverContract.ts +74 -0
  117. package/src/web/public/css/notifications.css +48 -17
  118. package/src/web/public/css/onboard.css +107 -0
  119. package/src/web/public/index.html +84 -16
  120. package/src/web/public/js/api.js +3 -6
  121. package/src/web/public/js/flights/flights.js +127 -0
  122. package/src/web/public/js/modal/installation.js +5 -5
  123. package/src/web/public/js/modal/modalSetup.js +3 -2
  124. package/src/web/public/js/notifications.js +66 -27
  125. package/src/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +338 -0
  126. package/src/web/public/js/onboard/formProcessor.js +864 -0
  127. package/src/web/public/js/onboard/index.js +374 -0
  128. package/src/web/public/js/onboard/publishHandler.js +132 -0
  129. package/src/web/public/js/onboard/state.js +76 -0
  130. package/src/web/public/js/onboard/templates.js +343 -0
  131. package/src/web/public/js/onboard/uiHandlers.js +758 -0
  132. package/src/web/public/js/onboard/validationHandlers.js +378 -0
  133. package/src/web/public/js/serverCategoryList.js +15 -2
  134. package/src/web/public/onboard.html +296 -0
  135. package/src/web/public/styles.css +91 -1
  136. package/src/web/server.ts +167 -58
@@ -1,167 +1,110 @@
1
- import { ExtensionInstaller } from './ExtensionInstaller.js';
2
- import { GetBrowserPath } from '../../../utils/osUtils.js';
3
1
  import { ConfigurationProvider } from '../../ConfigurationProvider.js';
4
- import { SUPPORTED_CLIENTS } from '../../constants.js';
5
- import { resolveNpmModulePath, readJsonFile, writeJsonFile } from '../../../utils/clientUtils.js';
6
- import { exec } from 'child_process';
7
- import { promisify } from 'util';
8
- import { Logger } from '../../../utils/logger.js';
9
- import { getPythonPackagePath, getSystemPythonPackageDirectory } from '../../../utils/osUtils.js';
10
- const execAsync = promisify(exec); // Moved promisify here for reuse
2
+ import { ClientInstallerFactory } from './ClientInstallerFactory.js';
3
+ /**
4
+ * Main client installer class that orchestrates client installation process
5
+ * Handles requirements checking and delegates to specific client installers
6
+ */
11
7
  export class ClientInstaller {
12
8
  categoryName;
13
9
  serverName;
14
10
  clients;
15
11
  configProvider;
16
- operationStatuses;
17
12
  constructor(categoryName, serverName, clients) {
18
13
  this.categoryName = categoryName;
19
14
  this.serverName = serverName;
20
15
  this.clients = clients;
21
16
  this.configProvider = ConfigurationProvider.getInstance();
22
- this.operationStatuses = new Map();
23
17
  }
18
+ /**
19
+ * Generate a unique operation ID for tracking installations
20
+ */
24
21
  generateOperationId() {
25
22
  return `install-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
26
23
  }
27
- async getNpmPath() {
28
- try {
29
- // Execute the get-command npm command to find the npm path
30
- const { stdout } = await execAsync('powershell -Command "get-command npm | Select-Object -ExpandProperty Source"');
31
- // Extract the directory from the full path (removing npm.cmd)
32
- const npmPath = stdout.trim().replace(/\\npm\.cmd$/, '');
33
- return npmPath;
34
- }
35
- catch (error) {
36
- console.error('Error getting npm path:', error);
37
- // Return a default path if the command fails
38
- return 'C:\\Program Files\\nodejs';
39
- }
40
- }
41
24
  /**
42
- * Check if a command is available on the system
43
- * @param command The command to check
44
- * @returns True if the command is available, false otherwise
25
+ * Check if server requirements are ready
26
+ * Waits for requirements to be ready with timeout
45
27
  */
46
- async isCommandAvailable(command) {
47
- try {
48
- // For VS Code on macOS, check both command-line tool and app bundle
49
- if (process.platform === 'darwin' && (command === 'code' || command === 'code-insiders')) {
50
- try {
51
- // Try which command first
52
- await execAsync(`which ${command}`);
53
- return true;
54
- }
55
- catch (error) {
56
- // If which fails, check application bundles
57
- const systemVSCodePath = command === 'code' ?
58
- '/Applications/Visual Studio Code.app' :
59
- '/Applications/Visual Studio Code - Insiders.app';
60
- try {
61
- // Check system Applications first
62
- await execAsync(`test -d "${systemVSCodePath}"`);
63
- return true;
64
- }
65
- catch (error) {
66
- // If system Applications check fails, try user Applications
67
- const homedir = process.env.HOME;
68
- if (homedir) {
69
- const userVSCodePath = command === 'code' ?
70
- `${homedir}/Applications/Visual Studio Code.app` :
71
- `${homedir}/Applications/Visual Studio Code - Insiders.app`;
72
- try {
73
- await execAsync(`test -d "${userVSCodePath}"`);
74
- return true;
75
- }
76
- catch (error) {
77
- return false;
78
- }
79
- }
80
- return false;
81
- }
82
- }
83
- }
84
- // For Windows, use where command
85
- if (process.platform === 'win32') {
86
- await execAsync(`where ${command}`);
87
- return true;
88
- }
89
- // For all other cases (Unix-like systems), use which command
90
- await execAsync(`which ${command}`);
91
- return true;
92
- }
93
- catch (error) {
94
- return false;
95
- }
28
+ async checkRequirements(operationId, clientName, options) {
29
+ let requirementsReady = await this.configProvider.isRequirementsReady(this.categoryName, this.serverName);
30
+ if (!requirementsReady) {
31
+ const pendingStatus = {
32
+ status: 'pending',
33
+ type: 'install',
34
+ target: 'server',
35
+ message: `Waiting for requirements to be ready for client: ${clientName}`,
36
+ operationId
37
+ };
38
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, pendingStatus);
39
+ // Set up periodic checking with timeout
40
+ const startTime = Date.now();
41
+ const timeoutMs = 5 * 60 * 1000; // 5 minutes
42
+ const intervalMs = 5 * 1000; // 5 seconds
43
+ while (!requirementsReady && (Date.now() - startTime) < timeoutMs) {
44
+ await new Promise(resolve => setTimeout(resolve, intervalMs));
45
+ requirementsReady = await this.configProvider.isRequirementsReady(this.categoryName, this.serverName);
46
+ }
47
+ }
48
+ var requirementsStatus = await this.configProvider.GetServerRequirementStatus(this.categoryName, this.serverName);
49
+ // Find first non-empty npmPath from requirements status
50
+ const npmPathRequirement = requirementsStatus.find(status => status.npmPath && status.npmPath.length > 0);
51
+ if (npmPathRequirement && npmPathRequirement.npmPath) {
52
+ options.settings = options.settings || {};
53
+ options.settings.npmPath = npmPathRequirement.npmPath;
54
+ }
55
+ return requirementsReady;
96
56
  }
97
- // Modified to accept ServerInstallOptions
57
+ /**
58
+ * Install client with requirements checking
59
+ */
98
60
  async installClient(clientName, options) {
61
+ const operationId = this.generateOperationId();
99
62
  // Check if client is supported
100
- if (!SUPPORTED_CLIENTS[clientName]) {
63
+ if (!ClientInstallerFactory.isClientSupported(clientName)) {
101
64
  return {
102
65
  status: 'failed',
103
66
  type: 'install',
104
67
  target: 'server',
105
68
  message: `Unsupported client: ${clientName}`,
106
- operationId: this.generateOperationId()
69
+ operationId
107
70
  };
108
71
  }
109
72
  // Create initial operation status
110
- const operationId = this.generateOperationId();
111
73
  const initialStatus = {
112
74
  status: 'pending',
113
75
  type: 'install',
114
76
  target: 'server',
115
77
  message: `Initializing installation for client: ${clientName}`,
116
- operationId: operationId
78
+ operationId
117
79
  };
80
+ this.processInstallation(clientName, operationId, options);
118
81
  // Update server status with initial client installation status
119
82
  await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, initialStatus);
120
- // Start the asynchronous installation process without awaiting it
121
- // Pass options down
122
- this.processInstallation(clientName, operationId, options);
123
- // Return the initial status immediately
124
83
  return initialStatus;
125
84
  }
126
- // Modified to accept ServerInstallOptions
127
85
  async processInstallation(clientName, operationId, options) {
128
86
  try {
129
- await ExtensionInstaller.installExtension(clientName);
130
- // Check requirements before installation
131
- let requirementsReady = await this.configProvider.isRequirementsReady(this.categoryName, this.serverName);
132
- // If requirements are not ready, periodically check with timeout
87
+ // Check requirements
88
+ const requirementsReady = await this.checkRequirements(operationId, clientName, options);
133
89
  if (!requirementsReady) {
134
- const pendingStatus = {
135
- status: 'pending',
90
+ const failedStatus = {
91
+ status: 'failed',
136
92
  type: 'install',
137
93
  target: 'server',
138
- message: `Waiting for requirements to be ready for client: ${clientName}`,
139
- operationId: operationId
94
+ message: `Requirements not ready for client: ${clientName} after timeout`,
95
+ operationId
140
96
  };
141
- // Update status to pending with reference to configProvider
142
- await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, pendingStatus);
143
- // Set up periodic checking with timeout
144
- const startTime = Date.now();
145
- const timeoutMs = 5 * 60 * 1000; // 5 minutes in milliseconds
146
- const intervalMs = 5 * 1000; // 5 seconds in milliseconds
147
- while (!requirementsReady && (Date.now() - startTime) < timeoutMs) {
148
- // Wait for the interval
149
- await new Promise(resolve => setTimeout(resolve, intervalMs));
150
- // Check again
151
- requirementsReady = await this.configProvider.isRequirementsReady(this.categoryName, this.serverName);
152
- }
153
- // If still not ready after timeout, update status as failed and exit
154
- if (!requirementsReady) {
155
- const failedStatus = {
156
- status: 'failed',
157
- type: 'install',
158
- target: 'server',
159
- message: `Timed out waiting for requirements to be ready for client: ${clientName} after 5 minutes`,
160
- operationId: operationId
161
- };
162
- await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, failedStatus);
163
- return; // Exit the installation process
164
- }
97
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, failedStatus);
98
+ return;
99
+ }
100
+ // Create client-specific installer
101
+ const installer = ClientInstallerFactory.getInstaller(clientName);
102
+ if (!installer) {
103
+ throw new Error(`Failed to create installer for client: ${clientName}`);
104
+ }
105
+ const serverConfig = await this.configProvider.getServerMcpConfig(this.categoryName, this.serverName);
106
+ if (!serverConfig) {
107
+ throw new Error(`Server configuration not found for category: ${this.categoryName}, server: ${this.serverName}`);
165
108
  }
166
109
  // If we've reached here, requirements are ready - update status to in-progress
167
110
  const inProgressStatus = {
@@ -172,65 +115,11 @@ export class ClientInstaller {
172
115
  operationId: operationId
173
116
  };
174
117
  await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, inProgressStatus);
175
- // Get feed configuration for the server
176
- const feedConfiguration = await this.configProvider.getFeedConfiguration(this.categoryName);
177
- if (!feedConfiguration) {
178
- const errorStatus = {
179
- status: 'failed',
180
- type: 'install',
181
- target: 'server',
182
- message: `Failed to get feed configuration for category: ${this.categoryName}`,
183
- operationId: operationId
184
- };
185
- await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, errorStatus);
186
- return;
187
- }
188
- // Find the server config in the feed configuration
189
- const serverConfig = feedConfiguration.mcpServers.find(s => s.name === this.serverName);
190
- if (!serverConfig) {
191
- const errorStatus = {
192
- status: 'failed',
193
- type: 'install',
194
- target: 'server',
195
- message: `Server ${this.serverName} not found in feed configuration`,
196
- operationId: operationId
197
- };
198
- await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, errorStatus);
199
- return;
200
- }
201
- try {
202
- // Install extension if available
203
- if (SUPPORTED_CLIENTS[clientName]?.extension) {
204
- const extensionResult = await ExtensionInstaller.installExtension(clientName);
205
- if (!extensionResult) {
206
- Logger.debug(`Failed to install extension for client ${clientName}`);
207
- }
208
- }
209
- // Install client-specific configuration, passing options down
210
- const result = await this.installClientConfig(clientName, options, serverConfig, feedConfiguration);
211
- const finalStatus = {
212
- status: result.success ? 'completed' : 'failed',
213
- type: 'install',
214
- target: 'server',
215
- message: result.message || `Installation for client ${clientName}: ${result.success ? 'successful' : 'failed'}`,
216
- operationId: operationId,
217
- error: result.success ? undefined : result.message
218
- };
219
- await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, finalStatus);
220
- if (result.success) {
221
- await this.configProvider.reloadClientMCPSettings();
222
- }
223
- }
224
- catch (error) {
225
- const errorStatus = {
226
- status: 'failed',
227
- type: 'install',
228
- target: 'server',
229
- message: `Failed to install client: ${clientName}. Error: ${error instanceof Error ? error.message : String(error)}`,
230
- operationId: operationId,
231
- error: error instanceof Error ? error.message : String(error)
232
- };
233
- await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, errorStatus);
118
+ // Install client
119
+ const status = await installer.install(serverConfig, options);
120
+ await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, status);
121
+ if (status.status === 'completed') {
122
+ await this.configProvider.reloadClientMCPSettings();
234
123
  }
235
124
  }
236
125
  catch (error) {
@@ -238,366 +127,30 @@ export class ClientInstaller {
238
127
  status: 'failed',
239
128
  type: 'install',
240
129
  target: 'server',
241
- message: `Unexpected error in installation process for client: ${clientName}. Error: ${error instanceof Error ? error.message : String(error)}`,
242
- operationId: operationId,
130
+ message: `Error installing client ${clientName}: ${error instanceof Error ? error.message : String(error)}`,
131
+ operationId,
243
132
  error: error instanceof Error ? error.message : String(error)
244
133
  };
245
134
  await this.configProvider.updateServerOperationStatus(this.categoryName, this.serverName, clientName, errorStatus);
246
135
  }
247
136
  }
248
- // Modified to accept ServerInstallOptions
249
- async installClientConfig(clientName, options, // Use options directly
250
- serverConfig, feedConfig) {
251
- try {
252
- if (!SUPPORTED_CLIENTS[clientName]) {
253
- Logger.debug(`Client ${clientName} is not supported.`);
254
- return { success: false, message: `Unsupported client: ${clientName}` };
255
- }
256
- const clientSettings = SUPPORTED_CLIENTS[clientName];
257
- // Get both setting paths for VS Code and VS Code Insiders
258
- const regularSettingPath = clientSettings.codeSettingPath;
259
- const insidersSettingPath = clientSettings.codeInsiderSettingPath;
260
- Logger.debug(`Starting installation of ${this.serverName} for client ${clientName}`);
261
- Logger.debug(`VS Code settings path configured as: ${regularSettingPath}`);
262
- Logger.debug(`VS Code Insiders settings path configured as: ${insidersSettingPath}`);
263
- // Check if VS Code and VS Code Insiders are installed
264
- const isVSCodeInstalled = await this.isCommandAvailable('code');
265
- const isVSCodeInsidersInstalled = await this.isCommandAvailable('code-insiders');
266
- Logger.debug(isVSCodeInstalled ? 'VS Code detected on system' : 'VS Code not detected on system');
267
- Logger.debug(isVSCodeInsidersInstalled ? 'VS Code Insiders detected on system' : 'VS Code Insiders not detected on system');
268
- // If neither is installed, we can't proceed
269
- if (!isVSCodeInstalled && !isVSCodeInsidersInstalled) {
270
- Logger.debug('No VS Code installations detected on system. Cannot update settings.');
271
- return {
272
- success: false,
273
- message: `Neither VS Code nor VS Code Insiders are installed on this system. Cannot update settings for client: ${clientName}. Please install VS Code or VS Code Insiders and try again.`
274
- };
275
- }
276
- // --- Start of new logic ---
277
- // Clone the base installation configuration to avoid modifying the original serverConfig
278
- const installConfig = JSON.parse(JSON.stringify(serverConfig.installation));
279
- installConfig.mode = serverConfig.mode;
280
- const pythonEnv = options.settings?.pythonEnv;
281
- let pythonDir = null;
282
- // 1. Determine which args to use and resolve npm paths
283
- let finalArgs = [];
284
- if (options.args && options.args.length > 0) {
285
- Logger.debug(`Using args from ServerInstallOptions: ${options.args.join(' ')}`);
286
- finalArgs = options.args.map(arg => resolveNpmModulePath(arg));
287
- }
288
- else if (installConfig.args && installConfig.args.length > 0) {
289
- Logger.debug(`Using args from serverConfig.installation: ${installConfig.args.join(' ')}`);
290
- finalArgs = installConfig.args.map((arg) => resolveNpmModulePath(arg));
291
- }
292
- else {
293
- Logger.debug('No args found in options or serverConfig.installation.');
294
- finalArgs = [];
295
- }
296
- // 2. Handle pythonEnv settings
297
- if (pythonEnv) {
298
- // 2.1 If pythonEnv is set
299
- Logger.debug(`Python environment specified: ${pythonEnv}`);
300
- pythonDir = getPythonPackagePath(pythonEnv);
301
- // 2.1.1 Replace ${PYTHON_PACKAGE} in args
302
- if (pythonDir) {
303
- finalArgs = finalArgs.map(arg => arg.includes('${PYTHON_PACKAGE}') ? arg.replace('${PYTHON_PACKAGE}', pythonDir) : arg);
304
- Logger.debug(`Args after PYTHON_PACKAGE replacement (using pythonEnv): ${finalArgs.join(' ')}`);
305
- }
306
- else {
307
- Logger.debug(`Could not determine directory for pythonEnv: ${pythonEnv}`);
308
- }
309
- // 2.1.2 Replace command if it's 'python'
310
- if (installConfig.command === 'python') {
311
- Logger.debug(`Replacing command 'python' with specified pythonEnv: ${pythonEnv}`);
312
- installConfig.command = pythonEnv;
313
- }
314
- }
315
- else {
316
- // 2.2 If pythonEnv is not set
317
- Logger.debug('No Python environment specified in settings.');
318
- // 2.2.1 Replace ${PYTHON_PACKAGE} with system python directory if needed
319
- if (finalArgs.some(arg => arg.includes('${PYTHON_PACKAGE}'))) {
320
- Logger.debug('Attempting to find system Python directory for ${PYTHON_PACKAGE} replacement.');
321
- pythonDir = await getSystemPythonPackageDirectory();
322
- if (pythonDir) {
323
- finalArgs = finalArgs.map(arg => arg.includes('${PYTHON_PACKAGE}') ? arg.replace('${PYTHON_PACKAGE}', pythonDir) : arg);
324
- Logger.debug(`Args after PYTHON_PACKAGE replacement (using system python): ${finalArgs.join(' ')}`);
325
- }
326
- else {
327
- Logger.debug('Could not find system Python directory. ${PYTHON_PACKAGE} replacement skipped.');
328
- // Optionally, remove or handle the arg containing ${PYTHON_PACKAGE} if Python is required
329
- // finalArgs = finalArgs.filter(arg => !arg.includes('${PYTHON_PACKAGE}'));
330
- }
331
- }
332
- }
333
- // Update installConfig with potentially modified args
334
- installConfig.args = finalArgs;
335
- // 3. Handle environment variables (merge default, serverConfig, and options.env)
336
- const baseEnv = serverConfig.installation.env || {};
337
- const defaultEnv = {};
338
- for (const [key, config] of Object.entries(baseEnv)) {
339
- const envConfig = config; // Type assertion
340
- if (envConfig.Default) {
341
- defaultEnv[key] = envConfig.Default;
342
- }
343
- }
344
- // Merge: options.env overrides defaultEnv
345
- installConfig.env = { ...defaultEnv, ...(options.env || {}) };
346
- // Replace ${BROWSER_PATH} with actual browser path
347
- const replacements = Object.entries(installConfig.env)
348
- .filter(([_, value]) => typeof value === 'string' && value.includes('${BROWSER_PATH}'))
349
- .map(async ([key, value]) => {
350
- try {
351
- const browserPath = await GetBrowserPath();
352
- return [key, value.replace('${BROWSER_PATH}', browserPath)];
353
- }
354
- catch (error) {
355
- Logger.error(`Failed to get system browser path for env var ${key}:`, error);
356
- return [key, value];
357
- }
358
- });
359
- // Wait for all replacements to complete
360
- const replacedValues = await Promise.all(replacements);
361
- replacedValues.forEach(([key, value]) => {
362
- installConfig.env[key] = value;
363
- });
364
- Logger.debug(`Final environment variables: ${JSON.stringify(installConfig.env)}`);
365
- // --- End of new logic ---
366
- // Keep track of success for both installations
367
- let regularSuccess = false;
368
- let insidersSuccess = false;
369
- let errorMessages = [];
370
- // Update client-specific settings for both VS Code and VS Code Insiders
371
- if (clientName === 'MSRooCode' || clientName === 'Cline') {
372
- // Update VS Code settings if VS Code is installed
373
- if (isVSCodeInstalled) {
374
- try {
375
- Logger.debug(`Updating VS Code settings for ${clientName} at path: ${regularSettingPath}`);
376
- // Pass the modified installConfig
377
- await this.updateClineOrMSRooSettings(regularSettingPath, this.serverName, installConfig, clientName);
378
- regularSuccess = true;
379
- Logger.debug(`Settings successfully updated to ${regularSettingPath} for ${clientName} (VS Code)`);
380
- }
381
- catch (error) {
382
- const errorMsg = `Error updating VS Code settings: ${error instanceof Error ? error.message : String(error)}`;
383
- errorMessages.push(errorMsg);
384
- console.error(errorMsg);
385
- }
386
- }
387
- // Update VS Code Insiders settings if VS Code Insiders is installed
388
- if (isVSCodeInsidersInstalled) {
389
- try {
390
- Logger.debug(`Updating VS Code Insiders settings for ${clientName} at path: ${insidersSettingPath}`);
391
- // Pass the modified installConfig
392
- await this.updateClineOrMSRooSettings(insidersSettingPath, this.serverName, installConfig, clientName);
393
- insidersSuccess = true;
394
- Logger.debug(`Settings successfully updated to ${insidersSettingPath} for ${clientName} (VS Code Insiders)`);
395
- }
396
- catch (error) {
397
- const errorMsg = `Error updating VS Code Insiders settings: ${error instanceof Error ? error.message : String(error)}`;
398
- errorMessages.push(errorMsg);
399
- console.error(errorMsg);
400
- }
401
- }
402
- }
403
- else if (clientName === 'GithubCopilot') {
404
- // Update VS Code settings if VS Code is installed
405
- if (isVSCodeInstalled) {
406
- try {
407
- Logger.debug(`Updating VS Code settings for ${clientName} at path: ${regularSettingPath}`);
408
- // Pass the modified installConfig
409
- await this.updateGithubCopilotSettings(regularSettingPath, this.serverName, installConfig);
410
- regularSuccess = true;
411
- Logger.debug(`Settings successfully updated to ${regularSettingPath} for ${clientName} (VS Code)`);
412
- }
413
- catch (error) {
414
- const errorMsg = `Error updating VS Code settings: ${error instanceof Error ? error.message : String(error)}`;
415
- errorMessages.push(errorMsg);
416
- console.error(errorMsg);
417
- }
418
- }
419
- // Update VS Code Insiders settings if VS Code Insiders is installed
420
- if (isVSCodeInsidersInstalled) {
421
- try {
422
- Logger.debug(`Updating VS Code Insiders settings for ${clientName} at path: ${insidersSettingPath}`);
423
- // Pass the modified installConfig
424
- await this.updateGithubCopilotSettings(insidersSettingPath, this.serverName, installConfig);
425
- insidersSuccess = true;
426
- Logger.debug(`Settings successfully updated to ${insidersSettingPath} for ${clientName} (VS Code Insiders)`);
427
- }
428
- catch (error) {
429
- const errorMsg = `Error updating VS Code Insiders settings: ${error instanceof Error ? error.message : String(error)}`;
430
- errorMessages.push(errorMsg);
431
- console.error(errorMsg);
432
- }
433
- }
434
- }
435
- else {
436
- Logger.debug(`No implementation exists for updating settings for client: ${clientName}`);
437
- return {
438
- success: false,
439
- message: `Client ${clientName} is supported but no implementation exists for updating its settings`
440
- };
441
- }
442
- // Determine overall success status and message
443
- const overallSuccess = regularSuccess || insidersSuccess;
444
- let message = '';
445
- if (overallSuccess) {
446
- const successDetails = [];
447
- if (regularSuccess)
448
- successDetails.push('VS Code');
449
- if (insidersSuccess)
450
- successDetails.push('VS Code Insiders');
451
- // Create a more compact success message with specific paths
452
- const pathDetails = [];
453
- if (regularSuccess) {
454
- pathDetails.push(`\n[VS Code]: ${regularSettingPath}`);
455
- }
456
- if (insidersSuccess) {
457
- pathDetails.push(`\n[VS Code Insiders]: ${insidersSettingPath}`);
458
- }
459
- message = `Successfully installed ${this.serverName} for client: ${clientName}. ${pathDetails.join(' ')}`;
460
- // Add partial failure information if applicable
461
- if (errorMessages.length > 0) {
462
- message += `\nHowever, some errors occurred:\n${errorMessages.join('\n- ')}`;
463
- }
464
- Logger.debug(`Installation complete: ${message}`);
465
- }
466
- else {
467
- // Create a more detailed failure message that includes the detection results
468
- const detectionInfo = [];
469
- if (!isVSCodeInstalled)
470
- detectionInfo.push('VS Code not detected');
471
- if (!isVSCodeInsidersInstalled)
472
- detectionInfo.push('VS Code Insiders not detected');
473
- if (errorMessages.length > 0) {
474
- message = `Failed to install ${this.serverName} for client: ${clientName}.\nDetection status: [${detectionInfo.join(', ')}].\nErrors:\n- ${errorMessages.join('\n- ')}`;
475
- }
476
- else {
477
- message = `Failed to install ${this.serverName} for client: ${clientName}.\nDetection status: [${detectionInfo.join(', ')}]`;
478
- }
479
- console.error(`Installation failed: ${message}`);
480
- }
481
- return {
482
- success: overallSuccess,
483
- message: message
484
- };
485
- }
486
- catch (error) {
487
- const errorMsg = `Error installing client ${clientName}: ${error instanceof Error ? error.message : String(error)}`;
488
- console.error(errorMsg);
489
- return {
490
- success: false,
491
- message: errorMsg
492
- };
493
- }
494
- }
495
- async updateClineOrMSRooSettings(settingPath, serverName, installConfig, // Use the processed installConfig
496
- clientName) {
497
- // Read the Cline/MSRoo settings file
498
- const settings = await readJsonFile(settingPath, true);
499
- // Initialize mcpServers section if it doesn't exist
500
- if (!settings.mcpServers) {
501
- settings.mcpServers = {};
502
- }
503
- if (installConfig.mode === 'stdio') {
504
- // Special handling for Windows when command is npx for Cline and MSROO clients
505
- // Use a copy to avoid modifying the passed installConfig directly if needed elsewhere
506
- const serverConfigForClient = { ...installConfig };
507
- if (process.platform === 'win32' &&
508
- serverConfigForClient.command === 'npx' &&
509
- (clientName === 'Cline' || clientName === 'MSRooCode' || clientName === 'MSROO')) {
510
- // Update command to cmd
511
- serverConfigForClient.command = 'cmd';
512
- // Add /c and npx at the beginning of args
513
- serverConfigForClient.args = ['/c', 'npx', ...serverConfigForClient.args];
514
- // Add APPDATA environment variable pointing to npm directory
515
- if (!serverConfigForClient.env) {
516
- serverConfigForClient.env = {};
517
- }
518
- // Dynamically get npm path and set APPDATA to it
519
- const npmPath = await this.getNpmPath();
520
- serverConfigForClient.env['APPDATA'] = npmPath;
521
- Logger.debug(`Windows npx fix: command=${serverConfigForClient.command}, args=${serverConfigForClient.args.join(' ')}, env=${JSON.stringify(serverConfigForClient.env)}`);
522
- }
523
- // Convert backslashes to forward slashes in args paths
524
- if (serverConfigForClient.args) {
525
- serverConfigForClient.args = serverConfigForClient.args.map((arg) => typeof arg === 'string' ? arg.replace(/\\/g, '/') : arg);
526
- }
527
- // Add or update the server configuration
528
- settings.mcpServers[serverName] = {
529
- command: serverConfigForClient.command,
530
- args: serverConfigForClient.args,
531
- env: serverConfigForClient.env,
532
- autoApprove: [],
533
- disabled: false,
534
- alwaysAllow: []
535
- };
536
- Logger.debug(`Updating ${settingPath} for ${serverName}: ${JSON.stringify(settings.mcpServers[serverName])}`);
537
- }
538
- else if (installConfig.mode === 'sse') {
539
- // Handle SSE mode for Cline and MSRoo clients
540
- settings.mcpServers[serverName] = {
541
- type: 'sse',
542
- url: installConfig.url
543
- };
544
- }
545
- // Write the updated settings back to the file
546
- await writeJsonFile(settingPath, settings);
547
- }
548
- async updateGithubCopilotSettings(settingPath, serverName, installConfig // Use the processed installConfig
549
- ) {
550
- // Read the VS Code settings.json file
551
- const settings = await readJsonFile(settingPath, true);
552
- // Initialize the mcp section if it doesn't exist
553
- if (!settings.mcp) {
554
- settings.mcp = {
555
- servers: {},
556
- inputs: []
557
- };
558
- }
559
- if (!settings.mcp.servers) {
560
- settings.mcp.servers = {};
561
- }
562
- // Use a copy to avoid modifying the passed installConfig directly
563
- const serverConfigForClient = { ...installConfig };
564
- if (installConfig.mode === 'stdio') {
565
- if (serverConfigForClient.args) {
566
- serverConfigForClient.args = serverConfigForClient.args.map((arg) => typeof arg === 'string' ? arg.replace(/\\/g, '/') : arg);
567
- }
568
- // Add or update the server configuration
569
- settings.mcp.servers[serverName] = {
570
- command: serverConfigForClient.command,
571
- args: serverConfigForClient.args,
572
- env: serverConfigForClient.env
573
- };
574
- Logger.debug(`Updating ${settingPath} for ${serverName}: ${JSON.stringify(settings.mcp.servers[serverName])}`);
575
- }
576
- else if (installConfig.mode === 'sse') {
577
- // Handle SSE mode for Github Copilot
578
- settings.mcp.servers[serverName] = {
579
- type: 'sse',
580
- url: installConfig.url
581
- };
582
- }
583
- // Write the updated settings back to the file
584
- await writeJsonFile(settingPath, settings);
585
- }
137
+ /**
138
+ * Install all specified clients
139
+ */
586
140
  async install(options) {
587
141
  const initialStatuses = [];
588
- // Start installation for each client asynchronously and collect initial statuses
589
- // Pass options down to installClient
142
+ // Start installation for each client asynchronously
590
143
  const installPromises = this.clients.map(async (clientName) => {
591
- const initialStatus = await this.installClient(clientName, options);
592
- initialStatuses.push(initialStatus);
593
- return initialStatus;
144
+ const status = await this.installClient(clientName, options);
145
+ initialStatuses.push(status);
146
+ return status;
594
147
  });
595
- // Wait for all initial statuses (but actual installation continues asynchronously)
148
+ // Wait for all installations to complete
596
149
  await Promise.all(installPromises);
597
- // Return initial result showing installations have been initiated
150
+ // Return result
598
151
  return {
599
152
  success: true,
600
- message: 'Client installations initiated successfully',
153
+ message: 'Client installations completed',
601
154
  status: initialStatuses
602
155
  };
603
156
  }