mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-03 16:10:37 +00:00
feat: show the mcp consent page's access per workspace, edit it in a dialog
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c4b63237ea
commit
0d1bae4e4a
@@ -9,12 +9,22 @@
|
||||
* tools. Grants nothing, so it is never shown. */
|
||||
export const MCP_SESSION = 'mcp:session'
|
||||
|
||||
const ACCESS_SCOPES: Record<Exclude<McpAccess, 'selected'>, string[]> = {
|
||||
export const ACCESS_SCOPES: Record<Exclude<McpAccess, 'selected'>, string[]> = {
|
||||
read: ['mcp:all', 'mcp:read_only'],
|
||||
read_run: ['mcp:all', 'mcp:read_run'],
|
||||
full: ['mcp:all', MCP_SESSION]
|
||||
}
|
||||
|
||||
/** What each access level lets the client do. */
|
||||
export const ACCESS_HINTS: Record<McpAccess, string> = {
|
||||
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 {
|
||||
@@ -30,10 +40,9 @@
|
||||
import ToggleButtonGroup from '$lib/components/common/toggleButton-v2/ToggleButtonGroup.svelte'
|
||||
import ToggleButton from '$lib/components/common/toggleButton-v2/ToggleButton.svelte'
|
||||
import McpScopeSelector from './McpScopeSelector.svelte'
|
||||
import Popover from '$lib/components/Popover.svelte'
|
||||
import { Badge } from '$lib/components/common'
|
||||
import McpToolList from './McpToolList.svelte'
|
||||
import { toolset } from './toolsets.svelte'
|
||||
import Section from '$lib/components/Section.svelte'
|
||||
import { SvelteMap } from 'svelte/reactivity'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { resource } from 'runed'
|
||||
import Alert from '$lib/components/common/alert/Alert.svelte'
|
||||
@@ -84,20 +93,9 @@
|
||||
: ACCESS_SCOPES[access]
|
||||
})
|
||||
|
||||
// The tools each access level gives, as the server lists them.
|
||||
type ToolsetEntry = { name: string; description: string }
|
||||
let toolsCollapsed = $state(true)
|
||||
const toolsets = new SvelteMap<string, ToolsetEntry[]>()
|
||||
const toolsetAccess = $derived(access === 'selected' ? undefined : access)
|
||||
$effect(() => {
|
||||
const level = toolsetAccess
|
||||
if (toolsCollapsed || !level || toolsets.has(level)) return
|
||||
fetch(`/api/mcp/toolset?access=${level}`)
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((tools: ToolsetEntry[]) => toolsets.set(level, tools))
|
||||
.catch(() => toolsets.set(level, []))
|
||||
})
|
||||
const tools = $derived(toolsetAccess ? toolsets.get(toolsetAccess) : undefined)
|
||||
const tools = $derived(toolsetAccess && !toolsCollapsed ? toolset(toolsetAccess) : undefined)
|
||||
|
||||
// Each workspace's access, as the chat resolves it, to compare with the level picked.
|
||||
const workspaceAccess = resource(
|
||||
@@ -120,29 +118,19 @@
|
||||
<span class="block mb-1 text-emphasis text-xs font-semibold">Access</span>
|
||||
<ToggleButtonGroup bind:selected={access} allowEmpty={false}>
|
||||
{#snippet children({ item })}
|
||||
<ToggleButton
|
||||
{item}
|
||||
value="full"
|
||||
label={fullLabel}
|
||||
tooltip="Everything you can do yourself: explore, write, test and deploy drafts, and run."
|
||||
/>
|
||||
<ToggleButton {item} value="full" label={fullLabel} tooltip={ACCESS_HINTS.full} />
|
||||
<ToggleButton
|
||||
{item}
|
||||
value="read_run"
|
||||
label="Read and run"
|
||||
tooltip="Explore, and run deployed scripts, flows and agents. The client changes nothing itself; what it runs can."
|
||||
/>
|
||||
<ToggleButton
|
||||
{item}
|
||||
value="read"
|
||||
label="Read only"
|
||||
tooltip="Explore and read. Nothing is run or changed."
|
||||
tooltip={ACCESS_HINTS.read_run}
|
||||
/>
|
||||
<ToggleButton {item} value="read" label="Read only" tooltip={ACCESS_HINTS.read} />
|
||||
<ToggleButton
|
||||
{item}
|
||||
value="selected"
|
||||
label="Scripts and flows as tools"
|
||||
tooltip="The scripts and flows you pick, each as its own tool, and nothing else. To share a few automations."
|
||||
tooltip={ACCESS_HINTS.selected}
|
||||
/>
|
||||
{/snippet}
|
||||
</ToggleButtonGroup>
|
||||
@@ -159,20 +147,8 @@
|
||||
{@render afterAccess?.()}
|
||||
{#if toolsetAccess}
|
||||
<Section label="Tools the client gets" small collapsable bind:collapsed={toolsCollapsed}>
|
||||
<div class="flex flex-col gap-1 -mt-2">
|
||||
<span class="text-2xs text-secondary">
|
||||
{tools ? `${tools.length} tools. Hover one for what it does.` : 'Loading tools…'}
|
||||
</span>
|
||||
<div class="flex flex-wrap gap-1">
|
||||
{#each tools ?? [] as tool (tool.name)}
|
||||
<Popover notClickable>
|
||||
{#snippet text()}
|
||||
<div class="text-xs max-w-md">{tool.description}</div>
|
||||
{/snippet}
|
||||
<Badge rounded small color="gray">{tool.name}</Badge>
|
||||
</Popover>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="-mt-2">
|
||||
<McpToolList {tools} />
|
||||
</div>
|
||||
</Section>
|
||||
{/if}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<script lang="ts">
|
||||
import Popover from '$lib/components/Popover.svelte'
|
||||
import { Badge } from '$lib/components/common'
|
||||
import type { ToolsetEntry } from './toolsets.svelte'
|
||||
|
||||
let { tools }: { tools: ToolsetEntry[] | undefined } = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-2xs text-secondary">
|
||||
{tools ? `${tools.length} tools. Hover one for what it does.` : 'Loading tools…'}
|
||||
</span>
|
||||
<div class="flex flex-wrap gap-1">
|
||||
{#each tools ?? [] as tool (tool.name)}
|
||||
<Popover notClickable>
|
||||
{#snippet text()}
|
||||
<div class="text-xs max-w-md">{tool.description}</div>
|
||||
{/snippet}
|
||||
<Badge rounded small color="gray">{tool.name}</Badge>
|
||||
</Popover>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
import { SvelteMap } from 'svelte/reactivity'
|
||||
|
||||
export type ToolsetEntry = { name: string; description: string }
|
||||
export type ToolsetLevel = 'read' | 'read_run' | 'full'
|
||||
|
||||
const toolsets = new SvelteMap<ToolsetLevel, ToolsetEntry[]>()
|
||||
const loading = new Set<ToolsetLevel>()
|
||||
|
||||
/** The tools the server lists for an access level, undefined until loaded. The first read
|
||||
* starts the load. */
|
||||
export function toolset(level: ToolsetLevel): ToolsetEntry[] | undefined {
|
||||
if (!toolsets.has(level) && !loading.has(level)) {
|
||||
loading.add(level)
|
||||
fetch(`/api/mcp/toolset?access=${level}`)
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((tools: ToolsetEntry[]) => toolsets.set(level, tools))
|
||||
.catch(() => toolsets.set(level, []))
|
||||
.finally(() => loading.delete(level))
|
||||
}
|
||||
return toolsets.get(level)
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { McpWorkspaceAccess } from '$lib/gen'
|
||||
import { accessIsSet, accessLabel, connectsSeparately, defaultConnection } from './workspaceAccess'
|
||||
import {
|
||||
accessLabel,
|
||||
connectsSeparately,
|
||||
defaultConnection,
|
||||
servedOn,
|
||||
toolsetLevel
|
||||
} from './workspaceAccess'
|
||||
|
||||
const ws = (id: string, access: McpWorkspaceAccess['access']): McpWorkspaceAccess => ({
|
||||
id,
|
||||
@@ -31,7 +37,10 @@ it('names the lower of the picked access and the workspace one', () => {
|
||||
'12 scripts and flows as tools'
|
||||
)
|
||||
expect(
|
||||
accessLabel({ ...ws('a', 'run_and_edit'), edits: ['variables', 'schedules', 'triggers'] }, 'full')
|
||||
accessLabel(
|
||||
{ ...ws('a', 'run_and_edit'), edits: ['variables', 'schedules', 'triggers'] },
|
||||
'full'
|
||||
)
|
||||
).toBe('Read and run, edit variables, schedules and triggers')
|
||||
expect(accessLabel(ws('a', 'run_and_edit'), 'read_run')).toBe('Read and run')
|
||||
expect(accessLabel(ws('a', 'read_only'), 'read_run')).toBe('Read only')
|
||||
@@ -39,10 +48,21 @@ it('names the lower of the picked access and the workspace one', () => {
|
||||
expect(accessLabel(ws('a', 'runnables'), 'read')).toBe('Not available')
|
||||
})
|
||||
|
||||
it('leaves the access open as soon as one covered workspace does', () => {
|
||||
expect(accessIsSet([ws('a', 'runnables')])).toBe(true)
|
||||
expect(accessIsSet([ws('a', 'runnables'), ws('b', 'build_and_run')])).toBe(false)
|
||||
expect(accessIsSet([])).toBe(false)
|
||||
it('serves a tools workspace only to a connection covering it alone', () => {
|
||||
const tools = ws('a', 'runnables')
|
||||
const session = ws('b', 'read_only')
|
||||
expect(servedOn([tools], false)).toEqual([tools])
|
||||
expect(servedOn([tools], true)).toEqual([])
|
||||
expect(servedOn([tools, session], false)).toEqual([session])
|
||||
})
|
||||
|
||||
it('lists the session tools of the lower of the picked access and the workspace one', () => {
|
||||
expect(toolsetLevel(ws('a', 'build_and_run'), 'full')).toBe('full')
|
||||
expect(toolsetLevel(ws('a', 'run_and_edit'), 'full')).toBe('read_run')
|
||||
expect(toolsetLevel(ws('a', 'read_only'), 'read_run')).toBe('read')
|
||||
expect(toolsetLevel(ws('a', 'build_and_run'), 'read')).toBe('read')
|
||||
expect(toolsetLevel(ws('a', 'runnables'), 'full')).toBeUndefined()
|
||||
expect(toolsetLevel(ws('a', 'build_and_run'), 'selected')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('tools are part of a connection to their workspace alone', () => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { apiBaseUrl } from '$lib/apiBaseUrl.svelte'
|
||||
import type { McpWorkspaceAccess } from '$lib/gen'
|
||||
import type { McpAccess } from './McpAccessPicker.svelte'
|
||||
import type { ToolsetLevel } from './toolsets.svelte'
|
||||
|
||||
export type WorkspaceAccess = McpWorkspaceAccess['access']
|
||||
|
||||
@@ -39,9 +40,24 @@ export function accessLabel(workspace: McpWorkspaceAccess, picked: McpAccess): s
|
||||
return LABELS[access]
|
||||
}
|
||||
|
||||
/** Whether roles set the access in every workspace covered, which leaves nothing to choose. */
|
||||
export function accessIsSet(covered: McpWorkspaceAccess[]): boolean {
|
||||
return covered.length > 0 && covered.every((w) => w.limited)
|
||||
/** The covered workspaces a connection serves. One set to scripts and flows as tools is served
|
||||
* only to a connection covering it alone. */
|
||||
export function servedOn(covered: McpWorkspaceAccess[], all: boolean): McpWorkspaceAccess[] {
|
||||
const alone = !all && covered.length === 1
|
||||
return covered.filter((w) => w.access !== 'runnables' || alone)
|
||||
}
|
||||
|
||||
/** The session toolset a connection with the `picked` access gets in a workspace, none where it
|
||||
* gets scripts and flows as tools or nothing. */
|
||||
export function toolsetLevel(
|
||||
workspace: McpWorkspaceAccess,
|
||||
picked: McpAccess
|
||||
): ToolsetLevel | undefined {
|
||||
const { access } = workspace
|
||||
if (access === 'runnables' || access === 'off' || picked === 'selected') return undefined
|
||||
if (picked === 'read' || access === 'read_only') return 'read'
|
||||
if (picked === 'read_run' || access !== 'build_and_run') return 'read_run'
|
||||
return 'full'
|
||||
}
|
||||
|
||||
/** The MCP URL connecting to this workspace alone. */
|
||||
|
||||
@@ -5,16 +5,29 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import CenteredModal from '$lib/components/CenteredModal.svelte'
|
||||
import { Alert, Badge, Button } from '$lib/components/common'
|
||||
import { Badge, Button } from '$lib/components/common'
|
||||
import Modal from '$lib/components/common/modal/Modal.svelte'
|
||||
import MultiSelect from '$lib/components/select/MultiSelect.svelte'
|
||||
import Select from '$lib/components/select/Select.svelte'
|
||||
import Toggle from '$lib/components/Toggle.svelte'
|
||||
import Tooltip from '$lib/components/Tooltip.svelte'
|
||||
import McpAccessPicker, {
|
||||
ACCESS_HINTS,
|
||||
ACCESS_SCOPES,
|
||||
MCP_SESSION,
|
||||
RUNNABLES_AS_TOOLS,
|
||||
mcpAccessOf,
|
||||
type McpAccess
|
||||
} from '$lib/components/mcp/McpAccessPicker.svelte'
|
||||
import McpWorkspaceAccessList from '$lib/components/mcp/McpWorkspaceAccessList.svelte'
|
||||
import { accessIsSet, defaultConnection, workspaceMcpUrl } from '$lib/components/mcp/workspaceAccess'
|
||||
import McpToolList from '$lib/components/mcp/McpToolList.svelte'
|
||||
import { toolset } from '$lib/components/mcp/toolsets.svelte'
|
||||
import {
|
||||
accessLabel,
|
||||
defaultConnection,
|
||||
servedOn,
|
||||
toolsetLevel,
|
||||
workspaceMcpUrl
|
||||
} from '$lib/components/mcp/workspaceAccess'
|
||||
import ClipboardPanel from '$lib/components/details/ClipboardPanel.svelte'
|
||||
import {
|
||||
McpOauthService,
|
||||
@@ -25,8 +38,7 @@
|
||||
import { parseScopeParam } from '$lib/mcpAuth'
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
import { copyToClipboard } from '$lib/utils'
|
||||
import ChevronDown from 'lucide-svelte/icons/chevron-down'
|
||||
import ChevronRight from 'lucide-svelte/icons/chevron-right'
|
||||
import Pencil from 'lucide-svelte/icons/pencil'
|
||||
import Copy from 'lucide-svelte/icons/copy'
|
||||
import Check from 'lucide-svelte/icons/check'
|
||||
|
||||
@@ -58,8 +70,17 @@
|
||||
askedScopes.includes('mcp:read_run')
|
||||
? askedScopes.filter((s) => s !== 'mcp:read_only' && s !== 'mcp:read_run')
|
||||
: askedScopes
|
||||
let scopes = $state<string[]>([])
|
||||
let access = $state<McpAccess>()
|
||||
const requestedAccess = mcpAccessOf(requestedScopes)
|
||||
// What the client asked for, until the user edits the access in the dialog.
|
||||
let access = $state<McpAccess>(requestedAccess)
|
||||
let scopes = $state<string[]>(
|
||||
requestedAccess === 'selected'
|
||||
? [
|
||||
...requestedScopes.filter((s) => s !== RUNNABLES_AS_TOOLS && s !== MCP_SESSION),
|
||||
RUNNABLES_AS_TOOLS
|
||||
]
|
||||
: ACCESS_SCOPES[requestedAccess]
|
||||
)
|
||||
let oauthState = page.url.searchParams.get('state') || ''
|
||||
let codeChallenge = page.url.searchParams.get('code_challenge') || ''
|
||||
let codeChallengeMethod = page.url.searchParams.get('code_challenge_method') || ''
|
||||
@@ -134,28 +155,93 @@
|
||||
let pickedWorkspaces = $state<string[]>([])
|
||||
let allWorkspaces = $state(false)
|
||||
let loadingWorkspaces = $state(false)
|
||||
// Each scripts-and-flows-as-tools workspace needs a connection of its own.
|
||||
let oneEach = $state(false)
|
||||
const grantsWorkspace = $derived(!isGateway || allWorkspaces || pickedWorkspaces.length > 0)
|
||||
const coveredIds = $derived(isGateway ? pickedWorkspaces : [workspaceId])
|
||||
const coversAll = $derived(isGateway && allWorkspaces)
|
||||
const covered = $derived(workspaceAccess.filter((w) => coversAll || coveredIds.includes(w.id)))
|
||||
const requestedAccess = mcpAccessOf(requestedScopes)
|
||||
// A role that sets the access leaves nothing to choose, but a narrower access the client asked
|
||||
// for or the user picked stays in sight.
|
||||
const limitHidden = $derived(
|
||||
accessIsSet(covered) && requestedAccess === 'full' && access === 'full'
|
||||
)
|
||||
const served = $derived(servedOn(covered, coversAll))
|
||||
const unavailable = $derived(
|
||||
!coversAll && covered.length > 0 && covered.every((w) => w.access === 'off')
|
||||
)
|
||||
let limitCollapsed = $state(requestedAccess === 'full')
|
||||
const isTools = (w: McpWorkspaceAccess) => w.access === 'runnables'
|
||||
// Every workspace gives scripts and flows as tools, so a connection serves one of them.
|
||||
const toolsOnly = $derived(
|
||||
isGateway &&
|
||||
workspaceAccess.some(isTools) &&
|
||||
workspaceAccess.every((w) => isTools(w) || w.access === 'off')
|
||||
)
|
||||
// A workspace set to tools is picked only on its own, through "Connect it only".
|
||||
const pickable = $derived(
|
||||
workspaceAccess.filter((w) => !isTools(w)).map((w) => ({ value: w.id, label: w.name }))
|
||||
)
|
||||
const toolsAlone = $derived(
|
||||
isGateway && !toolsOnly && !allWorkspaces && covered.length === 1 && isTools(covered[0])
|
||||
)
|
||||
const leftOut = $derived(
|
||||
isGateway && !toolsOnly && access !== 'selected'
|
||||
? workspaceAccess.filter((w) => isTools(w) && !served.includes(w))
|
||||
: []
|
||||
)
|
||||
// Served workspaces grouped by what they get, so a role's access reads once per level.
|
||||
const groups = $derived.by(() => {
|
||||
const byLabel = new Map<string, McpWorkspaceAccess[]>()
|
||||
for (const w of served) {
|
||||
const label = accessLabel(w, access)
|
||||
byLabel.set(label, [...(byLabel.get(label) ?? []), w])
|
||||
}
|
||||
return [...byLabel].map(([label, ws]) => {
|
||||
const level = toolsetLevel(ws[0], access)
|
||||
const hint =
|
||||
ws[0].access === 'off'
|
||||
? 'Your role gives no MCP access there.'
|
||||
: isTools(ws[0])
|
||||
? 'The scripts and flows your role offers, each as its own tool, and nothing else.'
|
||||
: ACCESS_HINTS[level ?? access]
|
||||
return {
|
||||
label,
|
||||
ws,
|
||||
level,
|
||||
hint: ws.every((w) => w.limited) ? `${hint} Set by your role.` : hint
|
||||
}
|
||||
})
|
||||
})
|
||||
// A role limit settles the access; a narrower one the client asked for stays editable.
|
||||
const editable = $derived(served.every((w) => !w.limited) || access !== 'full')
|
||||
let shownTools = $state<string[]>([])
|
||||
let showUrls = $state(false)
|
||||
function coverDefault() {
|
||||
const initial = defaultConnection(workspaceAccess)
|
||||
allWorkspaces = initial.all
|
||||
pickedWorkspaces = initial.picked
|
||||
oneEach = initial.oneEach
|
||||
}
|
||||
function connectOnly(id: string) {
|
||||
allWorkspaces = false
|
||||
pickedWorkspaces = [id]
|
||||
}
|
||||
|
||||
// The access dialog edits the page's own state; closing it any way but Done puts it back.
|
||||
let editing = $state(false)
|
||||
let beforeEdit:
|
||||
| { access: McpAccess; scopes: string[]; all: boolean; picked: string[] }
|
||||
| undefined
|
||||
function openEdit() {
|
||||
beforeEdit = { access, scopes, all: allWorkspaces, picked: pickedWorkspaces }
|
||||
editing = true
|
||||
}
|
||||
function closeEdit(keep: boolean) {
|
||||
if (!keep && beforeEdit) {
|
||||
;({ access, scopes } = beforeEdit)
|
||||
allWorkspaces = beforeEdit.all
|
||||
pickedWorkspaces = beforeEdit.picked
|
||||
}
|
||||
beforeEdit = undefined
|
||||
editing = false
|
||||
}
|
||||
const selectionMissing = $derived(
|
||||
access === 'selected' &&
|
||||
((isGateway && pickedWorkspaces.length === 0) ||
|
||||
scopes.every((s) => s === RUNNABLES_AS_TOOLS))
|
||||
)
|
||||
// Selected scripts and flows are listed per workspace, so a selection keeps one of them.
|
||||
let beforeSelection: { all: boolean; picked: string[]; held: string | undefined } | undefined
|
||||
function setAccess(next: McpAccess | undefined) {
|
||||
@@ -294,9 +380,8 @@
|
||||
{#if !redirectUriValid}
|
||||
<CenteredModal title="Authorization Request">
|
||||
<p class="text-center text-sm text-primary break-all">
|
||||
This client's redirect URI {redirectUri} cannot receive the authorization: it must be an
|
||||
http(s) or app URL outside this instance's /api path. Register the client with its own
|
||||
callback URL.
|
||||
This client's redirect URI {redirectUri} cannot receive the authorization: it must be an http(s)
|
||||
or app URL outside this instance's /api path. Register the client with its own callback URL.
|
||||
</p>
|
||||
</CenteredModal>
|
||||
{:else if clientLookupFailed || (client && !redirectRegistered)}
|
||||
@@ -391,18 +476,50 @@
|
||||
{#if isGateway}
|
||||
<div class="mb-6 flex flex-col gap-2">
|
||||
<p class="text-xs font-semibold text-emphasis">
|
||||
{access === 'selected'
|
||||
? 'Workspace of its scripts and flows:'
|
||||
: 'Workspaces it may work in:'}
|
||||
{access === 'selected' || toolsOnly || toolsAlone ? 'Workspace' : 'Workspaces'}
|
||||
</p>
|
||||
{#if loadingWorkspaces}
|
||||
<p class="text-xs text-secondary">Loading workspaces...</p>
|
||||
{:else if accessLoadFailed}
|
||||
<p class="text-xs text-red-600 dark:text-red-400">
|
||||
Your workspaces could not be loaded. Reload this page.
|
||||
</p>
|
||||
{:else if access === 'selected'}
|
||||
<p class="text-xs text-primary">
|
||||
{pickedWorkspaces[0] ?? 'None yet'}
|
||||
</p>
|
||||
<p class="text-2xs text-secondary">
|
||||
The workspace of its scripts and flows. Change it with the access.
|
||||
</p>
|
||||
{:else if toolsOnly}
|
||||
<Select
|
||||
items={workspaces}
|
||||
items={workspaceAccess.filter(isTools).map((w) => ({ value: w.id, label: w.name }))}
|
||||
bind:value={() => pickedWorkspaces[0], (v) => (pickedWorkspaces = v ? [v] : [])}
|
||||
placeholder="Choose a workspace"
|
||||
/>
|
||||
<p class="text-2xs text-secondary">
|
||||
Your role gives scripts and flows as tools, one workspace per connection. For another,
|
||||
sign in again and choose it here, or add its URL to your client.
|
||||
</p>
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="xs"
|
||||
btnClasses="w-fit"
|
||||
aria-expanded={showUrls}
|
||||
onClick={() => (showUrls = !showUrls)}
|
||||
>
|
||||
{showUrls ? 'Hide workspace URLs' : 'Show workspace URLs'}
|
||||
</Button>
|
||||
{#if showUrls}
|
||||
{#each workspaceAccess.filter((w) => isTools(w) && !pickedWorkspaces.includes(w.id)) as w (w.id)}
|
||||
<ClipboardPanel title={w.name} content={workspaceMcpUrl(w.id)} size="sm" />
|
||||
{/each}
|
||||
{/if}
|
||||
{:else if toolsAlone}
|
||||
<p class="text-xs text-primary">{covered[0].name} only</p>
|
||||
<Button variant="subtle" unifiedSize="xs" btnClasses="w-fit" onClick={coverDefault}>
|
||||
Back to my other workspaces
|
||||
</Button>
|
||||
{:else}
|
||||
<Toggle
|
||||
bind:checked={allWorkspaces}
|
||||
@@ -413,35 +530,23 @@
|
||||
}}
|
||||
size="xs"
|
||||
/>
|
||||
{#if accessLoadFailed}
|
||||
<p class="text-xs text-red-600 dark:text-red-400">
|
||||
Your workspaces could not be loaded. Reload this page.
|
||||
</p>
|
||||
{:else if workspaces.length === 0 && !allWorkspaces}
|
||||
{#if workspaces.length === 0 && !allWorkspaces}
|
||||
<p class="text-xs text-secondary">
|
||||
You are not in any workspace yet. Turn this on to give it the ones you join later.
|
||||
</p>
|
||||
{:else if !allWorkspaces}
|
||||
<MultiSelect
|
||||
items={workspaces}
|
||||
items={pickable}
|
||||
bind:value={pickedWorkspaces}
|
||||
placeholder="Choose workspaces"
|
||||
reorderable={false}
|
||||
/>
|
||||
{#if pickedWorkspaces.length === 0}
|
||||
<p class="text-2xs text-secondary">Choose at least one workspace.</p>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
{#if oneEach && access !== 'selected' && !allWorkspaces && pickedWorkspaces.length === 1}
|
||||
<Alert type="info" size="xs" title="One workspace per connection">
|
||||
Scripts and flows as tools are offered one workspace at a time. This connection covers
|
||||
the one selected above. To use another, connect to its own URL:
|
||||
<ul class="flex flex-col gap-1 mt-1">
|
||||
{#each workspaceAccess.filter((w) => w.access === 'runnables' && !pickedWorkspaces.includes(w.id)) as w (w.id)}
|
||||
<li><ClipboardPanel title={w.name} content={workspaceMcpUrl(w.id)} size="sm" /></li>
|
||||
{/each}
|
||||
</ul>
|
||||
</Alert>
|
||||
{/if}
|
||||
{#if isSuperAdmin && !superAdmin && (access === 'selected' || !allWorkspaces)}
|
||||
{#if isSuperAdmin && !superAdmin && !allWorkspaces}
|
||||
<p class="text-xs text-tertiary">
|
||||
Showing workspaces you are a member of. Superadmin rights opens the rest.
|
||||
</p>
|
||||
@@ -455,17 +560,6 @@
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if access}
|
||||
<div class="mb-6">
|
||||
<McpWorkspaceAccessList
|
||||
workspaces={workspaceAccess}
|
||||
covered={coveredIds}
|
||||
all={coversAll}
|
||||
{access}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if isSuperAdmin}
|
||||
<div class="mb-6">
|
||||
<Toggle
|
||||
@@ -481,29 +575,146 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="mb-6 flex flex-col items-start" class:hidden={limitHidden}>
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
btnClasses="mb-2 w-fit"
|
||||
startIcon={{ icon: limitCollapsed ? ChevronRight : ChevronDown }}
|
||||
disabled={loadingWorkspaces}
|
||||
aria-expanded={!limitCollapsed}
|
||||
onClick={() => (limitCollapsed = !limitCollapsed)}
|
||||
>
|
||||
Limit access
|
||||
</Button>
|
||||
<!-- Hidden rather than unmounted: the picker writes the scopes to approve. -->
|
||||
<div class:hidden={limitCollapsed || loadingWorkspaces}>
|
||||
<McpAccessPicker
|
||||
workspaceId={scopeWorkspaceId ?? ''}
|
||||
initialScopes={requestedScopes}
|
||||
fullLabel="No extra limit"
|
||||
bind:scopes
|
||||
bind:access={() => access, setAccess}
|
||||
{#snippet pen()}
|
||||
{#if editable}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="xs"
|
||||
iconOnly
|
||||
startIcon={{ icon: Pencil }}
|
||||
aria-label="Edit access"
|
||||
title="Edit access"
|
||||
disabled={loadingWorkspaces}
|
||||
onClick={openEdit}
|
||||
/>
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet accessRow(group: (typeof groups)[number], named: boolean)}
|
||||
{@const open = shownTools.includes(group.label)}
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex flex-wrap items-center gap-x-1.5">
|
||||
<span class="text-xs text-primary">
|
||||
{#if named}
|
||||
<span class="font-semibold text-emphasis">{group.label}</span> in
|
||||
{group.ws.map((w) => w.name).join(', ')}
|
||||
{:else}
|
||||
{group.label}
|
||||
{/if}
|
||||
</span>
|
||||
<Tooltip small>{group.hint}</Tooltip>
|
||||
{#if !named}{@render pen()}{/if}
|
||||
{#if group.level}
|
||||
{@const tools = open ? toolset(group.level) : undefined}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="xs"
|
||||
btnClasses="ml-auto"
|
||||
aria-expanded={open}
|
||||
onClick={() =>
|
||||
(shownTools = open
|
||||
? shownTools.filter((l) => l !== group.label)
|
||||
: [...shownTools, group.label])}
|
||||
>
|
||||
{open ? 'Hide tools' : 'Show tools'}
|
||||
</Button>
|
||||
{#if open}
|
||||
<div class="basis-full"><McpToolList {tools} /></div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
{#if !loadingWorkspaces && (groups.length > 0 || access === 'selected')}
|
||||
<div class="mb-6 flex flex-col gap-1">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<p class="text-xs font-semibold text-emphasis">Access</p>
|
||||
{#if groups.length !== 1}{@render pen()}{/if}
|
||||
</div>
|
||||
{#if groups.length === 1}
|
||||
{@render accessRow(groups[0], false)}
|
||||
{:else if groups.length > 1}
|
||||
<div class="flex flex-col divide-y rounded-md border">
|
||||
{#each groups as group (group.label)}
|
||||
<div class="px-2 py-1.5">{@render accessRow(group, true)}</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-xs text-primary">
|
||||
Scripts and flows as tools. Choose the workspace and its scripts and flows.
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if leftOut.length > 0}
|
||||
{@const one = leftOut.length === 1}
|
||||
<div class="mb-6 flex flex-col gap-2 rounded-md border bg-surface-secondary p-3">
|
||||
<p class="text-xs font-semibold text-emphasis">
|
||||
{leftOut.map((w) => w.name).join(', ')}
|
||||
{one ? 'connects on its own' : 'connect on their own'}
|
||||
</p>
|
||||
<p class="text-xs text-primary">
|
||||
Your role gives scripts and flows as tools there, served on a connection covering {one
|
||||
? 'that workspace'
|
||||
: 'one workspace'} alone. Add {one ? 'its URL' : 'each URL'} to your client, or connect
|
||||
{one ? 'it' : 'one'} here instead of the others.
|
||||
</p>
|
||||
{#each leftOut as w (w.id)}
|
||||
<div class="flex flex-col gap-1">
|
||||
<ClipboardPanel
|
||||
title={one ? undefined : w.name}
|
||||
content={workspaceMcpUrl(w.id)}
|
||||
size="sm"
|
||||
/>
|
||||
<Button
|
||||
variant="default"
|
||||
unifiedSize="sm"
|
||||
btnClasses="w-fit"
|
||||
onClick={() => connectOnly(w.id)}
|
||||
>
|
||||
Connect {w.name} only
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Modal
|
||||
title="Edit access"
|
||||
enterConfirms={false}
|
||||
bind:open={() => editing, (v) => (v ? (editing = true) : closeEdit(false))}
|
||||
>
|
||||
<McpAccessPicker
|
||||
workspaceId={scopeWorkspaceId ?? ''}
|
||||
initialScopes={scopes}
|
||||
bind:scopes
|
||||
bind:access={() => access, setAccess}
|
||||
>
|
||||
{#snippet afterAccess()}
|
||||
{#if access === 'selected' && isGateway}
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-xs font-semibold text-emphasis">Workspace</span>
|
||||
<Select
|
||||
items={pickable}
|
||||
bind:value={() => pickedWorkspaces[0], (v) => (pickedWorkspaces = v ? [v] : [])}
|
||||
placeholder="Choose a workspace"
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</McpAccessPicker>
|
||||
{#snippet actions()}
|
||||
<Button
|
||||
variant="accent"
|
||||
unifiedSize="sm"
|
||||
disabled={selectionMissing}
|
||||
onClick={() => closeEdit(true)}
|
||||
>
|
||||
Done
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Modal>
|
||||
|
||||
<div class="flex flex-row justify-around gap-x-4">
|
||||
<Button variant="default" unifiedSize="lg" disabled={loading} onClick={onDeny}>Deny</Button>
|
||||
@@ -515,6 +726,8 @@
|
||||
accessLoadFailed ||
|
||||
!grantsWorkspace ||
|
||||
unavailable ||
|
||||
(isGateway && !allWorkspaces && served.length === 0) ||
|
||||
selectionMissing ||
|
||||
scopes.length === 0}
|
||||
{loading}
|
||||
onClick={onApprove}>Approve</Button
|
||||
|
||||
Reference in New Issue
Block a user