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.
- package/dist/core/ConfigurationProvider.d.ts +1 -0
- package/dist/core/ConfigurationProvider.js +15 -0
- package/dist/core/InstallationService.js +2 -7
- package/dist/core/MCPManager.d.ts +11 -2
- package/dist/core/MCPManager.js +24 -1
- package/dist/core/RequirementService.js +2 -8
- package/dist/core/installers/clients/BaseClientInstaller.d.ts +51 -0
- package/dist/core/installers/clients/BaseClientInstaller.js +160 -0
- package/dist/core/installers/clients/ClientInstaller.d.ts +16 -9
- package/dist/core/installers/clients/ClientInstaller.js +80 -527
- package/dist/core/installers/clients/ClientInstallerFactory.d.ts +20 -0
- package/dist/core/installers/clients/ClientInstallerFactory.js +37 -0
- package/dist/core/installers/clients/ClineInstaller.d.ts +18 -0
- package/dist/core/installers/clients/ClineInstaller.js +124 -0
- package/dist/core/installers/clients/GithubCopilotInstaller.d.ts +34 -0
- package/dist/core/installers/clients/GithubCopilotInstaller.js +162 -0
- package/dist/core/installers/clients/MSRooCodeInstaller.d.ts +15 -0
- package/dist/core/installers/clients/MSRooCodeInstaller.js +122 -0
- package/dist/core/installers/requirements/BaseInstaller.d.ts +11 -34
- package/dist/core/installers/requirements/BaseInstaller.js +5 -116
- package/dist/core/installers/requirements/CommandInstaller.d.ts +6 -1
- package/dist/core/installers/requirements/CommandInstaller.js +7 -0
- package/dist/core/installers/requirements/GeneralInstaller.d.ts +6 -1
- package/dist/core/installers/requirements/GeneralInstaller.js +9 -4
- package/dist/core/installers/requirements/NpmInstaller.d.ts +46 -7
- package/dist/core/installers/requirements/NpmInstaller.js +150 -58
- package/dist/core/installers/requirements/PipInstaller.d.ts +9 -0
- package/dist/core/installers/requirements/PipInstaller.js +66 -28
- package/dist/core/onboard/FeedOnboardService.d.ts +50 -13
- package/dist/core/onboard/FeedOnboardService.js +263 -88
- package/dist/core/onboard/OnboardProcessor.d.ts +79 -0
- package/dist/core/onboard/OnboardProcessor.js +290 -0
- package/dist/core/onboard/OnboardStatus.d.ts +49 -0
- package/dist/core/onboard/OnboardStatus.js +10 -0
- package/dist/core/onboard/OnboardStatusManager.d.ts +57 -0
- package/dist/core/onboard/OnboardStatusManager.js +176 -0
- package/dist/core/types.d.ts +4 -5
- package/dist/core/validators/FeedValidator.d.ts +8 -1
- package/dist/core/validators/FeedValidator.js +60 -7
- package/dist/core/validators/IServerValidator.d.ts +19 -0
- package/dist/core/validators/IServerValidator.js +2 -0
- package/dist/core/validators/SSEServerValidator.d.ts +15 -0
- package/dist/core/validators/SSEServerValidator.js +39 -0
- package/dist/core/validators/ServerValidatorFactory.d.ts +24 -0
- package/dist/core/validators/ServerValidatorFactory.js +45 -0
- package/dist/core/validators/StdioServerValidator.d.ts +46 -0
- package/dist/core/validators/StdioServerValidator.js +229 -0
- package/dist/services/InstallRequestValidator.d.ts +1 -1
- package/dist/services/ServerService.d.ts +9 -6
- package/dist/services/ServerService.js +18 -7
- package/dist/utils/adoUtils.d.ts +29 -0
- package/dist/utils/adoUtils.js +252 -0
- package/dist/utils/clientUtils.d.ts +0 -7
- package/dist/utils/clientUtils.js +0 -42
- package/dist/utils/githubUtils.d.ts +10 -0
- package/dist/utils/githubUtils.js +22 -0
- package/dist/utils/macroExpressionUtils.d.ts +38 -0
- package/dist/utils/macroExpressionUtils.js +116 -0
- package/dist/utils/osUtils.d.ts +4 -20
- package/dist/utils/osUtils.js +78 -23
- package/dist/web/contract/serverContract.d.ts +3 -1
- package/dist/web/public/css/notifications.css +48 -17
- package/dist/web/public/css/onboard.css +66 -3
- package/dist/web/public/index.html +84 -16
- package/dist/web/public/js/api.js +3 -6
- package/dist/web/public/js/flights/flights.js +127 -0
- package/dist/web/public/js/modal/installation.js +5 -5
- package/dist/web/public/js/modal/modalSetup.js +3 -2
- package/dist/web/public/js/notifications.js +66 -27
- package/dist/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +338 -0
- package/dist/web/public/js/onboard/formProcessor.js +810 -255
- package/dist/web/public/js/onboard/index.js +328 -85
- package/dist/web/public/js/onboard/publishHandler.js +132 -0
- package/dist/web/public/js/onboard/state.js +61 -17
- package/dist/web/public/js/onboard/templates.js +217 -249
- package/dist/web/public/js/onboard/uiHandlers.js +679 -117
- package/dist/web/public/js/onboard/validationHandlers.js +378 -0
- package/dist/web/public/js/serverCategoryList.js +15 -2
- package/dist/web/public/onboard.html +191 -45
- package/dist/web/public/styles.css +91 -1
- package/dist/web/server.d.ts +0 -10
- package/dist/web/server.js +131 -22
- package/package.json +2 -2
- package/src/core/ConfigurationProvider.ts +15 -0
- package/src/core/InstallationService.ts +2 -7
- package/src/core/MCPManager.ts +26 -1
- package/src/core/RequirementService.ts +2 -9
- package/src/core/installers/clients/BaseClientInstaller.ts +196 -0
- package/src/core/installers/clients/ClientInstaller.ts +97 -608
- package/src/core/installers/clients/ClientInstallerFactory.ts +43 -0
- package/src/core/installers/clients/ClineInstaller.ts +135 -0
- package/src/core/installers/clients/GithubCopilotInstaller.ts +179 -0
- package/src/core/installers/clients/MSRooCodeInstaller.ts +133 -0
- package/src/core/installers/requirements/BaseInstaller.ts +13 -136
- package/src/core/installers/requirements/CommandInstaller.ts +9 -1
- package/src/core/installers/requirements/GeneralInstaller.ts +11 -4
- package/src/core/installers/requirements/NpmInstaller.ts +178 -61
- package/src/core/installers/requirements/PipInstaller.ts +68 -29
- package/src/core/onboard/FeedOnboardService.ts +346 -0
- package/src/core/onboard/OnboardProcessor.ts +305 -0
- package/src/core/onboard/OnboardStatus.ts +55 -0
- package/src/core/onboard/OnboardStatusManager.ts +188 -0
- package/src/core/types.ts +4 -5
- package/src/core/validators/FeedValidator.ts +79 -0
- package/src/core/validators/IServerValidator.ts +21 -0
- package/src/core/validators/SSEServerValidator.ts +43 -0
- package/src/core/validators/ServerValidatorFactory.ts +51 -0
- package/src/core/validators/StdioServerValidator.ts +259 -0
- package/src/services/InstallRequestValidator.ts +1 -1
- package/src/services/ServerService.ts +22 -7
- package/src/utils/adoUtils.ts +291 -0
- package/src/utils/clientUtils.ts +0 -44
- package/src/utils/githubUtils.ts +24 -0
- package/src/utils/macroExpressionUtils.ts +121 -0
- package/src/utils/osUtils.ts +89 -24
- package/src/web/contract/serverContract.ts +74 -0
- package/src/web/public/css/notifications.css +48 -17
- package/src/web/public/css/onboard.css +107 -0
- package/src/web/public/index.html +84 -16
- package/src/web/public/js/api.js +3 -6
- package/src/web/public/js/flights/flights.js +127 -0
- package/src/web/public/js/modal/installation.js +5 -5
- package/src/web/public/js/modal/modalSetup.js +3 -2
- package/src/web/public/js/notifications.js +66 -27
- package/src/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +338 -0
- package/src/web/public/js/onboard/formProcessor.js +864 -0
- package/src/web/public/js/onboard/index.js +374 -0
- package/src/web/public/js/onboard/publishHandler.js +132 -0
- package/src/web/public/js/onboard/state.js +76 -0
- package/src/web/public/js/onboard/templates.js +343 -0
- package/src/web/public/js/onboard/uiHandlers.js +758 -0
- package/src/web/public/js/onboard/validationHandlers.js +378 -0
- package/src/web/public/js/serverCategoryList.js +15 -2
- package/src/web/public/onboard.html +296 -0
- package/src/web/public/styles.css +91 -1
- 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 {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
43
|
-
*
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
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 (!
|
|
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
|
|
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
|
|
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
|
-
|
|
130
|
-
|
|
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
|
|
135
|
-
status: '
|
|
90
|
+
const failedStatus = {
|
|
91
|
+
status: 'failed',
|
|
136
92
|
type: 'install',
|
|
137
93
|
target: 'server',
|
|
138
|
-
message: `
|
|
139
|
-
operationId
|
|
94
|
+
message: `Requirements not ready for client: ${clientName} after timeout`,
|
|
95
|
+
operationId
|
|
140
96
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
//
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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: `
|
|
242
|
-
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
|
589
|
-
// Pass options down to installClient
|
|
142
|
+
// Start installation for each client asynchronously
|
|
590
143
|
const installPromises = this.clients.map(async (clientName) => {
|
|
591
|
-
const
|
|
592
|
-
initialStatuses.push(
|
|
593
|
-
return
|
|
144
|
+
const status = await this.installClient(clientName, options);
|
|
145
|
+
initialStatuses.push(status);
|
|
146
|
+
return status;
|
|
594
147
|
});
|
|
595
|
-
// Wait for all
|
|
148
|
+
// Wait for all installations to complete
|
|
596
149
|
await Promise.all(installPromises);
|
|
597
|
-
// Return
|
|
150
|
+
// Return result
|
|
598
151
|
return {
|
|
599
152
|
success: true,
|
|
600
|
-
message: 'Client installations
|
|
153
|
+
message: 'Client installations completed',
|
|
601
154
|
status: initialStatuses
|
|
602
155
|
};
|
|
603
156
|
}
|