Skip to content

Commit 3edcbea

Browse files
authored
feat: MCP permission model + unified policy enforcement + settings UI (Phase 4) (#129)
* feat(mcp-bridge): enforce McpPolicy + flat /tools shape - bump data-studio-agent to feat/mcp-permissions (confirm_destructive) - McpConfig.policy field (serde default, backward compatible) - pure check_policy() gates /invoke: mode → allowlist → read-only override → confirm_destructive - invoke_with_policy() extracted for testability - /tools returns flat [{name, description, inputSchema, metadata:{riskLevel, requiredPermission}}] filtered by policy - get_mcp_status returns policy; save_mcp_config accepts policy arg (preserves existing on None) * feat(settings): MCP permission UI — mode, confirm toggle, allowlist, connection overrides - Permission Mode RadioGroup (ReadOnly/DataReadWrite/FullAccess) - Confirm Destructive Switch (gated on FullAccess) - Connection allowlist Checkbox list (from connectionStore) - Per-connection read-only Switch list - snake_case policy round-trip via save_mcp_config - i18n: 15 new pages.settings.mcp.* keys (en/zh) * feat(agent): enforce server-side McpPolicy Deny in built-in agent loop - bump data-studio-agent to 49f89a4 (PolicyAction + should_deny param) - run_agent_loop passes should_deny closure: loads McpPolicy from mcp-config, denies tools where policy.allows(risk, conn_id) is false - Deny short-circuits before confirmation await (no frontend round-trip) * fix: review issues — allowlist fallback bypass, empty-state allowlist UX, confirm_destructive defaults - agent_adapters: deny DB capabilities when allowlist set but connection_id omitted (fallback connection would bypass the allowlist); AppLocal tools exempt - mcp-bridge.vue: default confirmDestructive true (match Rust default) - onModeChange no longer resets confirm_destructive when leaving FullAccess - allowlist: explicit enable switch — empty state shows disabled checkboxes * feat(settings): sync dockit MCP UI redesign + McpAction + restart feedback - bump data-studio-agent to 6fae4e5 (default DataReadWrite, McpAction) - tests updated for DataReadWrite default (rejects Destructive) - UI: Font Weight card-style permission mode (single row + desc), Port + Auto-start in one card, Confirm Destructive inside mode card (shown only for FullAccess, defaults on) - Connection Access merged scrollable table with per-connection Read/Write/Delete actions (McpAction) - Restart Bridge: phase feedback (shutting-down/starting), spinner, disabled during restart, 60s timeout, success/error toasts - i18n: new keys (en/zh) * feat(mcp-bridge): policy notice in tools/list + actionable deny errors - tools_payload appends Neon-style 'MCP policy notice' to surviving tool descriptions when any capability class is gated (mode / confirm toggle), so the agent learns gated capabilities exist and how to lift the gate - check_policy errors now carry deny_reason() guidance the agent can relay to the user (requires X mode / enable Confirm Destructive / connection not in allowlist) - bump data-studio-agent to d492b96 for deny_reason()/policy_notice() - tests: notice presence/absence, guidance in deny error * fix(settings): permission mode row layout, port placeholder, MCP tab order - cn() now uses tailwind-merge (was clsx-only) — resolves grid/flex conflicts in shadcn components. Permission Mode cards render in one row instead of stacking vertically - Port input shows default port 9121 as placeholder when unset - Settings tab order: ... → AI → MCP → JRE → About (MCP right after LLM) * style: cargo fmt across backend modules * chore(deps): pin data-studio-agent to latest release tag data-studio-mcp-v0.1.4 Switch from dev branch feat/mcp-permissions to the published v0.1.4 release (038f6f6) — same tree as master with full Phase 4 code. * chore(deps): pin data-studio-agent to crate release tag v0.1.5 data-studio-mcp-v0.1.4 is the npm package for code agents; the desktop clients use the Rust crate, now released as v0.1.5 (f4871a4). * fix(mcp): review fixes — policy hot-swap, allowlist invoke guard, restart dead-end - save_mcp_policy: persist + hot-swap policy into the running bridge via a shared Arc<RwLock<McpPolicy>>, so permission toggles no longer restart it - save_mcp_config: new restart param forces a start even when auto_start is off; no longer shuts down a running bridge on config-only saves - allowlist bypass: /invoke denies non-AppLocal capabilities without a connection_id when the allowlist is set; /tools filters connections to allowlisted IDs - agent loop: reload McpPolicy per tool decision instead of snapshotting at loop start - settings UI: onModeChange double-fire guard, restart button re-enabled on failure, allowlist filter drops null ids
1 parent 744c09e commit 3edcbea

25 files changed

Lines changed: 1219 additions & 227 deletions

‎package-lock.json‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"pinia-plugin-persistedstate": "^4.7.1",
9595
"radix-vue": "^1.9.17",
9696
"sql-formatter": "^15.8.1",
97+
"tailwind-merge": "^3.6.0",
9798
"ulidx": "^2.4.1",
9899
"unocss-preset-animations": "^1.3.0",
99100
"vue": "^3.5.13",

‎src-tauri/Cargo.lock‎

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src-tauri/Cargo.toml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ rust_xlsxwriter = "0.64"
7777
calamine = "0.22"
7878

7979
# Agent / LLM dependencies
80-
# data-studio-agent: local checkout for active development.
81-
# Revert to release when ready: { git = "https://github.com/geek-fun/data-studio-agent.git", tag = "v0.1.2" }
8280
reqwest = { version = "0.12", default-features = false, features = [
8381
"json",
8482
"rustls-tls",
@@ -89,7 +87,8 @@ http = "1"
8987
log = "0.4"
9088
futures = "0.3"
9189
rand = "0.8"
92-
data-studio-agent = { git = "https://github.com/geek-fun/data-studio-agent.git", branch = "feat/unified-capability-types" }
90+
# data-studio-agent: pinned to latest release tag.
91+
data-studio-agent = { git = "https://github.com/geek-fun/data-studio-agent.git", tag = "v0.1.5" }
9392

9493
# Archive extraction (JRE downloads)
9594
flate2 = "1.0"

‎src-tauri/src/agent_adapters.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use std::collections::HashMap;
88
use std::sync::Arc;
99

10+
use crate::mcp_bridge::McpConfig;
1011
use data_studio_agent as lib;
1112
use data_studio_agent::storage;
1213
use data_studio_agent::traits::{CancelMap, ConfirmMap, EventEmitter};
@@ -64,6 +65,31 @@ pub async fn run_agent_loop(
6465
.unwrap_or(false)
6566
};
6667

68+
let app_data_dir = app.path().app_data_dir().map_err(|e| e.to_string())?;
69+
let should_deny = move |tool_name: &str, conn_id: Option<&str>| -> bool {
70+
// Reload per call so permission changes made in Settings apply to the
71+
// next tool call instead of being snapshotted for the whole run.
72+
let policy = McpConfig::load(&app_data_dir).policy;
73+
match data_studio_agent::capabilities::registry::registry().get(tool_name) {
74+
Some(cap) => {
75+
// Allowlist set but no connection specified: a DB capability would
76+
// fall back to the default connection, bypassing the allowlist.
77+
// AppLocal tools (list_connections etc.) need no connection.
78+
if !policy.allowed_connection_ids.is_empty()
79+
&& conn_id.is_none()
80+
&& !matches!(
81+
cap.source_kind,
82+
data_studio_agent::capabilities::types::SourceKind::AppLocal
83+
)
84+
{
85+
return true;
86+
}
87+
!policy.allows(cap.risk_level, conn_id)
88+
}
89+
None => false,
90+
}
91+
};
92+
6793
lib::loop_runner::run_agent_loop(
6894
&session_id,
6995
&user_message,
@@ -76,6 +102,7 @@ pub async fn run_agent_loop(
76102
&confirm_map,
77103
&cancel_map,
78104
&is_parallel_ok,
105+
&should_deny,
79106
)
80107
.await
81108
}

‎src-tauri/src/capabilities/sql.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use crate::database::{DatabaseAdapter, QueryResult};
99
use crate::state::{ActiveConnection, ServerConfig};
1010

1111
use data_studio_agent::capabilities::registry::CapabilityRegistry;
12-
use data_studio_agent::capabilities::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};
12+
use data_studio_agent::capabilities::types::{
13+
Capability, CapabilityHandler, RiskLevel, SourceKind,
14+
};
1315

1416
fn app_handle() -> AppHandle {
1517
crate::APP_HANDLE

‎src-tauri/src/capabilities/sqlkit.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use serde_json::Value;
44
use tauri_plugin_store::StoreExt;
55

66
use data_studio_agent::capabilities::registry::CapabilityRegistry;
7-
use data_studio_agent::capabilities::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};
7+
use data_studio_agent::capabilities::types::{
8+
Capability, CapabilityHandler, RiskLevel, SourceKind,
9+
};
810

911
// ---------------------------------------------------------------------------
1012
// Connection store abstraction (testable via mockall)

0 commit comments

Comments
 (0)