diff --git a/backend/windmill-api/src/mcp/core.rs b/backend/windmill-api/src/mcp/core.rs index 50be927d8d..e0b59082e6 100644 --- a/backend/windmill-api/src/mcp/core.rs +++ b/backend/windmill-api/src/mcp/core.rs @@ -499,7 +499,7 @@ impl McpBackend for WindmillBackend { pub struct McpSelection; /// The scopes that give the whole of MCP at some access level, rather than a selection. -const ACCESS_LEVELS: [&str; 3] = ["mcp:all", "mcp:run", "mcp:read"]; +pub(crate) const ACCESS_LEVELS: [&str; 3] = ["mcp:all", "mcp:run", "mcp:read"]; /// MCP scopes without an access level: favorites, chosen scripts, flows, endpoints or hub apps. fn scoped_to_selection(scopes: &[String]) -> bool { diff --git a/backend/windmill-api/src/mcp/oauth_server.rs b/backend/windmill-api/src/mcp/oauth_server.rs index 8d4c7ec7ee..b5b2e2ebb0 100644 --- a/backend/windmill-api/src/mcp/oauth_server.rs +++ b/backend/windmill-api/src/mcp/oauth_server.rs @@ -890,8 +890,9 @@ async fn oauth_approve_inner( .collect(); // On every access level, so the grant keeps the session toolset if it is later raised to // `mcp:all`, which without the marker means the tools server on its URLs. - let access_level = ["mcp:all", "mcp:run", "mcp:read"]; - if scopes.iter().any(|s| access_level.contains(&s.as_str())) + if scopes + .iter() + .any(|s| super::core::ACCESS_LEVELS.contains(&s.as_str())) && !scopes.iter().any(|s| s == SESSION_SCOPE) { scopes.push(SESSION_SCOPE.to_string()); diff --git a/backend/windmill-mcp/src/common/scope.rs b/backend/windmill-mcp/src/common/scope.rs index f2e832feaa..95adb3b553 100644 --- a/backend/windmill-mcp/src/common/scope.rs +++ b/backend/windmill-mcp/src/common/scope.rs @@ -164,8 +164,8 @@ fn pattern_covers(caller: &str, requested: &str) -> bool { /// URL, which an older selection, carrying none of the newer scopes, still does. pub const RUNNABLES_AS_TOOLS_SCOPE: &str = "mcp:runnables_as_tools"; -/// Added server-side to an `mcp:all` OAuth grant so the tools server's URLs serve it the AI -/// session's toolset. Grants nothing: an un-narrowed `mcp:all` token without it predates the +/// Added server-side to every access-level OAuth grant so the tools server's URLs serve it the +/// AI session's toolset, including once it is raised to `mcp:all`. Grants nothing: an un-narrowed `mcp:all` token without it predates the /// session toolset there, and must keep the tools server's endpoint tools. pub const SESSION_SCOPE: &str = "mcp:session"; diff --git a/backend/windmill-mcp/src/server/session.rs b/backend/windmill-mcp/src/server/session.rs index b7fac23b43..529d975bca 100644 --- a/backend/windmill-mcp/src/server/session.rs +++ b/backend/windmill-mcp/src/server/session.rs @@ -25,7 +25,7 @@ use serde_json::Value; use std::borrow::Cow; use std::sync::Arc; -/// `mcp:all`, and no scope from outside `mcp:` that confines the token to some routes +/// An access level (`mcp:all`, `mcp:run`, `mcp:read`), and no scope from outside `mcp:` that confines the token to some routes /// or paths (`variables:read:f/x/*`): the tools call the API without a route scope, so /// that confinement would be lost here. The job tag fence is carried through instead. fn admits(scopes: &[String], all: bool) -> bool {