Stop extension MCPs from hopping into settings. (#1026)

This commit is contained in:
Tommaso Sciortino 2025-06-13 14:51:29 -07:00 committed by GitHub
parent bb67d31739
commit a2fe3d2ad0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 4 deletions

View File

@ -269,3 +269,32 @@ describe('Hierarchical Memory Loading (config.ts) - Placeholder Suite', () => {
});
*/
});
describe('mergeMcpServers', () => {
it('should not modify the original settings object', async () => {
const settings: Settings = {
mcpServers: {
'test-server': {
url: 'http://localhost:8080',
},
},
};
const extensions: Extension[] = [
{
config: {
name: 'ext1',
version: '1.0.0',
mcpServers: {
'ext1-server': {
url: 'http://localhost:8081',
},
},
},
contextFiles: [],
},
];
const originalSettings = JSON.parse(JSON.stringify(settings));
await loadCliConfig(settings, extensions, [], 'test-session');
expect(settings).toEqual(originalSettings);
});
});

View File

@ -205,7 +205,7 @@ export async function loadCliConfig(
}
function mergeMcpServers(settings: Settings, extensions: Extension[]) {
const mcpServers = settings.mcpServers || {};
const mcpServers = { ...(settings.mcpServers || {}) };
for (const extension of extensions) {
Object.entries(extension.config.mcpServers || {}).forEach(
([key, server]) => {

View File

@ -72,7 +72,7 @@ describe('loadExtensions', () => {
'ext1',
'1.0.0',
false,
'my-context.md',
'my-context-file.md',
);
const extensions = loadExtensions(tempWorkspaceDir);
@ -80,7 +80,7 @@ describe('loadExtensions', () => {
expect(extensions).toHaveLength(1);
const ext1 = extensions.find((e) => e.config.name === 'ext1');
expect(ext1?.contextFiles).toEqual([
path.join(workspaceExtensionsDir, 'ext1', 'my-context.md'),
path.join(workspaceExtensionsDir, 'ext1', 'my-context-file.md'),
]);
});
});

View File

@ -107,7 +107,7 @@ function loadExtension(extensionDir: string): Extension | null {
function getContextFileNames(config: ExtensionConfig): string[] {
if (!config.contextFileName) {
return ['GEMINI.md', 'gemini.md', 'Gemini.md'];
return ['GEMINI.md'];
} else if (!Array.isArray(config.contextFileName)) {
return [config.contextFileName];
}