Skip to content

Commit b9e5621

Browse files
committed
feat: MCP tool auto-approve and global auto-approve (Auto-approve Part 4) (#218)
* add mcp approve support and global approve support * resolve comments * fix test cases * resolve comments and add token/policy check * fix compile error * Fix auto-approve preference page layout instability
1 parent ce2e019 commit b9e5621

25 files changed

Lines changed: 2102 additions & 124 deletions

File tree

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/Constants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ private Constants() {
5959
public static final String AUTO_APPROVE_UNMATCHED_TERMINAL = "autoApproveUnmatchedTerminal";
6060
public static final String AUTO_APPROVE_FILE_OP_RULES = "autoApproveEditRules";
6161
public static final String AUTO_APPROVE_UNMATCHED_FILE_OP = "autoApproveUnmatchedFileOp";
62+
public static final String AUTO_APPROVE_MCP_SERVERS = "autoApproveMcpServers";
63+
public static final String AUTO_APPROVE_MCP_TOOLS = "autoApproveMcpTools";
64+
public static final String AUTO_APPROVE_TRUST_TOOL_ANNOTATIONS = "autoApproveTrustToolAnnotations";
65+
public static final String AUTO_APPROVE_YOLO_MODE = "autoApproveYoloMode";
6266

6367
// Base excluded file types shared by both
6468
// Copied from InelliJ, excluded file extension list

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/FeatureFlags.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class FeatureFlags {
2525

2626
private boolean customAgentPolicyEnabled = true;
2727

28+
private boolean autoApprovalTokenEnabled = true;
29+
30+
private boolean autoApprovalPolicyEnabled = true;
31+
2832
public boolean isAgentModeEnabled() {
2933
return agentModeEnabled;
3034
}
@@ -84,6 +88,25 @@ public void setCustomAgentPolicyEnabled(boolean customAgentPolicyEnabled) {
8488
this.customAgentPolicyEnabled = customAgentPolicyEnabled;
8589
}
8690

91+
/**
92+
* Returns true if the auto-approval feature is available.
93+
* Requires both the server token ({@code agent_mode_auto_approval}) and
94+
* the organization policy ({@code agentMode.autoApproval.enabled}) to permit it.
95+
*
96+
* @return true if auto-approval is permitted
97+
*/
98+
public boolean isAutoApprovalEnabled() {
99+
return autoApprovalTokenEnabled && autoApprovalPolicyEnabled;
100+
}
101+
102+
public void setAutoApprovalTokenEnabled(boolean autoApprovalTokenEnabled) {
103+
this.autoApprovalTokenEnabled = autoApprovalTokenEnabled;
104+
}
105+
106+
public void setAutoApprovalPolicyEnabled(boolean autoApprovalPolicyEnabled) {
107+
this.autoApprovalPolicyEnabled = autoApprovalPolicyEnabled;
108+
}
109+
87110
public boolean isClientPreviewFeatureEnabled() {
88111
return clientPreviewFeatureEnabled;
89112
}

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ public void onDidChangeFeatureFlags(DidChangeFeatureFlagsParams params) {
310310
flags.setMcpEnabled(params.isMcpEnabled());
311311
flags.setByokEnabled(params.isByokEnabled());
312312
flags.setClientPreviewFeatureEnabled(params.isClientPreviewFeaturesEnabled());
313+
flags.setAutoApprovalTokenEnabled(params.isAutoApprovalEnabled());
313314
}
314315

315316
if (eventBroker != null) {
@@ -337,6 +338,7 @@ public void onDidChangePolicy(DidChangePolicyParams params) {
337338
flags.setCustomAgentPolicyEnabled(params.isCustomAgentEnabled());
338339
eventBroker.post(CopilotEventConstants.TOPIC_DID_CHANGE_CUSTOM_AGENT_POLICY, params.isCustomAgentEnabled());
339340
}
341+
flags.setAutoApprovalPolicyEnabled(params.isAutoApprovalPolicyEnabled());
340342
}
341343
}
342344

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/DidChangeFeatureFlagsParams.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public boolean isClientPreviewFeaturesEnabled() {
7676
return !disabled;
7777
}
7878

79+
/**
80+
* Checks if the auto-approval feature is enabled.
81+
* Disabled only when the feature flag "agent_mode_auto_approval" is set to "0".
82+
*/
83+
public boolean isAutoApprovalEnabled() {
84+
boolean disabled = featureFlags != null && "0".equals(featureFlags.get("agent_mode_auto_approval"));
85+
return !disabled;
86+
}
87+
7988
@Override
8089
public int hashCode() {
8190
return Objects.hash(activeExps, featureFlags, envelope, byokEnabled);

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/policy/DidChangePolicyParams.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public class DidChangePolicyParams {
2222
@SerializedName("customAgent.enabled")
2323
private boolean customAgentEnabled = true;
2424

25+
@SerializedName("agentMode.autoApproval.enabled")
26+
private boolean autoApprovalPolicyEnabled = true;
27+
2528
public boolean isMcpContributionPointEnabled() {
2629
return mcpContributionPointEnabled;
2730
}
@@ -46,9 +49,18 @@ public void setCustomAgentEnabled(boolean customAgentEnabled) {
4649
this.customAgentEnabled = customAgentEnabled;
4750
}
4851

52+
public boolean isAutoApprovalPolicyEnabled() {
53+
return autoApprovalPolicyEnabled;
54+
}
55+
56+
public void setAutoApprovalPolicyEnabled(boolean autoApprovalPolicyEnabled) {
57+
this.autoApprovalPolicyEnabled = autoApprovalPolicyEnabled;
58+
}
59+
4960
@Override
5061
public int hashCode() {
51-
return Objects.hash(mcpContributionPointEnabled, subAgentEnabled, customAgentEnabled);
62+
return Objects.hash(mcpContributionPointEnabled, subAgentEnabled, customAgentEnabled,
63+
autoApprovalPolicyEnabled);
5264
}
5365

5466
@Override
@@ -65,7 +77,8 @@ public boolean equals(Object obj) {
6577
DidChangePolicyParams other = (DidChangePolicyParams) obj;
6678
return mcpContributionPointEnabled == other.mcpContributionPointEnabled
6779
&& subAgentEnabled == other.subAgentEnabled
68-
&& customAgentEnabled == other.customAgentEnabled;
80+
&& customAgentEnabled == other.customAgentEnabled
81+
&& autoApprovalPolicyEnabled == other.autoApprovalPolicyEnabled;
6982
}
7083

7184
@Override
@@ -74,6 +87,7 @@ public String toString() {
7487
builder.append("mcpContributionPointEnabled", mcpContributionPointEnabled);
7588
builder.append("subAgentEnabled", subAgentEnabled);
7689
builder.append("customAgentEnabled", customAgentEnabled);
90+
builder.append("autoApprovalPolicyEnabled", autoApprovalPolicyEnabled);
7791
return builder.toString();
7892
}
7993
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Global Auto-Approve
2+
3+
## Overview
4+
5+
Tests the Global Auto-Approve (YOLO) feature: enabling/disabling it via the
6+
preference page and verifying that all tool confirmations are bypassed when
7+
active.
8+
9+
Entry points exercised:
10+
- **Preferences → GitHub Copilot → Tool Auto Approve → Global Auto-Approve**
11+
the "Automatically approve ALL tool invocations" checkbox with its
12+
confirmation dialog.
13+
- **Agent Mode chat** — any tool call (terminal, file operation, MCP) to
14+
observe confirmation bypass.
15+
16+
---
17+
18+
## Prerequisites
19+
20+
- Eclipse IDE with the GitHub Copilot for Eclipse plugin installed and
21+
activated.
22+
- A signed-in Copilot account on the host machine.
23+
- Network access to `api.githubcopilot.com`.
24+
- **Agent Mode** selected in the chat mode dropdown.
25+
- Global Auto-Approve is **disabled** at the start of each scenario.
26+
27+
---
28+
29+
## 1. Enable Global Auto-Approve — confirmation dialog required
30+
31+
### TC-001: Enable Global Auto-Approve → confirmation dialog required
32+
→ all tools skip confirmation
33+
34+
**Type:** `Happy Path`
35+
**Priority:** `P0`
36+
37+
#### Steps
38+
1. Open **Preferences → Tool Auto Approve → Global Auto-Approve** section.
39+
2. Click the **"Automatically approve ALL tool invocations"** checkbox.
40+
3. Observe that a **confirmation dialog immediately appears** asking the user
41+
to confirm this dangerous setting.
42+
4. Verify the dialog title and message warn about the risk.
43+
5. Click **Cancel** — verify the checkbox remains **unchecked**.
44+
6. Click the checkbox again, then click **OK** in the confirmation dialog.
45+
7. Verify the checkbox is now **checked**.
46+
8. Click **"Apply and Close"**.
47+
9. In Agent Mode, send a prompt that would normally trigger a confirmation
48+
(e.g., an MCP tool call or a terminal command).
49+
10. Observe that **no confirmation dialog appears** — all tools auto-approve.
50+
51+
#### Expected Result
52+
- Enabling YOLO mode requires an explicit confirmation dialog.
53+
- Cancelling the dialog keeps the checkbox unchecked.
54+
- When enabled, all tool confirmations (terminal, file operations, MCP)
55+
are bypassed.
56+
57+
#### 📸 Key Screenshots
58+
- [ ] Confirmation dialog when enabling YOLO mode.
59+
- [ ] Checkbox unchecked after Cancel.
60+
- [ ] Checkbox checked after OK.
61+
- [ ] Agent Mode: tool runs without any confirmation dialog.
62+
63+
---
64+
65+
## 2. Disable Global Auto-Approve — no confirmation needed
66+
67+
### TC-002: Disable Global Auto-Approve → no dialog → tools require
68+
confirmation again
69+
70+
**Type:** `Happy Path`
71+
**Priority:** `P1`
72+
73+
#### Preconditions
74+
- Global Auto-Approve is **enabled**.
75+
76+
#### Steps
77+
1. Open **Preferences → Tool Auto Approve → Global Auto-Approve** section.
78+
2. Click the **"Automatically approve ALL tool invocations"** checkbox to
79+
uncheck it.
80+
3. Observe that **no confirmation dialog appears** — turning it off is safe
81+
and does not require confirmation.
82+
4. Verify the checkbox is now **unchecked**.
83+
5. Click **"Apply and Close"**.
84+
6. In Agent Mode, trigger any tool.
85+
7. Observe that the **confirmation dialog appears** — YOLO mode is off.
86+
87+
#### Expected Result
88+
- Disabling YOLO mode does not require a confirmation dialog.
89+
- Tools require confirmation again after disabling.
90+
91+
#### 📸 Key Screenshots
92+
- [ ] Checkbox unchecked without any dialog.
93+
- [ ] Tool shows confirmation dialog again.
94+
95+
---
96+
97+
## 3. Global Auto-Approve overrides all tool categories
98+
99+
### TC-003: Global Auto-Approve bypasses terminal deny rules, MCP
100+
rules, and file operation rules
101+
102+
**Type:** `Edge Case`
103+
**Priority:** `P1`
104+
105+
#### Preconditions
106+
- Global Auto-Approve is **enabled**.
107+
- Terminal has a custom **Deny** rule for `curl`.
108+
109+
#### Steps
110+
1. In Agent Mode, trigger a `curl` terminal command (normally blocked by the
111+
deny rule).
112+
2. Observe **auto-approved** — YOLO mode bypasses the deny rule.
113+
3. Trigger an MCP tool call with no prior MCP approval.
114+
4. Observe **auto-approved** — YOLO mode bypasses MCP confirmation.
115+
5. Trigger a file operation on a file not in the attached context.
116+
6. Observe **auto-approved** — YOLO mode bypasses file operation confirmation.
117+
118+
#### Expected Result
119+
- Global Auto-Approve bypasses ALL tool categories regardless of individual
120+
rules or approval lists.
121+
122+
#### 📸 Key Screenshots
123+
- [ ] `curl` auto-approved despite deny rule.
124+
- [ ] MCP tool auto-approved without prior approval.
125+
- [ ] File operation auto-approved.

0 commit comments

Comments
 (0)