mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 22:02:59 -07:00
Skip MCP server connections in untrusted folders (#7358)
This commit is contained in:
@@ -747,6 +747,89 @@ describe('DiscoveredMCPTool', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('shouldConfirmExecute with folder trust', () => {
|
||||
const mockConfig = (isTrusted: boolean | undefined) => ({
|
||||
isTrustedFolder: () => isTrusted,
|
||||
});
|
||||
|
||||
it('should return false if trust is true and folder is trusted', async () => {
|
||||
const trustedTool = new DiscoveredMCPTool(
|
||||
mockCallableToolInstance,
|
||||
serverName,
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
undefined,
|
||||
true, // trust = true
|
||||
undefined,
|
||||
mockConfig(true) as any, // isTrustedFolder = true
|
||||
);
|
||||
const invocation = trustedTool.build({ param: 'mock' });
|
||||
expect(
|
||||
await invocation.shouldConfirmExecute(new AbortController().signal),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should return confirmation details if trust is true but folder is not trusted', async () => {
|
||||
const trustedTool = new DiscoveredMCPTool(
|
||||
mockCallableToolInstance,
|
||||
serverName,
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
undefined,
|
||||
true, // trust = true
|
||||
undefined,
|
||||
mockConfig(false) as any, // isTrustedFolder = false
|
||||
);
|
||||
const invocation = trustedTool.build({ param: 'mock' });
|
||||
const confirmation = await invocation.shouldConfirmExecute(
|
||||
new AbortController().signal,
|
||||
);
|
||||
expect(confirmation).not.toBe(false);
|
||||
expect(confirmation).toHaveProperty('type', 'mcp');
|
||||
});
|
||||
|
||||
it('should return confirmation details if trust is false, even if folder is trusted', async () => {
|
||||
const untrustedTool = new DiscoveredMCPTool(
|
||||
mockCallableToolInstance,
|
||||
serverName,
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
undefined,
|
||||
false, // trust = false
|
||||
undefined,
|
||||
mockConfig(true) as any, // isTrustedFolder = true
|
||||
);
|
||||
const invocation = untrustedTool.build({ param: 'mock' });
|
||||
const confirmation = await invocation.shouldConfirmExecute(
|
||||
new AbortController().signal,
|
||||
);
|
||||
expect(confirmation).not.toBe(false);
|
||||
expect(confirmation).toHaveProperty('type', 'mcp');
|
||||
});
|
||||
|
||||
it('should return false if trust is true and folder trust is undefined', async () => {
|
||||
// The check is `isTrustedFolder() !== false`, so `undefined` should pass
|
||||
const trustedTool = new DiscoveredMCPTool(
|
||||
mockCallableToolInstance,
|
||||
serverName,
|
||||
serverToolName,
|
||||
baseDescription,
|
||||
inputSchema,
|
||||
undefined,
|
||||
true, // trust = true
|
||||
undefined,
|
||||
mockConfig(undefined) as any, // isTrustedFolder = undefined
|
||||
);
|
||||
const invocation = trustedTool.build({ param: 'mock' });
|
||||
expect(
|
||||
await invocation.shouldConfirmExecute(new AbortController().signal),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DiscoveredMCPToolInvocation', () => {
|
||||
it('should return the stringified params from getDescription', () => {
|
||||
const params = { param: 'testValue', param2: 'anotherOne' };
|
||||
|
||||
Reference in New Issue
Block a user