Skip to content

Commit 211c35c

Browse files
authored
Merge pull request #6808 from remix-project-org/fix_workspace_config
added workspace creation check before saving configs
2 parents 5140b0e + 2b4f12a commit 211c35c

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

apps/remix-ide/src/app/panels/file-panel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ export default class Filepanel extends ViewPlugin {
313313
if (workspace.name !== ' - connect to localhost - ') {
314314
localStorage.setItem('currentWorkspace', workspace.name)
315315
}
316+
console.log('setting workspace', workspace)
316317
this.emit('setWorkspace', workspace)
317318
}
318319

libs/remix-ai-core/src/remix-mcp-server/config/MCPConfigManager.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class MCPConfigManager {
2525
// Handle empty or whitespace-only files
2626
if (!configContent || configContent.trim() === '') {
2727
console.log('[MCPConfigManager] Config file saved as empty, writing default config');
28-
await this.saveConfig(minimalMCPConfig);
28+
await this.saveConfigWithWorkspaceCheck(minimalMCPConfig);
2929
return;
3030
}
3131

@@ -36,13 +36,13 @@ export class MCPConfigManager {
3636
console.log('[MCPConfigManager] Config reloaded from file save');
3737
} else {
3838
console.log('[MCPConfigManager] No mcp config in saved file, writing default');
39-
await this.saveConfig(minimalMCPConfig);
39+
await this.saveConfigWithWorkspaceCheck(minimalMCPConfig);
4040
}
4141
} catch (error) {
4242
console.error('[MCPConfigManager] Error reloading config on file save:', error);
4343
// If there's an error, write the default config
4444
try {
45-
await this.saveConfig(minimalMCPConfig);
45+
await this.saveConfigWithWorkspaceCheck(minimalMCPConfig);
4646
} catch (saveError) {
4747
console.error('[MCPConfigManager] Error writing default config:', saveError);
4848
}
@@ -54,6 +54,7 @@ export class MCPConfigManager {
5454

5555
async loadConfig(): Promise<MCPConfig> {
5656
try {
57+
await this.waitForWorkspace();
5758
const exists = await this.plugin.call('fileManager', 'exists', this.configPath);
5859

5960
if (exists) {
@@ -107,6 +108,44 @@ export class MCPConfigManager {
107108
}
108109
}
109110

111+
private async isWorkspaceReady(): Promise<boolean> {
112+
try {
113+
const workspace = await this.plugin.call('filePanel', 'getCurrentWorkspace');
114+
return workspace && workspace.name.trim() !== '';
115+
} catch (error) {
116+
return false;
117+
}
118+
}
119+
120+
private async waitForWorkspace(): Promise<boolean> {
121+
if (await this.isWorkspaceReady()) {
122+
console.log('[MCPConfigManager] Workspace is already ready');
123+
return true;
124+
}
125+
126+
return new Promise<boolean>((resolve) => {
127+
const checkAndResolve = async () => {
128+
if (await this.isWorkspaceReady()) {
129+
console.log('[MCPConfigManager] Workspace is ready');
130+
resolve(true);
131+
}
132+
};
133+
134+
this.plugin.once('filePanel', 'setWorkspace', checkAndResolve);
135+
});
136+
}
137+
138+
async saveConfigWithWorkspaceCheck(config: MCPConfig): Promise<void> {
139+
const workspaceReady = await this.waitForWorkspace();
140+
141+
if (!workspaceReady) {
142+
this.config = config;
143+
return;
144+
}
145+
146+
await this.saveConfig(config);
147+
}
148+
110149
async saveConfig(config: MCPConfig): Promise<void> {
111150
try {
112151
const exists = await this.plugin.call('fileManager', 'exists', this.configPath);
@@ -151,7 +190,7 @@ export class MCPConfigManager {
151190
return;
152191
}
153192

154-
await this.saveConfig(defaultMCPConfig);
193+
await this.saveConfigWithWorkspaceCheck(defaultMCPConfig);
155194
console.log('[MCPConfigManager] Default config file created');
156195
} catch (error) {
157196
console.error(`[MCPConfigManager] Error creating default config: ${error.message}`);
@@ -179,7 +218,7 @@ export class MCPConfigManager {
179218
const permissions = this.config.security.fileWritePermissions || {
180219
mode: 'ask' as const,
181220
allowedFiles: [],
182-
lastPrompted: null
221+
lastPrompted: undefined
183222
};
184223
return permissions;
185224
}
@@ -199,15 +238,15 @@ export class MCPConfigManager {
199238
config.security.fileWritePermissions = {
200239
mode: 'ask',
201240
allowedFiles: [],
202-
lastPrompted: null
241+
lastPrompted: undefined
203242
};
204243
}
205244

206245
const perms = config.security.fileWritePermissions;
207246
perms.mode = mode;
208247
perms.lastPrompted = new Date().toISOString();
209248

210-
if (mode === 'allow-specific' && filePath) {
249+
if (mode === 'allow-specific' && filePath && perms.allowedFiles) {
211250
if (!perms.allowedFiles.includes(filePath)) {
212251
perms.allowedFiles.push(filePath);
213252
}

libs/remix-ai-core/src/remix-mcp-server/types/mcpConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export const defaultMCPConfig: MCPConfig = {
107107
fileWritePermissions: {
108108
mode: 'ask',
109109
allowedFiles: [],
110-
lastPrompted: null
110+
lastPrompted: undefined
111111
}
112112
},
113113
validation: {

0 commit comments

Comments
 (0)