imcp 0.0.16 → 0.0.18
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/cli/commands/install.js +2 -2
- package/dist/cli/commands/list.js +2 -2
- package/dist/cli/commands/serve.js +3 -2
- package/dist/core/RequirementService.d.ts +0 -12
- package/dist/core/RequirementService.js +0 -24
- package/dist/core/installers/clients/BaseClientInstaller.d.ts +26 -3
- package/dist/core/installers/clients/BaseClientInstaller.js +121 -0
- package/dist/core/installers/clients/ClientInstaller.d.ts +1 -1
- package/dist/core/installers/clients/ClientInstaller.js +1 -1
- package/dist/core/installers/clients/ClientInstallerFactory.js +1 -1
- package/dist/core/installers/clients/ClineInstaller.d.ts +1 -6
- package/dist/core/installers/clients/ClineInstaller.js +1 -94
- package/dist/core/installers/clients/ExtensionInstaller.js +1 -1
- package/dist/core/installers/clients/GithubCopilotInstaller.d.ts +1 -6
- package/dist/core/installers/clients/GithubCopilotInstaller.js +1 -94
- package/dist/core/installers/clients/MSRooCodeInstaller.d.ts +1 -5
- package/dist/core/installers/clients/MSRooCodeInstaller.js +1 -94
- package/dist/core/installers/requirements/BaseInstaller.d.ts +1 -1
- package/dist/core/installers/requirements/BaseInstaller.js +1 -1
- package/dist/core/installers/requirements/CommandInstaller.d.ts +1 -1
- package/dist/core/installers/requirements/CommandInstaller.js +1 -1
- package/dist/core/installers/requirements/GeneralInstaller.d.ts +1 -1
- package/dist/core/installers/requirements/InstallerFactory.d.ts +1 -1
- package/dist/core/installers/requirements/NpmInstaller.d.ts +1 -1
- package/dist/core/installers/requirements/NpmInstaller.js +1 -1
- package/dist/core/installers/requirements/PipInstaller.d.ts +1 -1
- package/dist/core/installers/requirements/RequirementInstaller.d.ts +1 -1
- package/dist/core/loaders/ConfigurationLoader.d.ts +35 -0
- package/dist/core/loaders/ConfigurationLoader.js +257 -0
- package/dist/core/loaders/ConfigurationProvider.d.ts +38 -0
- package/dist/core/loaders/ConfigurationProvider.js +384 -0
- package/dist/core/loaders/ServerSchemaLoader.d.ts +22 -0
- package/dist/core/loaders/ServerSchemaLoader.js +109 -0
- package/dist/core/loaders/ServerSchemaProvider.d.ts +14 -0
- package/dist/core/loaders/ServerSchemaProvider.js +90 -0
- package/dist/core/metadatas/constants.d.ts +47 -0
- package/dist/core/metadatas/constants.js +94 -0
- package/dist/core/metadatas/types.d.ts +167 -0
- package/dist/core/metadatas/types.js +16 -0
- package/dist/core/onboard/FeedOnboardService.d.ts +15 -8
- package/dist/core/onboard/FeedOnboardService.js +215 -130
- package/dist/core/onboard/OnboardProcessor.d.ts +8 -2
- package/dist/core/onboard/OnboardProcessor.js +53 -9
- package/dist/core/onboard/OnboardStatus.d.ts +7 -2
- package/dist/core/onboard/OnboardStatusManager.d.ts +71 -25
- package/dist/core/onboard/OnboardStatusManager.js +231 -47
- package/dist/core/validators/FeedValidator.d.ts +8 -3
- package/dist/core/validators/FeedValidator.js +61 -7
- package/dist/core/validators/IServerValidator.d.ts +1 -1
- package/dist/core/validators/SSEServerValidator.d.ts +1 -1
- package/dist/core/validators/ServerValidatorFactory.d.ts +1 -1
- package/dist/core/validators/StdioServerValidator.d.ts +1 -1
- package/dist/core/validators/StdioServerValidator.js +85 -33
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/services/InstallationService.d.ts +50 -0
- package/dist/services/InstallationService.js +350 -0
- package/dist/services/MCPManager.d.ts +29 -0
- package/dist/services/MCPManager.js +192 -0
- package/dist/services/RequirementService.d.ts +40 -0
- package/dist/services/RequirementService.js +110 -0
- package/dist/services/ServerService.d.ts +2 -2
- package/dist/services/ServerService.js +6 -6
- package/dist/utils/adoUtils.d.ts +2 -2
- package/dist/utils/adoUtils.js +1 -1
- package/dist/utils/feedUtils.js +1 -1
- package/dist/utils/githubUtils.d.ts +1 -1
- package/dist/utils/githubUtils.js +1 -1
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.js +11 -1
- package/dist/utils/macroExpressionUtils.d.ts +1 -1
- package/dist/utils/osUtils.d.ts +1 -1
- package/dist/utils/osUtils.js +1 -1
- package/dist/web/contract/serverContract.d.ts +1 -1
- package/dist/web/public/index.html +1 -3
- package/dist/web/public/js/api.js +2 -80
- package/dist/web/public/js/modal/installation.js +1 -1
- package/dist/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +41 -9
- package/dist/web/public/js/onboard/formProcessor.js +200 -34
- package/dist/web/public/js/onboard/index.js +2 -2
- package/dist/web/public/js/onboard/publishHandler.js +30 -22
- package/dist/web/public/js/onboard/templates.js +34 -40
- package/dist/web/public/js/onboard/uiHandlers.js +175 -84
- package/dist/web/public/js/onboard/validationHandlers.js +147 -64
- package/dist/web/public/js/serverCategoryDetails.js +19 -4
- package/dist/web/public/js/serverCategoryList.js +13 -1
- package/dist/web/public/onboard.html +1 -1
- package/dist/web/server.js +21 -8
- package/package.json +1 -1
- package/src/cli/commands/install.ts +3 -3
- package/src/cli/commands/list.ts +2 -2
- package/src/cli/commands/serve.ts +3 -2
- package/src/cli/index.ts +1 -1
- package/src/core/installers/clients/BaseClientInstaller.ts +134 -3
- package/src/core/installers/clients/ClientInstaller.ts +3 -3
- package/src/core/installers/clients/ClientInstallerFactory.ts +1 -1
- package/src/core/installers/clients/ClineInstaller.ts +1 -101
- package/src/core/installers/clients/ExtensionInstaller.ts +1 -1
- package/src/core/installers/clients/GithubCopilotInstaller.ts +1 -101
- package/src/core/installers/clients/MSRooCodeInstaller.ts +1 -102
- package/src/core/installers/requirements/BaseInstaller.ts +2 -2
- package/src/core/installers/requirements/CommandInstaller.ts +1 -1
- package/src/core/installers/requirements/GeneralInstaller.ts +1 -1
- package/src/core/installers/requirements/InstallerFactory.ts +1 -1
- package/src/core/installers/requirements/NpmInstaller.ts +12 -12
- package/src/core/installers/requirements/PipInstaller.ts +1 -1
- package/src/core/installers/requirements/RequirementInstaller.ts +1 -1
- package/src/core/{ConfigurationLoader.ts → loaders/ConfigurationLoader.ts} +31 -7
- package/src/core/{ConfigurationProvider.ts → loaders/ConfigurationProvider.ts} +18 -10
- package/src/core/loaders/ServerSchemaLoader.ts +117 -0
- package/src/core/loaders/ServerSchemaProvider.ts +99 -0
- package/src/core/{types.ts → metadatas/types.ts} +3 -2
- package/src/core/onboard/FeedOnboardService.ts +270 -146
- package/src/core/onboard/OnboardProcessor.ts +60 -11
- package/src/core/onboard/OnboardStatus.ts +7 -2
- package/src/core/onboard/OnboardStatusManager.ts +270 -43
- package/src/core/validators/FeedValidator.ts +65 -9
- package/src/core/validators/IServerValidator.ts +1 -1
- package/src/core/validators/SSEServerValidator.ts +2 -2
- package/src/core/validators/ServerValidatorFactory.ts +1 -1
- package/src/core/validators/StdioServerValidator.ts +86 -34
- package/src/index.ts +3 -3
- package/src/{core → services}/InstallationService.ts +5 -5
- package/src/{core → services}/MCPManager.ts +10 -5
- package/src/{core → services}/RequirementService.ts +2 -31
- package/src/services/ServerService.ts +7 -7
- package/src/utils/adoUtils.ts +3 -3
- package/src/utils/feedUtils.ts +2 -2
- package/src/utils/githubUtils.ts +2 -2
- package/src/utils/logger.ts +13 -1
- package/src/utils/macroExpressionUtils.ts +1 -1
- package/src/utils/osUtils.ts +4 -4
- package/src/web/contract/serverContract.ts +2 -2
- package/src/web/public/index.html +1 -3
- package/src/web/public/js/api.js +2 -80
- package/src/web/public/js/modal/installation.js +1 -1
- package/src/web/public/js/onboard/ONBOARDING_PAGE_DESIGN.md +41 -9
- package/src/web/public/js/onboard/formProcessor.js +200 -34
- package/src/web/public/js/onboard/index.js +2 -2
- package/src/web/public/js/onboard/publishHandler.js +30 -22
- package/src/web/public/js/onboard/templates.js +34 -40
- package/src/web/public/js/onboard/uiHandlers.js +175 -84
- package/src/web/public/js/onboard/validationHandlers.js +147 -64
- package/src/web/public/js/serverCategoryDetails.js +19 -4
- package/src/web/public/js/serverCategoryList.js +13 -1
- package/src/web/public/onboard.html +1 -1
- package/src/web/server.ts +30 -14
- package/src/core/ServerSchemaLoader.ts +0 -48
- package/src/core/ServerSchemaProvider.ts +0 -137
- package/src/services/InstallRequestValidator.ts +0 -112
- /package/src/core/{constants.ts → metadatas/constants.ts} +0 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { exec } from 'child_process';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { GITHUB_REPO, LOCAL_FEEDS_DIR, SETTINGS_DIR, SUPPORTED_CLIENTS } from '../metadatas/constants.js';
|
|
7
|
+
import { Logger } from '../../utils/logger.js';
|
|
8
|
+
import { checkGithubAuth } from '../../utils/githubAuth.js';
|
|
9
|
+
import { ConfigurationLoader } from './ConfigurationLoader.js';
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
export class ConfigurationProvider {
|
|
13
|
+
static instance;
|
|
14
|
+
configPath;
|
|
15
|
+
configuration;
|
|
16
|
+
configLock = Promise.resolve();
|
|
17
|
+
tempDir;
|
|
18
|
+
constructor() {
|
|
19
|
+
// Initialize configuration in user's appdata/imcp directory
|
|
20
|
+
this.configPath = path.join(SETTINGS_DIR, 'configurations.json');
|
|
21
|
+
this.configuration = {
|
|
22
|
+
localServerCategories: [],
|
|
23
|
+
feeds: {},
|
|
24
|
+
clientMCPSettings: {}
|
|
25
|
+
};
|
|
26
|
+
this.tempDir = path.join(LOCAL_FEEDS_DIR, '../temp');
|
|
27
|
+
}
|
|
28
|
+
static getInstance() {
|
|
29
|
+
if (!ConfigurationProvider.instance) {
|
|
30
|
+
ConfigurationProvider.instance = new ConfigurationProvider();
|
|
31
|
+
}
|
|
32
|
+
return ConfigurationProvider.instance;
|
|
33
|
+
}
|
|
34
|
+
async withLock(operation) {
|
|
35
|
+
const current = this.configLock;
|
|
36
|
+
let resolve;
|
|
37
|
+
this.configLock = new Promise(r => resolve = r);
|
|
38
|
+
try {
|
|
39
|
+
await current;
|
|
40
|
+
return await operation();
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
resolve();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async initialize(feedFile, settings) {
|
|
47
|
+
await this.withLock(async () => {
|
|
48
|
+
const configDir = path.dirname(this.configPath);
|
|
49
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
50
|
+
// remove the old configuration file if it exists
|
|
51
|
+
try {
|
|
52
|
+
await fs.rm(this.configPath, { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error.code !== 'ENOENT') {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
try {
|
|
61
|
+
const config = JSON.parse(await fs.readFile(this.configPath, 'utf8'));
|
|
62
|
+
this.configuration = config;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error.code !== 'ENOENT') {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
// File doesn't exist, use default empty configuration
|
|
69
|
+
await this.saveConfiguration();
|
|
70
|
+
}
|
|
71
|
+
// Always load feeds and client settings, whether file existed or not
|
|
72
|
+
await this.loadFeedsIntoConfiguration(feedFile, settings);
|
|
73
|
+
await this.loadClientMCPSettings();
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
Logger.error('Error during initialization', error);
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async saveConfiguration() {
|
|
82
|
+
const configDir = path.dirname(this.configPath);
|
|
83
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
84
|
+
await fs.writeFile(this.configPath, JSON.stringify(this.configuration, null, 2));
|
|
85
|
+
}
|
|
86
|
+
async getServerCategories() {
|
|
87
|
+
return await this.withLock(async () => {
|
|
88
|
+
return this.configuration.localServerCategories;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async getServerCategory(categoryName) {
|
|
92
|
+
return await this.withLock(async () => {
|
|
93
|
+
return this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async getClientMcpSettings() {
|
|
97
|
+
return await this.withLock(async () => {
|
|
98
|
+
return this.configuration.clientMCPSettings;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async getFeedConfiguration(categoryName) {
|
|
102
|
+
return await this.withLock(async () => {
|
|
103
|
+
return this.configuration.feeds[categoryName];
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async getServerMcpConfig(categoryName, serverName) {
|
|
107
|
+
return await this.withLock(async () => {
|
|
108
|
+
return this.configuration.feeds[categoryName]?.mcpServers.find(s => s.name === serverName);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async getInstallationStatus(categoryName) {
|
|
112
|
+
return await this.withLock(async () => {
|
|
113
|
+
// Inline getServerCategory logic
|
|
114
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
115
|
+
return category?.installationStatus;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async getServerStatus(categoryName, serverName) {
|
|
119
|
+
return await this.withLock(async () => {
|
|
120
|
+
// Inline getInstallationStatus logic
|
|
121
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
122
|
+
const status = category?.installationStatus;
|
|
123
|
+
return status?.serversStatus[serverName];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async getRequirementStatus(categoryName, requirementName) {
|
|
127
|
+
return await this.withLock(async () => {
|
|
128
|
+
// Inline getInstallationStatus logic
|
|
129
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
130
|
+
const status = category?.installationStatus;
|
|
131
|
+
return status?.requirementsStatus[requirementName];
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async updateInstallationStatus(categoryName, requirementStatus, serverStatus) {
|
|
135
|
+
return await this.withLock(async () => {
|
|
136
|
+
// Inline getServerCategory logic
|
|
137
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
138
|
+
if (!category)
|
|
139
|
+
return false;
|
|
140
|
+
if (!category.installationStatus) {
|
|
141
|
+
category.installationStatus = {
|
|
142
|
+
requirementsStatus: {},
|
|
143
|
+
serversStatus: {},
|
|
144
|
+
lastUpdated: new Date().toISOString()
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
category.installationStatus.requirementsStatus = {
|
|
148
|
+
...category.installationStatus.requirementsStatus,
|
|
149
|
+
...requirementStatus
|
|
150
|
+
};
|
|
151
|
+
category.installationStatus.serversStatus = {
|
|
152
|
+
...category.installationStatus.serversStatus,
|
|
153
|
+
...serverStatus
|
|
154
|
+
};
|
|
155
|
+
category.installationStatus.lastUpdated = new Date().toISOString();
|
|
156
|
+
await this.saveConfiguration();
|
|
157
|
+
return true;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async updateRequirementStatus(categoryName, requirementName, status) {
|
|
161
|
+
return await this.withLock(async () => {
|
|
162
|
+
// Inline getServerCategory logic
|
|
163
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
164
|
+
if (!category?.installationStatus)
|
|
165
|
+
return false;
|
|
166
|
+
category.installationStatus.requirementsStatus[requirementName] = status;
|
|
167
|
+
category.installationStatus.lastUpdated = new Date().toISOString();
|
|
168
|
+
await this.saveConfiguration();
|
|
169
|
+
return true;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async updateRequirementOperationStatus(categoryName, requirementName, operationStatus) {
|
|
173
|
+
return await this.withLock(async () => {
|
|
174
|
+
// Inline getServerCategory logic
|
|
175
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
176
|
+
if (!category?.installationStatus?.requirementsStatus[requirementName])
|
|
177
|
+
return false;
|
|
178
|
+
category.installationStatus.requirementsStatus[requirementName].operationStatus = operationStatus;
|
|
179
|
+
category.installationStatus.lastUpdated = new Date().toISOString();
|
|
180
|
+
await this.saveConfiguration();
|
|
181
|
+
return true;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async updateServerStatus(categoryName, serverName, status) {
|
|
185
|
+
return await this.withLock(async () => {
|
|
186
|
+
// Inline getServerCategory logic
|
|
187
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
188
|
+
if (!category?.installationStatus)
|
|
189
|
+
return false;
|
|
190
|
+
category.installationStatus.serversStatus[serverName] = status;
|
|
191
|
+
category.installationStatus.lastUpdated = new Date().toISOString();
|
|
192
|
+
await this.saveConfiguration();
|
|
193
|
+
return true;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async updateServerOperationStatus(categoryName, serverName, clientName, operationStatus) {
|
|
197
|
+
return await this.withLock(async () => {
|
|
198
|
+
// Inline getServerCategory logic
|
|
199
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
200
|
+
if (!category?.installationStatus?.serversStatus[serverName])
|
|
201
|
+
return false;
|
|
202
|
+
category.installationStatus.serversStatus[serverName].installedStatus[clientName] = operationStatus;
|
|
203
|
+
category.installationStatus.lastUpdated = new Date().toISOString();
|
|
204
|
+
await this.saveConfiguration();
|
|
205
|
+
return true;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
async isRequirementsReady(categoryName, serverName) {
|
|
209
|
+
return await this.withLock(async () => {
|
|
210
|
+
// Inline getServerCategory logic
|
|
211
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
212
|
+
if (!category?.feedConfiguration)
|
|
213
|
+
return false;
|
|
214
|
+
const serverConfig = category.feedConfiguration.mcpServers.find(s => s.name === serverName);
|
|
215
|
+
if (!serverConfig?.dependencies?.requirements)
|
|
216
|
+
return true; // No requirements means ready
|
|
217
|
+
const requirementNames = serverConfig.dependencies.requirements.map(r => r.name);
|
|
218
|
+
// Inline getInstallationStatus logic (using the already fetched category)
|
|
219
|
+
const status = category?.installationStatus;
|
|
220
|
+
if (!status?.requirementsStatus)
|
|
221
|
+
return false;
|
|
222
|
+
return requirementNames.every(name => {
|
|
223
|
+
const reqStatus = status.requirementsStatus[name];
|
|
224
|
+
return reqStatus?.installed && !reqStatus?.error;
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
async GetServerRequirementStatus(categoryName, serverName) {
|
|
229
|
+
return await this.withLock(async () => {
|
|
230
|
+
// Inline getServerCategory logic
|
|
231
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
232
|
+
if (!category?.feedConfiguration)
|
|
233
|
+
return [];
|
|
234
|
+
const serverConfig = category.feedConfiguration.mcpServers.find(s => s.name === serverName);
|
|
235
|
+
if (!serverConfig?.dependencies?.requirements)
|
|
236
|
+
return [];
|
|
237
|
+
const requirementNames = serverConfig.dependencies.requirements.map(r => r.name);
|
|
238
|
+
return requirementNames
|
|
239
|
+
.map(name => category?.installationStatus?.requirementsStatus[name])
|
|
240
|
+
.filter(x => x !== undefined);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
async isServerReady(categoryName, serverName, clients) {
|
|
244
|
+
return await this.withLock(async () => {
|
|
245
|
+
// Inline the logic from getServerStatus and getInstallationStatus to avoid nested lock
|
|
246
|
+
const category = this.configuration.localServerCategories.find(s => s.name === categoryName);
|
|
247
|
+
const installationStatus = category?.installationStatus;
|
|
248
|
+
const serverStatus = installationStatus?.serversStatus[serverName];
|
|
249
|
+
if (!serverStatus)
|
|
250
|
+
return false;
|
|
251
|
+
return clients.every(clientName => {
|
|
252
|
+
// Add optional chaining for safety in case installedStatus is missing
|
|
253
|
+
const clientStatus = serverStatus.installedStatus?.[clientName];
|
|
254
|
+
return clientStatus?.status === 'completed' && !clientStatus?.error;
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
async syncFeeds() {
|
|
259
|
+
return await this.withLock(async () => {
|
|
260
|
+
Logger.log('Starting feed synchronization...');
|
|
261
|
+
try {
|
|
262
|
+
// Check GitHub authentication first
|
|
263
|
+
await checkGithubAuth();
|
|
264
|
+
Logger.debug({
|
|
265
|
+
action: 'create_directories',
|
|
266
|
+
paths: {
|
|
267
|
+
localFeeds: LOCAL_FEEDS_DIR,
|
|
268
|
+
tempDir: this.tempDir
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
await fs.mkdir(LOCAL_FEEDS_DIR, { recursive: true });
|
|
272
|
+
await fs.mkdir(this.tempDir, { recursive: true });
|
|
273
|
+
// Clean up temp directory
|
|
274
|
+
await fs.rm(this.tempDir, { recursive: true, force: true });
|
|
275
|
+
// Download latest release
|
|
276
|
+
Logger.debug('Downloading latest release...');
|
|
277
|
+
const { downloadGithubRelease } = await import('../../utils/githubUtils.js');
|
|
278
|
+
const { version, downloadPath } = await downloadGithubRelease(GITHUB_REPO.repoName, 'latest', GITHUB_REPO.feedAssetsName, undefined, true, this.tempDir);
|
|
279
|
+
Logger.debug({
|
|
280
|
+
action: 'download_release',
|
|
281
|
+
downloadPath,
|
|
282
|
+
version,
|
|
283
|
+
repoName: GITHUB_REPO.repoName,
|
|
284
|
+
});
|
|
285
|
+
Logger.debug('Updating local feeds...');
|
|
286
|
+
await fs.rm(LOCAL_FEEDS_DIR, { recursive: true, force: true });
|
|
287
|
+
const sourceFeedsDir = downloadPath;
|
|
288
|
+
try {
|
|
289
|
+
await fs.access(downloadPath);
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
throw new Error(`Could not find feeds directory in downloaded path: ${sourceFeedsDir}`);
|
|
293
|
+
}
|
|
294
|
+
await fs.cp(sourceFeedsDir, LOCAL_FEEDS_DIR, { recursive: true, force: true });
|
|
295
|
+
Logger.log('Successfully updated local feeds');
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
Logger.error('Error during feed synchronization', error);
|
|
299
|
+
throw new Error('Failed to sync feeds. Use --verbose for detailed error information.');
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
async loadFeedsIntoConfiguration(feedFile, settings) {
|
|
304
|
+
this.configuration = await ConfigurationLoader.loadFeedsIntoConfiguration(this.configuration, feedFile, settings);
|
|
305
|
+
await this.saveConfiguration();
|
|
306
|
+
}
|
|
307
|
+
async loadClientMCPSettings() {
|
|
308
|
+
this.configuration = await ConfigurationLoader.loadClientMCPSettings(this.configuration);
|
|
309
|
+
await this.saveConfiguration();
|
|
310
|
+
}
|
|
311
|
+
// Public method to reload client MCP settings
|
|
312
|
+
async reloadClientMCPSettings() {
|
|
313
|
+
return await this.withLock(async () => {
|
|
314
|
+
await this.loadClientMCPSettings();
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
async removeServerFromClientMCPSettings(serverName, target) {
|
|
318
|
+
return await this.withLock(async () => {
|
|
319
|
+
// Load utils in async context to avoid circular dependencies
|
|
320
|
+
const { readJsonFile, writeJsonFile } = await import('../../utils/clientUtils.js');
|
|
321
|
+
// Filter clients if target is specified
|
|
322
|
+
const clientEntries = Object.entries(SUPPORTED_CLIENTS);
|
|
323
|
+
const targetClients = target
|
|
324
|
+
? clientEntries.filter(([clientName]) => clientName === target)
|
|
325
|
+
: clientEntries;
|
|
326
|
+
for (const [clientName, clientSettings] of targetClients) {
|
|
327
|
+
const settingPath = process.env.CODE_INSIDERS
|
|
328
|
+
? clientSettings.codeInsiderSettingPath
|
|
329
|
+
: clientSettings.codeSettingPath;
|
|
330
|
+
try {
|
|
331
|
+
const content = await readJsonFile(settingPath, true);
|
|
332
|
+
let modified = false;
|
|
333
|
+
// Handle GitHub Copilot's different structure
|
|
334
|
+
if (clientName === 'GithubCopilot' && content.mcp?.servers?.[serverName]) {
|
|
335
|
+
delete content.mcp.servers[serverName];
|
|
336
|
+
modified = true;
|
|
337
|
+
}
|
|
338
|
+
else if (content.mcpServers?.[serverName]) {
|
|
339
|
+
delete content.mcpServers[serverName];
|
|
340
|
+
modified = true;
|
|
341
|
+
}
|
|
342
|
+
// Only write if we actually modified the content
|
|
343
|
+
if (modified) {
|
|
344
|
+
await writeJsonFile(settingPath, content);
|
|
345
|
+
Logger.debug(`Removed server ${serverName} from client ${clientName} settings`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
Logger.error(`Failed to remove server ${serverName} from client ${clientName} settings:`, error);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// Also update our in-memory configuration
|
|
353
|
+
if (this.configuration.clientMCPSettings) {
|
|
354
|
+
if (target) {
|
|
355
|
+
// Only update settings for the target client
|
|
356
|
+
const clientSettings = this.configuration.clientMCPSettings[target];
|
|
357
|
+
if (clientSettings) {
|
|
358
|
+
if (clientSettings.mcpServers?.[serverName]) {
|
|
359
|
+
delete clientSettings.mcpServers[serverName];
|
|
360
|
+
}
|
|
361
|
+
if (clientSettings.servers?.[serverName]) { // For GitHub Copilot
|
|
362
|
+
delete clientSettings.servers[serverName];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
// Update all clients if no target specified
|
|
368
|
+
for (const clientSettings of Object.values(this.configuration.clientMCPSettings)) {
|
|
369
|
+
if (clientSettings.mcpServers?.[serverName]) {
|
|
370
|
+
delete clientSettings.mcpServers[serverName];
|
|
371
|
+
}
|
|
372
|
+
if (clientSettings.servers?.[serverName]) { // For GitHub Copilot
|
|
373
|
+
delete clientSettings.servers[serverName];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
await this.saveConfiguration();
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
// Export a singleton instance
|
|
383
|
+
export const configProvider = ConfigurationProvider.getInstance();
|
|
384
|
+
//# sourceMappingURL=ConfigurationProvider.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ServerSchema } from './ServerSchemaProvider.js';
|
|
2
|
+
export declare class ServerSchemaLoader {
|
|
3
|
+
/**
|
|
4
|
+
* Loads a single schema file.
|
|
5
|
+
* @param filePath The absolute path to the schema file.
|
|
6
|
+
* @returns A Promise that resolves to the ServerSchema or undefined if not found or error.
|
|
7
|
+
*/
|
|
8
|
+
static loadSchema(filePath: string): Promise<ServerSchema | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* Loads all schemas from the default feeds directory.
|
|
11
|
+
* @param defaultFeedsDir The path to the default feeds directory.
|
|
12
|
+
* @param schemaMap The map to populate with loaded schemas.
|
|
13
|
+
*/
|
|
14
|
+
static loadAllDefaultSchemas(defaultFeedsDir: string, schemaMap: Map<string, Map<string, ServerSchema>>): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Loads schemas from an adhoc directory for a specific category.
|
|
17
|
+
* @param adhocSchemasDir The path to the adhoc schemas directory.
|
|
18
|
+
* @param categoryName The name of the category for these adhoc schemas.
|
|
19
|
+
* @param schemaMap The map to update with loaded adhoc schemas.
|
|
20
|
+
*/
|
|
21
|
+
static loadAdhocSchemas(adhocSchemasDir: string, categoryName: string, schemaMap: Map<string, Map<string, ServerSchema>>): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { Logger } from '../../utils/logger.js';
|
|
4
|
+
export class ServerSchemaLoader {
|
|
5
|
+
/**
|
|
6
|
+
* Loads a single schema file.
|
|
7
|
+
* @param filePath The absolute path to the schema file.
|
|
8
|
+
* @returns A Promise that resolves to the ServerSchema or undefined if not found or error.
|
|
9
|
+
*/
|
|
10
|
+
static async loadSchema(filePath) {
|
|
11
|
+
try {
|
|
12
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
13
|
+
const schema = JSON.parse(content);
|
|
14
|
+
return {
|
|
15
|
+
schema: schema
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error.code === 'ENOENT') {
|
|
20
|
+
Logger.debug(`No schema file found at ${filePath}`);
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
Logger.error(`Error loading schema from ${filePath}:`, error);
|
|
24
|
+
// Optionally rethrow or return undefined based on desired error handling
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Loads all schemas from the default feeds directory.
|
|
30
|
+
* @param defaultFeedsDir The path to the default feeds directory.
|
|
31
|
+
* @param schemaMap The map to populate with loaded schemas.
|
|
32
|
+
*/
|
|
33
|
+
static async loadAllDefaultSchemas(defaultFeedsDir, schemaMap) {
|
|
34
|
+
schemaMap.clear(); // Clear map for initial load from default directory
|
|
35
|
+
try {
|
|
36
|
+
const categoryDirs = await fs.readdir(defaultFeedsDir, { withFileTypes: true });
|
|
37
|
+
for (const categoryDir of categoryDirs) {
|
|
38
|
+
if (categoryDir.isDirectory()) {
|
|
39
|
+
const categoryName = categoryDir.name;
|
|
40
|
+
const categoryPath = path.join(defaultFeedsDir, categoryName);
|
|
41
|
+
const serverFiles = await fs.readdir(categoryPath);
|
|
42
|
+
const serverSchemas = new Map();
|
|
43
|
+
for (const file of serverFiles) {
|
|
44
|
+
if (file.endsWith('.json')) {
|
|
45
|
+
try {
|
|
46
|
+
const schemaFilePath = path.join(categoryPath, file);
|
|
47
|
+
const schema = await this.loadSchema(schemaFilePath);
|
|
48
|
+
if (schema) {
|
|
49
|
+
serverSchemas.set(file, schema); // file is serverName
|
|
50
|
+
Logger.debug(`Loaded schema '${file}' for category '${categoryName}' from default directory`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) { // Error already logged in loadSchema
|
|
54
|
+
Logger.error(`Skipping schema file ${file} in category ${categoryName} due to loading error.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (serverSchemas.size > 0) {
|
|
59
|
+
schemaMap.set(categoryName, serverSchemas);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
Logger.error(`Error reading schemas from default directory ${defaultFeedsDir}:`, error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Loads schemas from an adhoc directory for a specific category.
|
|
70
|
+
* @param adhocSchemasDir The path to the adhoc schemas directory.
|
|
71
|
+
* @param categoryName The name of the category for these adhoc schemas.
|
|
72
|
+
* @param schemaMap The map to update with loaded adhoc schemas.
|
|
73
|
+
*/
|
|
74
|
+
static async loadAdhocSchemas(adhocSchemasDir, categoryName, schemaMap) {
|
|
75
|
+
try {
|
|
76
|
+
const serverFiles = await fs.readdir(adhocSchemasDir);
|
|
77
|
+
if (schemaMap.has(categoryName)) {
|
|
78
|
+
Logger.warn(`\x1b[33mAdhoc schema category '${categoryName}' (from dir: ${adhocSchemasDir}) conflicts with an existing category. Adhoc schemas in this category will override existing ones.\x1b[0m`);
|
|
79
|
+
}
|
|
80
|
+
let serverSchemas = schemaMap.get(categoryName);
|
|
81
|
+
if (!serverSchemas) {
|
|
82
|
+
serverSchemas = new Map();
|
|
83
|
+
}
|
|
84
|
+
for (const file of serverFiles) {
|
|
85
|
+
if (file.endsWith('.json')) {
|
|
86
|
+
try {
|
|
87
|
+
const schemaFilePath = path.join(adhocSchemasDir, file);
|
|
88
|
+
const schema = await this.loadSchema(schemaFilePath);
|
|
89
|
+
if (schema) {
|
|
90
|
+
serverSchemas.set(file, schema); // file is serverName
|
|
91
|
+
Logger.debug(`Loaded adhoc schema '${file}' for category '${categoryName}'`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) { // Error already logged in loadSchema
|
|
95
|
+
Logger.error(`Skipping adhoc schema file ${file} in category ${categoryName} due to loading error.`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (serverSchemas.size > 0) {
|
|
100
|
+
schemaMap.set(categoryName, serverSchemas);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
// This case should ideally be caught by the fs.access check in ServerSchemaProvider.initialize
|
|
105
|
+
Logger.error(`Error reading adhoc schemas from directory ${adhocSchemasDir} for category ${categoryName}:`, error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=ServerSchemaLoader.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ServerSchema {
|
|
2
|
+
schema: Record<string, any>;
|
|
3
|
+
}
|
|
4
|
+
export declare class ServerSchemaProvider {
|
|
5
|
+
private static instance;
|
|
6
|
+
private schemaMap;
|
|
7
|
+
private schemaLock;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): ServerSchemaProvider;
|
|
10
|
+
private withLock;
|
|
11
|
+
initialize(adhocSchemasDir?: string): Promise<void>;
|
|
12
|
+
getSchema(categoryName: string, schemaFileName: string): Promise<ServerSchema | undefined>;
|
|
13
|
+
reloadSchemas(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { LOCAL_FEEDS_SCHEMA_DIR } from '../metadatas/constants.js';
|
|
4
|
+
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
import { ServerSchemaLoader } from './ServerSchemaLoader.js';
|
|
6
|
+
export class ServerSchemaProvider {
|
|
7
|
+
static instance;
|
|
8
|
+
schemaMap;
|
|
9
|
+
schemaLock = Promise.resolve();
|
|
10
|
+
constructor() {
|
|
11
|
+
this.schemaMap = new Map();
|
|
12
|
+
}
|
|
13
|
+
static getInstance() {
|
|
14
|
+
if (!ServerSchemaProvider.instance) {
|
|
15
|
+
ServerSchemaProvider.instance = new ServerSchemaProvider();
|
|
16
|
+
// Initialize is now called with optional adhocSchemasDir,
|
|
17
|
+
// but getInstance is often called without it initially.
|
|
18
|
+
// The actual loading with adhoc dir will happen when MCPManager calls initialize.
|
|
19
|
+
}
|
|
20
|
+
return ServerSchemaProvider.instance;
|
|
21
|
+
}
|
|
22
|
+
async withLock(operation) {
|
|
23
|
+
const current = this.schemaLock;
|
|
24
|
+
let resolve;
|
|
25
|
+
this.schemaLock = new Promise(r => resolve = r);
|
|
26
|
+
try {
|
|
27
|
+
await current;
|
|
28
|
+
return await operation();
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
resolve();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async initialize(adhocSchemasDir) {
|
|
35
|
+
await this.withLock(async () => {
|
|
36
|
+
try {
|
|
37
|
+
// Create default feeds directory if it doesn't exist
|
|
38
|
+
await fs.mkdir(LOCAL_FEEDS_SCHEMA_DIR, { recursive: true });
|
|
39
|
+
// Load all schemas from the default feeds directory
|
|
40
|
+
await ServerSchemaLoader.loadAllDefaultSchemas(LOCAL_FEEDS_SCHEMA_DIR, this.schemaMap);
|
|
41
|
+
// Load schemas from adhoc directory if provided
|
|
42
|
+
if (adhocSchemasDir) {
|
|
43
|
+
try {
|
|
44
|
+
await fs.access(adhocSchemasDir); // Check if directory exists
|
|
45
|
+
const adhocCategoryName = path.basename(adhocSchemasDir);
|
|
46
|
+
Logger.info(`Loading adhoc schemas from: ${adhocSchemasDir} for category: ${adhocCategoryName}`);
|
|
47
|
+
await ServerSchemaLoader.loadAdhocSchemas(adhocSchemasDir, adhocCategoryName, this.schemaMap);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error.code === 'ENOENT') {
|
|
51
|
+
Logger.warn(`Adhoc schemas directory not found: ${adhocSchemasDir}`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
Logger.error(`Error accessing adhoc schemas directory ${adhocSchemasDir}:`, error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
Logger.error('Error during schema initialization:', error);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// The actual loading methods (loadSchema, loadAllSchemas, loadAdhocSchemas) have been moved to ServerSchemaLoader.
|
|
66
|
+
// ServerSchemaProvider now delegates to ServerSchemaLoader for these operations.
|
|
67
|
+
async getSchema(categoryName, schemaFileName) {
|
|
68
|
+
return await this.withLock(async () => {
|
|
69
|
+
const categorySchemas = this.schemaMap.get(categoryName);
|
|
70
|
+
if (!categorySchemas) {
|
|
71
|
+
Logger.debug(`No schemas found for category ${categoryName}`);
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
const schema = categorySchemas.get(schemaFileName);
|
|
75
|
+
if (!schema) {
|
|
76
|
+
Logger.debug(`Schema ${schemaFileName} not found in category ${categoryName}`);
|
|
77
|
+
}
|
|
78
|
+
return schema;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async reloadSchemas() {
|
|
82
|
+
return await this.withLock(async () => {
|
|
83
|
+
// Reloading should re-evaluate both default and any configured adhoc directory
|
|
84
|
+
// For simplicity, we assume initialize would be called again if adhoc path changes.
|
|
85
|
+
// This reload will just reload from the paths known during the last full initialize.
|
|
86
|
+
await this.initialize(); // This will re-load default and adhoc if adhocSchemasDir was set
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=ServerSchemaProvider.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines constants used across the application.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* GitHub repository configuration for feeds
|
|
6
|
+
*/
|
|
7
|
+
export declare const GITHUB_REPO: {
|
|
8
|
+
url: string;
|
|
9
|
+
repoName: string;
|
|
10
|
+
feedsPath: string;
|
|
11
|
+
feedAssetsName: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Local settings directory path based on OS
|
|
15
|
+
*/
|
|
16
|
+
export declare const SETTINGS_DIR: string;
|
|
17
|
+
/**
|
|
18
|
+
* Local feeds directory path
|
|
19
|
+
*/
|
|
20
|
+
export declare const LOCAL_FEEDS_DIR: string;
|
|
21
|
+
export declare const LOCAL_FEEDS_SCHEMA_DIR: string;
|
|
22
|
+
/**
|
|
23
|
+
* Supported client configurations.
|
|
24
|
+
* Key: Client name (e.g., 'vscode')
|
|
25
|
+
* Value: Client-specific settings or configuration details.
|
|
26
|
+
* TODO: Define actual client settings structure.
|
|
27
|
+
*/
|
|
28
|
+
export declare const SUPPORTED_CLIENTS: Record<string, {
|
|
29
|
+
extension: {
|
|
30
|
+
extensionId: string;
|
|
31
|
+
leastVersion?: string;
|
|
32
|
+
repository?: string;
|
|
33
|
+
assetName?: string;
|
|
34
|
+
private?: boolean;
|
|
35
|
+
};
|
|
36
|
+
codeSettingPath: string;
|
|
37
|
+
codeInsiderSettingPath: string;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* List of supported client names.
|
|
41
|
+
*/
|
|
42
|
+
export declare const SUPPORTED_CLIENT_NAMES: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Minimum time between requirement update checks (in milliseconds)
|
|
45
|
+
* 10 minutes = 10 * 60 * 1000 = 600000 ms
|
|
46
|
+
*/
|
|
47
|
+
export declare const UPDATE_CHECK_INTERVAL_MS: number;
|