diff --git a/backend/.sqlx/query-44f272788e9dcceef20348675db1bb22391e9ac7b9c4d11786d59fa9b17fc8f9.json b/backend/.sqlx/query-44f272788e9dcceef20348675db1bb22391e9ac7b9c4d11786d59fa9b17fc8f9.json new file mode 100644 index 0000000000..e2a992cd8b --- /dev/null +++ b/backend/.sqlx/query-44f272788e9dcceef20348675db1bb22391e9ac7b9c4d11786d59fa9b17fc8f9.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT workspace.id, workspace.name FROM workspace\n JOIN usr ON usr.workspace_id = workspace.id\n WHERE usr.email = $1 AND usr.disabled = false AND workspace.deleted = false\n ORDER BY workspace.name", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false + ] + }, + "hash": "44f272788e9dcceef20348675db1bb22391e9ac7b9c4d11786d59fa9b17fc8f9" +} diff --git a/backend/.sqlx/query-cc2d27c55c3dac7b0f287b56c66ec1ee8856df25ebe62074bb1628ee7f39415b.json b/backend/.sqlx/query-ee761c085738bb22b01a48627e067b145f92f1c396817e4c13e50019fc085d6c.json similarity index 64% rename from backend/.sqlx/query-cc2d27c55c3dac7b0f287b56c66ec1ee8856df25ebe62074bb1628ee7f39415b.json rename to backend/.sqlx/query-ee761c085738bb22b01a48627e067b145f92f1c396817e4c13e50019fc085d6c.json index 8881f24f4d..22f1035e0c 100644 --- a/backend/.sqlx/query-cc2d27c55c3dac7b0f287b56c66ec1ee8856df25ebe62074bb1628ee7f39415b.json +++ b/backend/.sqlx/query-ee761c085738bb22b01a48627e067b145f92f1c396817e4c13e50019fc085d6c.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT workspace_id, is_admin, operator, workspace_role FROM usr\n WHERE email = $1 AND workspace_id = ANY($2) AND disabled = false", + "query": "SELECT workspace_id, username, is_admin, operator, workspace_role FROM usr\n WHERE email = $1 AND workspace_id = ANY($2) AND disabled = false", "describe": { "columns": [ { @@ -10,16 +10,21 @@ }, { "ordinal": 1, + "name": "username", + "type_info": "Varchar" + }, + { + "ordinal": 2, "name": "is_admin", "type_info": "Bool" }, { - "ordinal": 2, + "ordinal": 3, "name": "operator", "type_info": "Bool" }, { - "ordinal": 3, + "ordinal": 4, "name": "workspace_role", "type_info": "Varchar" } @@ -34,8 +39,9 @@ false, false, false, + false, true ] }, - "hash": "cc2d27c55c3dac7b0f287b56c66ec1ee8856df25ebe62074bb1628ee7f39415b" + "hash": "ee761c085738bb22b01a48627e067b145f92f1c396817e4c13e50019fc085d6c" } diff --git a/backend/tests/mcp_role_access.rs b/backend/tests/mcp_role_access.rs index e03719fe82..9154061983 100644 --- a/backend/tests/mcp_role_access.rs +++ b/backend/tests/mcp_role_access.rs @@ -194,6 +194,32 @@ async fn role_setting_caps_every_token(db: Pool) -> anyhow::Result<()> let out = call(DEFAULT, "ROLEUNBOUND_TOKEN", "list_workspaces", json!({})).await; assert!(out["result"].to_string().contains("read only"), "{out}"); + let listed = |bearer: &'static str| async move { + reqwest::Client::new() + .get(format!( + "http://localhost:{port}/api/mcp/gateway/oauth/server/workspace_access" + )) + .bearer_auth(bearer) + .send() + .await + .unwrap() + }; + let access: Value = listed("SECRET_TOKEN").await.json().await?; + let here = access + .as_array() + .unwrap() + .iter() + .find(|w| w["id"] == "test-workspace") + .unwrap(); + assert_eq!( + (&here["access"], &here["limited"]), + (&json!("read_only"), &json!(true)) + ); + assert!( + !listed("ROLEUNBOUND_TOKEN").await.status().is_success(), + "a scoped token must not list its owner's other workspaces" + ); + set_access(&db, json!({"access": "off"})).await; assert!(tools(port, WORKSPACE, "ROLESEL_TOKEN").await.is_empty()); assert_eq!( diff --git a/docs/workspace-roles.md b/docs/workspace-roles.md index 2d5c6984b5..24a625b4f8 100644 --- a/docs/workspace-roles.md +++ b/docs/workspace-roles.md @@ -75,6 +75,8 @@ it must not restrict a role, cost a seat or reach an authoring gate. `runnables` gets the tools server whatever the token, and an `mcp:all` token under another limit the session toolset, since endpoint tools are never served under one. Where a connection covers several workspaces the list is one for all, so the limit refuses at call time. +- The connect page and the MCP tab of the home page read `workspace_access`, the same computation + as `list_workspaces`, so a user is shown what they get rather than what they ask for. - A selection intersects with the token's own (`McpScopeConfig::limited_by`). - A lapsed license freezes it as it does roles: it keeps applying and can be removed, not changed. On Community it is ignored and refused at write. diff --git a/frontend/src/lib/components/mcp/McpWorkspaceAccessList.svelte b/frontend/src/lib/components/mcp/McpWorkspaceAccessList.svelte index e471593965..1340344ac8 100644 --- a/frontend/src/lib/components/mcp/McpWorkspaceAccessList.svelte +++ b/frontend/src/lib/components/mcp/McpWorkspaceAccessList.svelte @@ -22,7 +22,7 @@

What it gets