From 0acfdb938df4de438da7be6e925cb5468ac7fefa Mon Sep 17 00:00:00 2001 From: hugocasa Date: Thu, 3 Dec 2026 09:43:32 +0100 Subject: [PATCH] feat: one per-workspace access list on the consent page and token forms, in place of the narrowing alert Co-Authored-By: Claude Opus 5.5 --- .../lib/components/mcp/McpAccessPicker.svelte | 43 +------- .../mcp/McpWorkspaceAccessList.svelte | 21 +++- .../components/mcp/accessNarrowing.test.ts | 31 ------ .../src/lib/components/mcp/accessNarrowing.ts | 38 ------- .../components/mcp/workspaceAccess.test.ts | 14 +++ .../src/lib/components/mcp/workspaceAccess.ts | 28 +++++ .../components/settings/CreateToken.svelte | 14 ++- .../settings/EditTokenScopesModal.svelte | 25 ++++- .../oauth/mcp_authorize/+page@(root).svelte | 100 +++++++----------- 9 files changed, 125 insertions(+), 189 deletions(-) delete mode 100644 frontend/src/lib/components/mcp/accessNarrowing.test.ts delete mode 100644 frontend/src/lib/components/mcp/accessNarrowing.ts diff --git a/frontend/src/lib/components/mcp/McpAccessPicker.svelte b/frontend/src/lib/components/mcp/McpAccessPicker.svelte index 28b7f0d12e..bf6aee8a9b 100644 --- a/frontend/src/lib/components/mcp/McpAccessPicker.svelte +++ b/frontend/src/lib/components/mcp/McpAccessPicker.svelte @@ -15,16 +15,6 @@ full: ['mcp:all', MCP_SESSION] } - /** What each access level lets the client do. */ - export const ACCESS_HINTS: Record = { - full: 'Everything you can do yourself: explore, write, test and deploy drafts, and run.', - read_run: - 'Explore, and run deployed scripts, flows and agents. The client changes nothing itself; what it runs can.', - read: 'Explore and read. Nothing is run or changed.', - selected: - 'The scripts and flows you pick, each as its own tool, and nothing else. To share a few automations.' - } - /** The access a token's MCP scopes give: `mcp:all` and how it is narrowed, or else a * selection of scripts, flows and endpoints. */ export function mcpAccessOf(scopes: string[]): McpAccess { @@ -42,17 +32,11 @@ import McpToolsModal from './McpToolsModal.svelte' import { Button } from '$lib/components/common' import type { Snippet } from 'svelte' - import { resource } from 'runed' - import Alert from '$lib/components/common/alert/Alert.svelte' - import { resolveSessionAccess } from '$lib/components/copilot/chat/global/sessionAccess' - import { accessNarrowing } from './accessNarrowing' - import { userWorkspaces } from '$lib/stores' + import { ACCESS_HINTS } from './workspaceAccess' interface Props { /** The workspace the selection picker browses. */ workspaceId: string - /** The workspaces the token reaches, to warn where one holds it to less than `access`. */ - workspaces?: string[] /** The token's MCP scopes, the workspace list aside. */ scopes?: string[] access?: McpAccess @@ -67,7 +51,6 @@ let { workspaceId, - workspaces = [], scopes = $bindable(), access = $bindable(), initialScopes = [], @@ -103,21 +86,6 @@ let toolsOpen = $state(false) const toolsetAccess = $derived(access === 'selected' ? undefined : access) - - // Each workspace's access, as the chat resolves it, to compare with the level picked. - const workspaceAccess = resource( - // Rerun once the workspace list loads: until then a role reads as its legacy defaults. - () => ({ ids: [...workspaces], roles: $userWorkspaces }), - ({ ids }) => Promise.all(ids.map(async (id) => ({ id, there: await resolveSessionAccess(id) }))) - ) - const narrowed = $derived( - access - ? (workspaceAccess.current ?? []).flatMap(({ id, there }) => { - const why = accessNarrowing(access!, there) - return why ? [{ id, why }] : [] - }) - : [] - )
@@ -135,15 +103,6 @@
{/if} - {#if narrowed.length > 0} - -
    - {#each narrowed as { id, why } (id)} -
  • In {id}, {why}.
  • - {/each} -
-
- {/if} {@render afterAccess?.()} {#if access === 'selected'} diff --git a/frontend/src/lib/components/mcp/McpWorkspaceAccessList.svelte b/frontend/src/lib/components/mcp/McpWorkspaceAccessList.svelte index 1443ea1852..a1aa333862 100644 --- a/frontend/src/lib/components/mcp/McpWorkspaceAccessList.svelte +++ b/frontend/src/lib/components/mcp/McpWorkspaceAccessList.svelte @@ -3,8 +3,15 @@ import type { McpWorkspaceAccess } from '$lib/gen' import type { McpAccess } from './McpAccessPicker.svelte' import Popover from '$lib/components/Popover.svelte' + import Tooltip from '$lib/components/Tooltip.svelte' import { Badge } from '$lib/components/common' - import { accessLabel, connectsSeparately, restriction, workspaceMcpUrl } from './workspaceAccess' + import { + accessHint, + accessLabel, + connectsSeparately, + restriction, + workspaceMcpUrl + } from './workspaceAccess' interface Props { workspaces: McpWorkspaceAccess[] @@ -12,24 +19,27 @@ covered: string[] all: boolean access: McpAccess + title?: string } - let { workspaces, covered, all, access }: Props = $props() + let { workspaces, covered, all, access, title }: Props = $props() const listed = $derived(workspaces.filter((w) => all || covered.includes(w.id))) {#if listed.length > 0}
-

What it gets

+ {#if title} +

{title}

+ {/if}
    {#each listed as workspace (workspace.id)} {@const separate = connectsSeparately(workspace, all, covered, access)} {@const restricted = restriction(workspace, access)}
  • -
    +
    {workspace.name} - + {accessLabel(workspace, access)}{separate ? ', connect separately' : ''} {#if restricted} @@ -39,6 +49,7 @@ Restricted {/if} + {accessHint(workspace, access)}
    {#if separate} diff --git a/frontend/src/lib/components/mcp/accessNarrowing.test.ts b/frontend/src/lib/components/mcp/accessNarrowing.test.ts deleted file mode 100644 index 16b8e6b8f5..0000000000 --- a/frontend/src/lib/components/mcp/accessNarrowing.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { accessNarrowing } from './accessNarrowing' -import { - capabilitiesForRole, - fullSessionAccess -} from '$lib/components/copilot/chat/global/sessionAccess' -import { NO_RUN_ACCESS, USE_MODE_ACCESS } from '$lib/components/copilot/chat/sessionCapabilities' -import { FULL_CAPABILITIES } from '$lib/roleCapabilities' - -describe('accessNarrowing', () => { - it('says nothing where the workspace holds the token to what was picked', () => { - for (const picked of ['full', 'read_run', 'read', 'selected'] as const) - expect(accessNarrowing(picked, fullSessionAccess())).toBeUndefined() - expect(accessNarrowing('read_run', USE_MODE_ACCESS)).toBeUndefined() - expect(accessNarrowing('read', NO_RUN_ACCESS)).toBeUndefined() - }) - - it('names how a workspace narrows each level', () => { - expect(accessNarrowing('read_run', NO_RUN_ACCESS)).toContain('only reads') - expect(accessNarrowing('selected', NO_RUN_ACCESS)).toContain('no tools') - expect(accessNarrowing('full', USE_MODE_ACCESS)).toContain('protected') - const noCode = capabilitiesForRole({ - isAdmin: false, - deployRulesPass: false, - capabilities: { ...FULL_CAPABILITIES, code: false, flows: 'compose', apps: 'compose' } - }) - expect(accessNarrowing('full', noCode)).toBe( - "your role can't build scripts and the deploy rules don't let you deploy, so the client can't either" - ) - }) -}) diff --git a/frontend/src/lib/components/mcp/accessNarrowing.ts b/frontend/src/lib/components/mcp/accessNarrowing.ts deleted file mode 100644 index 28d6dde92f..0000000000 --- a/frontend/src/lib/components/mcp/accessNarrowing.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { - SessionAccess, - SessionCapability -} from '$lib/components/copilot/chat/sessionCapabilities' -import type { McpAccess } from './McpAccessPicker.svelte' - -const BUILDS: [SessionCapability, string][] = [ - ['write_draft', 'scripts'], - ['write_flow_draft', 'flows'], - ['write_app_draft', 'apps'], - ['write_schedule_draft', 'schedules'], - ['write_trigger_draft', 'triggers'] -] - -/** How a workspace narrows the access picked for a token, read from the session access the chat - * resolves there (`resolveSessionAccess`), the twin of what the MCP server holds the token to. */ -export function accessNarrowing(picked: McpAccess, there: SessionAccess): string | undefined { - if (picked === 'read') return undefined - if (!there.has('run')) - return picked === 'selected' - ? "your role can't run anything, so the client gets no tools" - : "your role can't run anything, so the client only reads" - if (picked !== 'full') return undefined - if (!there.has('modify_workspace')) - return 'it is protected against direct changes, so the client only reads and runs' - const cannot = BUILDS.filter(([cap]) => !there.has(cap)).map(([, what]) => what) - const parts: string[] = [] - if (cannot.length > 0) parts.push(`your role can't build ${listed(cannot)}`) - if (!there.has('deploy')) parts.push("the deploy rules don't let you deploy") - if (parts.length === 0) return undefined - return `${parts.join(' and ')}, so the client can't either` -} - -function listed(items: string[]): string { - return items.length === 1 - ? items[0] - : `${items.slice(0, -1).join(', ')} or ${items[items.length - 1]}` -} diff --git a/frontend/src/lib/components/mcp/workspaceAccess.test.ts b/frontend/src/lib/components/mcp/workspaceAccess.test.ts index 4c45262798..02fface3ab 100644 --- a/frontend/src/lib/components/mcp/workspaceAccess.test.ts +++ b/frontend/src/lib/components/mcp/workspaceAccess.test.ts @@ -4,6 +4,7 @@ import { accessLabel, connectsSeparately, defaultConnection, + narrows, restriction, servedOn, connectionToolset, @@ -85,3 +86,16 @@ it('tools are part of a connection to their workspace alone', () => { expect(connectsSeparately(ws('a', 'runnables'), true, [], 'read')).toBe(false) expect(connectsSeparately(ws('a', 'read_only'), true, [], 'full')).toBe(false) }) + +describe('narrows', () => { + it('flags a workspace giving less or other than the pick', () => { + expect(narrows(ws('a', 'build_and_run'), 'full')).toBe(false) + expect(narrows(ws('a', 'read_and_run'), 'full')).toBe(true) + expect(narrows(ws('a', 'run_and_edit'), 'full')).toBe(true) + expect(narrows(ws('a', 'read_only'), 'read_run')).toBe(true) + expect(narrows(ws('a', 'read_only'), 'read')).toBe(false) + expect(narrows(ws('a', 'runnables'), 'full')).toBe(true) + expect(narrows(ws('a', 'read_only'), 'selected')).toBe(true) + expect(narrows(ws('a', 'off'), 'read')).toBe(true) + }) +}) diff --git a/frontend/src/lib/components/mcp/workspaceAccess.ts b/frontend/src/lib/components/mcp/workspaceAccess.ts index 61ee23f384..c98529f1b4 100644 --- a/frontend/src/lib/components/mcp/workspaceAccess.ts +++ b/frontend/src/lib/components/mcp/workspaceAccess.ts @@ -5,6 +5,16 @@ import type { ToolsetLevel } from './toolsets.svelte' export type WorkspaceAccess = McpWorkspaceAccess['access'] +/** What each access level lets the client do. */ +export const ACCESS_HINTS: Record = { + full: 'Everything you can do yourself: explore, write, test and deploy drafts, and run.', + read_run: + 'Explore, and run deployed scripts, flows and agents. The client changes nothing itself; what it runs can.', + read: 'Explore and read. Nothing is run or changed.', + selected: + 'The scripts and flows you pick, each as its own tool, and nothing else. To share a few automations.' +} + const LABELS: Record = { build_and_run: 'Build and run', run_and_edit: 'Build and run', @@ -127,3 +137,21 @@ export function connectsSeparately( ) { return workspace.access === 'runnables' && picked !== 'read' && (all || covered.length > 1) } + +/** What a level means in a workspace, and whether its role set it. */ +export function accessHint(workspace: McpWorkspaceAccess, picked: McpAccess): string { + const level = toolsetLevel(workspace, picked) + const hint = !givesAnything(workspace, picked) + ? 'Nothing the client can use there with this access.' + : workspace.access === 'runnables' + ? 'The scripts and flows your role offers, each as its own tool, and nothing else.' + : ACCESS_HINTS[level ?? picked] + return workspace.limited ? `${hint} Set by your role.` : hint +} + +/** Whether a workspace gives less than, or other than, the `picked` access. */ +export function narrows(workspace: McpWorkspaceAccess, picked: McpAccess): boolean { + if (!givesAnything(workspace, picked) || restriction(workspace, picked)) return true + if (picked === 'read' || picked === 'selected') return false + return workspace.access === 'runnables' || toolsetLevel(workspace, picked) !== picked +} diff --git a/frontend/src/lib/components/settings/CreateToken.svelte b/frontend/src/lib/components/settings/CreateToken.svelte index c9273ed894..70c31630bb 100644 --- a/frontend/src/lib/components/settings/CreateToken.svelte +++ b/frontend/src/lib/components/settings/CreateToken.svelte @@ -32,7 +32,7 @@ import Select from '../select/Select.svelte' import Section from '../Section.svelte' import ClipboardPanel from '../details/ClipboardPanel.svelte' - import { workspaceMcpUrl } from '../mcp/workspaceAccess' + import { narrows, workspaceMcpUrl } from '../mcp/workspaceAccess' import McpAccessPicker, { type McpAccess } from '../mcp/McpAccessPicker.svelte' import McpWorkspaceAccessList from '../mcp/McpWorkspaceAccessList.svelte' import MultiSelect from '../select/MultiSelect.svelte' @@ -387,10 +387,10 @@ (w) => w.id === mcpBoundWorkspace && w.access === 'runnables' ) ) - // Shown only where a role sets the access: elsewhere the picked access is what the token gets. - const mcpRoleLimited = $derived( + // Shown only where a workspace gives other than the picked access. + const mcpNarrowed = $derived( !!mcpWorkspaceAccess.current?.some( - (w) => w.limited && (mcpAllWorkspaces || mcpWorkspaces.includes(w.id)) + (w) => (mcpAllWorkspaces || mcpWorkspaces.includes(w.id)) && narrows(w, mcpAccess) ) ) const mcpUrl = $derived( @@ -428,9 +428,6 @@ {/if} w.id) - : mcpWorkspaces} bind:scopes={mcpScopes} bind:access={() => mcpAccess, setMcpAccess} showTools @@ -456,12 +453,13 @@ {/if} {/snippet} - {#if mcpRoleLimited} + {#if mcpNarrowed} {/if} {#if !mcpOnly} diff --git a/frontend/src/lib/components/settings/EditTokenScopesModal.svelte b/frontend/src/lib/components/settings/EditTokenScopesModal.svelte index 47c5993b20..84dfb62699 100644 --- a/frontend/src/lib/components/settings/EditTokenScopesModal.svelte +++ b/frontend/src/lib/components/settings/EditTokenScopesModal.svelte @@ -1,6 +1,9 @@