Skip to content

Commit 1399a75

Browse files
authored
separate mcp r/w classification (#177)
1 parent cf96824 commit 1399a75

10 files changed

Lines changed: 69 additions & 6 deletions

File tree

‎src/server/lib/validation/aiAgentConfigSchemas.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const approvalPolicyRulesSchema = {
2020
type: 'object',
2121
properties: {
2222
read: approvalModeSchema,
23+
external_mcp_read: approvalModeSchema,
2324
workspace_write: approvalModeSchema,
2425
shell_exec: approvalModeSchema,
2526
git_write: approvalModeSchema,

‎src/server/services/agent/CapabilityService.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export default class AgentCapabilityService {
348348
const catalogEntries = getSessionWorkspaceCatalogEntriesForRuntimeTool(discoveredTool.name, server.name);
349349

350350
for (const entry of catalogEntries) {
351-
const capabilityKey = AgentPolicyService.capabilityForMcpTool(
351+
const capabilityKey = AgentPolicyService.capabilityForSessionWorkspaceTool(
352352
entry.toolName,
353353
entry.annotations || discoveredTool.annotations
354354
);
@@ -496,7 +496,10 @@ export default class AgentCapabilityService {
496496
continue;
497497
}
498498

499-
const capabilityKey = AgentPolicyService.capabilityForMcpTool(discoveredTool.name, discoveredTool.annotations);
499+
const capabilityKey = AgentPolicyService.capabilityForExternalMcpTool(
500+
discoveredTool.name,
501+
discoveredTool.annotations
502+
);
500503
const toolName = buildAgentToolKey(server.slug, discoveredTool.name);
501504
const mode = resolveToolApprovalMode({
502505
toolRules,

‎src/server/services/agent/PolicyService.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class AgentPolicyService {
4343
};
4444
}
4545

46-
static capabilityForMcpTool(toolName: string, annotations?: McpAnnotations): AgentCapabilityKey {
46+
static capabilityForSessionWorkspaceTool(toolName: string, annotations?: McpAnnotations): AgentCapabilityKey {
4747
if (annotations?.readOnlyHint) {
4848
return 'read';
4949
}
@@ -75,6 +75,14 @@ export default class AgentPolicyService {
7575
return 'network_access';
7676
}
7777

78+
return 'workspace_write';
79+
}
80+
81+
static capabilityForExternalMcpTool(_toolName: string, annotations?: McpAnnotations): AgentCapabilityKey {
82+
if (annotations?.readOnlyHint) {
83+
return 'external_mcp_read';
84+
}
85+
7886
return 'external_mcp_write';
7987
}
8088

‎src/server/services/agent/__tests__/CapabilityService.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ jest.mock('server/lib/logger', () => ({
5757
jest.mock('../PolicyService', () => ({
5858
__esModule: true,
5959
default: {
60-
capabilityForMcpTool: jest.fn(() => 'external_mcp_read'),
60+
capabilityForSessionWorkspaceTool: jest.fn(() => 'read'),
61+
capabilityForExternalMcpTool: jest.fn(() => 'external_mcp_read'),
6162
modeForCapability: (...args: unknown[]) => mockModeForCapability(...args),
6263
},
6364
}));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2026 GoodRx, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import AgentPolicyService from '../PolicyService';
18+
19+
describe('AgentPolicyService', () => {
20+
it('keeps read-only sandbox tools in the read capability', () => {
21+
expect(
22+
AgentPolicyService.capabilityForSessionWorkspaceTool('workspace.read_file', {
23+
readOnlyHint: true,
24+
})
25+
).toBe('read');
26+
});
27+
28+
it('keeps session git helpers in the git write capability', () => {
29+
expect(AgentPolicyService.capabilityForSessionWorkspaceTool('git.branch')).toBe('git_write');
30+
});
31+
32+
it('maps read-only external MCP tools to external_mcp_read', () => {
33+
expect(
34+
AgentPolicyService.capabilityForExternalMcpTool('getJiraIssue', {
35+
readOnlyHint: true,
36+
})
37+
).toBe('external_mcp_read');
38+
});
39+
40+
it('maps mutating external MCP tools to external_mcp_write without workspace heuristics', () => {
41+
expect(AgentPolicyService.capabilityForExternalMcpTool('editJiraIssue')).toBe('external_mcp_write');
42+
});
43+
});

‎src/server/services/agent/sandboxToolCatalog.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function isSessionWorkspaceToolAllowed(
284284
toolRules: AgentSessionToolRule[] = []
285285
): boolean {
286286
const rule = toolRules.find((item) => item.toolKey === entry.toolKey);
287-
const capabilityKey = AgentPolicyService.capabilityForMcpTool(entry.toolName, entry.annotations);
287+
const capabilityKey = AgentPolicyService.capabilityForSessionWorkspaceTool(entry.toolName, entry.annotations);
288288
const mode = rule?.mode || AgentPolicyService.modeForCapability(approvalPolicy, capabilityKey);
289289

290290
return mode !== 'deny';

‎src/server/services/agent/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type { UIDataTypes, UIMessage } from 'ai';
1818

1919
export const AGENT_CAPABILITY_KEYS = [
2020
'read',
21+
'external_mcp_read',
2122
'workspace_write',
2223
'shell_exec',
2324
'git_write',
@@ -159,6 +160,7 @@ export const DEFAULT_AGENT_APPROVAL_POLICY: AgentApprovalPolicy = {
159160
defaultMode: 'require_approval',
160161
rules: {
161162
read: 'allow',
163+
external_mcp_read: 'allow',
162164
workspace_write: 'require_approval',
163165
shell_exec: 'require_approval',
164166
git_write: 'require_approval',

‎src/server/services/agentSessionConfig.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,10 @@ export default class AgentSessionConfigService extends BaseService {
498498
annotations?: McpDiscoveredTool['annotations'];
499499
}) => {
500500
const toolKey = buildAgentToolKey(serverSlug, toolName);
501-
const capabilityKey = AgentPolicyService.capabilityForMcpTool(toolName, annotations);
501+
const capabilityKey =
502+
sourceType === 'builtin'
503+
? AgentPolicyService.capabilityForSessionWorkspaceTool(toolName, annotations)
504+
: AgentPolicyService.capabilityForExternalMcpTool(toolName, annotations);
502505
const approvalMode = AgentPolicyService.modeForCapability(approvalPolicy, capabilityKey);
503506
const scopeRuleMode = toRuleSelection(activeScopeConfig.toolRules || [], toolKey);
504507
const effectiveRuleMode = toRuleSelection(effectiveConfig.toolRules, toolKey);

‎src/server/services/types/aiAgent.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export interface ApprovalPolicyConfig {
331331
rules?: Partial<
332332
Record<
333333
| 'read'
334+
| 'external_mcp_read'
334335
| 'workspace_write'
335336
| 'shell_exec'
336337
| 'git_write'

‎src/shared/openApiSpec.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export const openApiSpecificationForV2Api: OAS3Options = {
195195
type: 'object',
196196
properties: {
197197
read: { $ref: '#/components/schemas/AgentApprovalMode' },
198+
external_mcp_read: { $ref: '#/components/schemas/AgentApprovalMode' },
198199
workspace_write: { $ref: '#/components/schemas/AgentApprovalMode' },
199200
shell_exec: { $ref: '#/components/schemas/AgentApprovalMode' },
200201
git_write: { $ref: '#/components/schemas/AgentApprovalMode' },

0 commit comments

Comments
 (0)