feat: role mcp access as a select with what members get and the urls to share

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-03 17:02:33 +01:00
co-authored by Claude Opus 5.5
parent e232973ad0
commit 6e16b0a01d
3 changed files with 121 additions and 66 deletions
@@ -104,7 +104,10 @@
const flipDurationMs = 200
function addRole() {
rows = [...rows, { id: nextId++, name: '', label: '', capabilities: {}, mcp: undefined, open: true }]
rows = [
...rows,
{ id: nextId++, name: '', label: '', capabilities: {}, mcp: undefined, open: true }
]
}
function summary(caps: RoleCapabilities): string {
@@ -246,7 +249,7 @@
/>
<RoleMcpAccessEditor
setting={row.mcp}
canRun={caps.run}
{caps}
frozen={unlicensed}
disabled={loading}
onchange={(mcp) => (row.mcp = mcp)}
@@ -1,8 +1,9 @@
<script lang="ts">
import Select from '$lib/components/select/Select.svelte'
import Toggle from '$lib/components/Toggle.svelte'
import ClipboardPanel from '$lib/components/details/ClipboardPanel.svelte'
import { apiBaseUrl } from '$lib/apiBaseUrl.svelte'
import McpScopeSelector from '$lib/components/mcp/McpScopeSelector.svelte'
import type { McpRoleSetting } from '$lib/gen'
import type { McpRoleSetting, RoleCapabilities } from '$lib/gen'
import { MCP_ROLE_LIMIT_LABELS, mcpSettingError } from '$lib/workspaceRoles'
type Access = McpRoleSetting['access']
@@ -11,8 +12,8 @@
setting: McpRoleSetting | undefined
/** The limit of the layer below, which an unset `setting` inherits. */
instanceLimit?: McpRoleSetting
/** Whether the role may run anything; undefined while not known. */
canRun?: boolean
/** What the role allows; undefined while not known. */
caps?: RoleCapabilities
/** The workspace overriding the role. Without one the role is the instance's, which cannot
* choose scripts and flows: their paths are a workspace's. */
workspace?: string
@@ -25,7 +26,7 @@
let {
setting,
instanceLimit,
canRun,
caps,
workspace,
frozen = false,
disabled = false,
@@ -33,9 +34,12 @@
}: Props = $props()
const INHERIT = 'inherit'
const ROLE = 'follow_role'
const canRun = $derived(caps?.run)
function limitLabel(access: Access): string {
return access === 'follow_role' ? '' : MCP_ROLE_LIMIT_LABELS[access]
return access === ROLE ? 'What the role allows' : MCP_ROLE_LIMIT_LABELS[access]
}
function inheritedLabel(limit: McpRoleSetting): string {
@@ -43,48 +47,78 @@
return `From instance (${label.charAt(0).toLowerCase()}${label.slice(1)})`
}
const effective = $derived(setting ?? instanceLimit)
const limited = $derived(effective != undefined && effective.access !== 'follow_role')
const effective = $derived(setting?.access ?? instanceLimit?.access ?? ROLE)
// Without an instance limit, following the role is storing nothing.
const selected = $derived(setting?.access ?? (instanceLimit ? INHERIT : ROLE))
// Both run, so a role that cannot run gets nothing from them. One that is stored stays
// selectable, with a hint.
const RUNS = ['read_run', 'runnables']
const runRedundant = (value: string) =>
canRun === false && RUNS.includes(value) && setting?.access !== value
// Only what lowers the access: a role that cannot run already reads only, and gets nothing
// from running tools. A stored entry stays listed.
const lowers = (value: Access) =>
value === 'off' || (canRun !== false && (workspace !== undefined || value !== 'runnables'))
const items = $derived([
...(instanceLimit ? [{ value: INHERIT, label: inheritedLabel(instanceLimit) }] : []),
...Object.entries(MCP_ROLE_LIMIT_LABELS)
.filter(
([value]) => value === setting?.access || (!frozen && (workspace || value !== 'runnables'))
const items = $derived(
[
...(instanceLimit ? [INHERIT] : []),
ROLE,
...(Object.keys(MCP_ROLE_LIMIT_LABELS) as Access[]).filter(
(value) => value === setting?.access || (!frozen && lowers(value))
)
.map(([value, label]) => ({
]
// Frozen, a stored setting can only be removed.
.filter(
(value) => !frozen || value === selected || value === (instanceLimit ? INHERIT : ROLE)
)
.filter((value, i, all) => all.indexOf(value) === i)
.map((value) => ({
value,
label,
...(runRedundant(value)
? { disabled: true, subtitle: 'This role cannot run scripts and flows' }
: {})
label: value === INHERIT ? inheritedLabel(instanceLimit!) : limitLabel(value as Access)
}))
])
)
const error = $derived(mcpSettingError(setting, !workspace))
// Frozen, a stored setting can only be removed, so the toggle works only where removing it is
// what flips it. Elsewhere the select's first entry removes it.
const toggleDisabled = $derived(
disabled || (frozen && (!setting || limited === (instanceLimit != undefined)))
)
const joined = (items: string[]) =>
items.length > 1 ? `${items.slice(0, -1).join(', ')} and ${items.at(-1)}` : (items[0] ?? '')
function setLimited(on: boolean) {
if (on === limited) return
if (frozen || (on && instanceLimit)) return onchange(undefined)
if (on) return onchange({ access: canRun === false ? 'read_only' : 'read_run' })
onchange(instanceLimit ? { access: 'follow_role' } : undefined)
}
// What members of the role get, in the role's own terms: an operator on no limit is served the
// full toolset, but only what the role allows works.
const gets = $derived.by(() => {
if (effective === 'off') return 'Nothing: members of this role cannot connect an AI client.'
if (canRun === false) {
return effective === 'runnables'
? 'No tools: this role cannot run scripts and flows.'
: 'Explore and read. Nothing is run.'
}
if (effective === 'runnables') return 'These scripts and flows, each as its own tool.'
if (effective === 'read_only') return 'Explore and read. Nothing is run.'
if (effective === 'read_run') return 'Explore, and run deployed scripts, flows and agents.'
if (!caps) return 'Everything the role allows.'
const builds = [
...(caps.code ? ['scripts'] : []),
...(caps.flows !== 'none' ? ['flows'] : []),
...(caps.apps !== 'none' ? ['apps'] : [])
]
const manages = [
...(caps.manage_schedules ? ['schedules'] : []),
...(caps.manage_triggers ? ['triggers'] : [])
]
return [
'Explore, run',
...(builds.length ? [`build ${joined(builds)}`] : []),
...(manages.length ? [`manage ${joined(manages)}`] : [])
]
.join(', ')
.concat(builds.length ? '.' : '. No building.')
})
const globalUrl = $derived(`${apiBaseUrl('mcp')}/api/mcp`)
const workspaceUrl = $derived(workspace ? `${apiBaseUrl('mcp')}/api/mcp/w/${workspace}/mcp` : '')
function setAccess(value: string) {
if (value === (setting?.access ?? INHERIT)) return
onchange(value === INHERIT ? undefined : { access: value as Access })
if (value === selected) return
if (value === INHERIT) return onchange(undefined)
if (value === ROLE) return onchange(instanceLimit ? { access: ROLE } : undefined)
onchange({ access: value as Access })
}
function setPaths(scripts: string[], flows: string[]) {
@@ -118,42 +152,27 @@
<div class="flex flex-col gap-2">
<div class="flex items-center gap-4">
<div class="flex flex-col grow min-w-0">
<span class="text-xs font-semibold text-emphasis">Limit MCP access</span>
<span class="text-xs font-semibold text-emphasis">MCP access</span>
<span class="text-2xs text-secondary">
Restrict what an AI client may do for members of this role, admins holding it included. A
limit never gives more than the role allows. Does not affect the chat in Windmill.
What an AI client may do for members of this role, admins holding it included, at most what
the role allows. Does not affect the chat in Windmill.
</span>
</div>
<!-- Lines up with the toggles and status column of RoleCapabilitiesEditor. -->
<div class="flex justify-end w-60 shrink-0">
<Toggle
size="xs"
ariaLabel="Limit MCP access"
disabled={toggleDisabled}
bind:checked={() => limited, (on) => setLimited(on ?? false)}
/>
</div>
<div class="w-32 shrink-0"></div>
</div>
{#if limited}
<div class="w-72">
<div class="w-60 shrink-0">
<Select
size="sm"
{items}
disabled={disabled || (frozen && !setting)}
bind:value={() => setting?.access ?? INHERIT, (v) => v && setAccess(v)}
bind:value={() => selected, (v) => v && setAccess(v)}
/>
</div>
{#if canRun === false && effective?.access === 'read_run'}
<span class="text-2xs text-secondary">
This role cannot run scripts and flows, so its members get read only.
</span>
{:else if canRun === false && effective?.access === 'runnables'}
<span class="text-2xs text-secondary">
This role cannot run scripts and flows, so its members get no tools.
</span>
{/if}
{/if}
<div class="w-32 shrink-0"></div>
</div>
<span class="text-2xs text-primary">
<span class="font-semibold">Members get:</span>
{gets}
</span>
{#if setting?.access === 'runnables'}
{#if frozen || disabled}
<span class="text-2xs text-secondary font-mono break-all">
@@ -176,4 +195,37 @@
<span class="text-2xs text-red-600 dark:text-red-400">{error}</span>
{/if}
{/if}
{#if effective === 'runnables'}
{#if workspace && !error && canRun !== false}
<div class="flex flex-col gap-1">
<span class="text-2xs font-semibold text-emphasis">URL for members of this role</span>
<ClipboardPanel content={workspaceUrl} size="sm" />
<span class="text-2xs text-secondary">
They add it to their AI client and sign in. The global URL does not serve these tools.
</span>
</div>
{/if}
{:else if effective !== 'off'}
{#if workspace}
<div class="flex flex-col gap-1">
<span class="text-2xs font-semibold text-emphasis">URL for this workspace</span>
<ClipboardPanel content={workspaceUrl} size="sm" />
<span class="text-2xs font-semibold text-emphasis">URL for several workspaces</span>
<ClipboardPanel content={globalUrl} size="sm" />
<span class="text-2xs text-secondary">
Members add one to their AI client and sign in. With the second, they choose the
workspaces then.
</span>
</div>
{:else}
<div class="flex flex-col gap-1">
<span class="text-2xs font-semibold text-emphasis">URL for members</span>
<ClipboardPanel content={globalUrl} size="sm" />
<span class="text-2xs text-secondary">
They add it to their AI client, sign in and choose the workspaces. Each workspace also has
its own URL, in its role settings.
</span>
</div>
{/if}
{/if}
</div>
@@ -332,7 +332,7 @@
instanceLimit={role && data && Object.hasOwn(data.instance_mcp, name)
? data.instance_mcp[name]
: undefined}
canRun={runUnknown(name) ? undefined : caps.run}
caps={runUnknown(name) ? undefined : caps}
{workspace}
frozen={!data?.custom_roles_enabled}
onchange={(mcp) => setMcp(name, mcp)}