diff --git a/backend/windmill-common/src/roles.rs b/backend/windmill-common/src/roles.rs index df3b432120..3fd91e8db3 100644 --- a/backend/windmill-common/src/roles.rs +++ b/backend/windmill-common/src/roles.rs @@ -1108,10 +1108,6 @@ pub async fn validate_instance_roles_write( )) })?; } - log_mcp_role_changes(next.iter().map(|r| { - let before = current.iter().find(|c| c.name == r.name); - (before.and_then(|c| c.mcp.as_ref()), r.mcp.as_ref()) - })); Ok(()) } @@ -1140,10 +1136,19 @@ pub fn log_mcp_role_changes<'a>( /// by billing on every replica, so it is rebuilt here rather than on the notify that drops the /// role caches. pub async fn after_instance_roles_write(db: &DB) -> Result<()> { + // What the write replaced: validating it read the cache. + let previous = cached_instance_roles(); invalidate_all_roles_cache(); let mut tx = db.begin().await?; sync_role_seats(&mut tx, None).await?; tx.commit().await?; + if let Some(previous) = previous { + let next = instance_roles(db).await?; + log_mcp_role_changes(next.iter().map(|r| { + let before = previous.iter().find(|c| c.name == r.name); + (before.and_then(|c| c.mcp.as_ref()), r.mcp.as_ref()) + })); + } Ok(()) } diff --git a/backend/windmill-mcp/src/common/scope.rs b/backend/windmill-mcp/src/common/scope.rs index 63d62cbc5e..d344866fe1 100644 --- a/backend/windmill-mcp/src/common/scope.rs +++ b/backend/windmill-mcp/src/common/scope.rs @@ -67,8 +67,16 @@ impl McpScopeConfig { pub fn limited_by(mut self, limit: &McpLimit) -> Self { self.no_endpoints = true; self.endpoints.clear(); + // Every limit leaves at most deployed runnables to run, which a Hub script is not. + self.hub_apps = None; match limit { - McpLimit::ReadAndRun => {} + McpLimit::ReadAndRun => { + // `all` reaches any Hub script by name; its `*` selection stays. + if self.all { + self.all = false; + self.granular = true; + } + } McpLimit::ReadOnly | McpLimit::Off => self.read_only = true, McpLimit::Runnables { scripts, flows } => { // Favorites name no path: the listing's favorites join keeps narrowing them. @@ -86,7 +94,6 @@ impl McpScopeConfig { } self.all = false; self.granular = true; - self.hub_apps = None; } } self @@ -432,6 +439,12 @@ mod tests { assert!(!parse(&["mcp:all", "mcp:read_run"]).limited_by(&limit).read_run); assert!(parse(&["mcp:all", "mcp:read_only"]).limited_by(&limit).read_only); + for scopes in [&["mcp:all"][..], &["mcp:scripts:f/a/*", "mcp:hub:slack"][..]] { + let runs = parse(scopes).limited_by(&McpLimit::ReadAndRun); + assert!(runs.is_allowed("script", "f/a/x") && !runs.read_only); + assert!(!runs.all && runs.hub_apps.is_none(), "{scopes:?}"); + } + let favorites = parse(&["mcp:favorites"]).limited_by(&limit); assert!(favorites.favorites && favorites.granular); assert!(!favorites.is_allowed("script", "f/b/x")); diff --git a/cli/test/audit_token_commands.test.ts b/cli/test/audit_token_commands.test.ts index 5588bfa1e5..1205fa09dd 100644 --- a/cli/test/audit_token_commands.test.ts +++ b/cli/test/audit_token_commands.test.ts @@ -177,13 +177,13 @@ describe("token command", () => { const created = await backend.runCLICommand( [ "token", "create", "--label", "cli-scoped-token", - "--scope", "jobs:run", "--scope", "mcp:workspaces:a,b", + "--scope", "mcp:all", "--scope", "mcp:workspaces:a,b", ], tempDir ); expect(created.code).toEqual(0); const token = await scopesOf(); - expect(token.scopes).toEqual(["jobs:run", "mcp:workspaces:a,b"]); + expect(token.scopes).toEqual(["mcp:all", "mcp:workspaces:a,b"]); const narrowed = await backend.runCLICommand( ["token", "update-scopes", token.token_prefix, "--scope", "scripts:read"],