Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/core/src/tools/mcp-tool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,54 @@ describe('DiscoveredMCPTool', () => {
isTrustedFolder: () => isTrusted,
});

it.each([
{
name: 'an untrusted server with readOnlyHint',
trust: undefined,
isTrustedFolder: true,
readOnlyHint: true,
expected: 'ask',
},
{
name: 'a trusted server with readOnlyHint in an untrusted folder',
trust: true,
isTrustedFolder: false,
readOnlyHint: true,
expected: 'ask',
},
{
name: 'a trusted server with readOnlyHint in a trusted folder',
trust: true,
isTrustedFolder: true,
readOnlyHint: true,
expected: 'allow',
},
{
name: 'an untrusted server with readOnlyHint disabled',
trust: undefined,
isTrustedFolder: true,
readOnlyHint: false,
expected: 'ask',
},
])('should return $expected for $name', async (testCase) => {
const annotatedTool = new DiscoveredMCPTool(
mockCallableToolInstance,
serverName,
serverToolName,
baseDescription,
inputSchema,
testCase.trust,
undefined,
mockConfig(testCase.isTrustedFolder) as any,
undefined,
undefined,
undefined,
{ readOnlyHint: testCase.readOnlyHint },
);
const invocation = annotatedTool.build({ param: 'mock' });
expect(await invocation.getDefaultPermission()).toBe(testCase.expected);
});

it('should return allow when trust is true and folder is trusted', async () => {
const trustedTool = new DiscoveredMCPTool(
mockCallableToolInstance,
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/tools/mcp-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
}

/**
* MCP tool default permission based on trust and annotations:
* MCP tool default permission based on trust:
* - trust: true in a trusted folder → 'allow' (server explicitly trusted by user config)
* - readOnlyHint → 'allow'
* - All other MCP tools → 'ask'
*/
override async getDefaultPermission(): Promise<PermissionDecision> {
Expand All @@ -155,10 +154,6 @@ class DiscoveredMCPToolInvocation extends BaseToolInvocation<
if (this.trust === true && this.cliConfig?.isTrustedFolder()) {
return 'allow';
}
// MCP tools annotated with readOnlyHint: true are safe
if (this.annotations?.readOnlyHint === true) {
return 'allow';
}
return 'ask';
}

Expand Down
Loading