feat: show the consent page's tools in a searchable dialog, pick the access from a select

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-02 19:59:19 +01:00
co-authored by Claude Opus 5.5
parent fc23165c33
commit e0bded292f
5 changed files with 104 additions and 33 deletions
+3
View File
@@ -1029,6 +1029,8 @@ struct ToolsetQuery {
struct ToolsetEntry {
name: String,
description: String,
/// The JSON Schema of its arguments.
parameters: serde_json::Value,
}
/// The tools `/api/mcp` offers an `mcp:all` token at each access level, for the token
@@ -1047,6 +1049,7 @@ async fn list_toolset_handler(
.map(|tool| ToolsetEntry {
name: tool.name.to_string(),
description: tool.description.map(|d| d.to_string()).unwrap_or_default(),
parameters: serde_json::Value::Object((*tool.input_schema).clone()),
})
.collect(),
))
@@ -40,6 +40,7 @@
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 Select from '$lib/components/select/Select.svelte'
import McpToolList from './McpToolList.svelte'
import { toolset } from './toolsets.svelte'
import Section from '$lib/components/Section.svelte'
@@ -63,6 +64,8 @@
fullLabel?: string
/** Rendered between the access choice and the tool list. */
afterAccess?: Snippet
/** A select, with the chosen level's meaning under it, for a narrow dialog. */
asSelect?: boolean
}
let {
@@ -72,9 +75,17 @@
access = $bindable(),
initialScopes = [],
fullLabel = 'Build and run',
afterAccess
afterAccess,
asSelect = false
}: Props = $props()
const LEVELS = $derived([
{ value: 'full', label: fullLabel },
{ value: 'read_run', label: 'Read and run' },
{ value: 'read', label: 'Read only' },
{ value: 'selected', label: 'Scripts and flows as tools' }
])
const initialAccess = mcpAccessOf(initialScopes)
access = initialAccess
const initialSelection =
@@ -116,24 +127,31 @@
<div class="flex flex-col gap-4">
<div>
<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={ACCESS_HINTS.full} />
<ToggleButton
{item}
value="read_run"
label="Read and run"
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={ACCESS_HINTS.selected}
/>
{/snippet}
</ToggleButtonGroup>
{#if asSelect}
<Select items={LEVELS} bind:value={() => access, (v) => v && (access = v as McpAccess)} />
{#if access}
<p class="mt-1 text-2xs text-secondary">{ACCESS_HINTS[access]}</p>
{/if}
{:else}
<ToggleButtonGroup bind:selected={access} allowEmpty={false}>
{#snippet children({ item })}
<ToggleButton {item} value="full" label={fullLabel} tooltip={ACCESS_HINTS.full} />
<ToggleButton
{item}
value="read_run"
label="Read and run"
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={ACCESS_HINTS.selected}
/>
{/snippet}
</ToggleButtonGroup>
{/if}
</div>
{#if narrowed.length > 0}
<Alert type="warning" size="xs" title="Narrower in some workspaces">
@@ -145,7 +163,8 @@
</Alert>
{/if}
{@render afterAccess?.()}
{#if toolsetAccess}
<!-- A dialog's caller lists the tools, and the select's caption says what a selection is. -->
{#if toolsetAccess && !asSelect}
<Section label="Tools the client gets" small collapsable bind:collapsed={toolsCollapsed}>
<div class="-mt-2">
<McpToolList {tools} />
@@ -153,10 +172,12 @@
</Section>
{/if}
{#if access === 'selected'}
<p class="text-2xs text-secondary -mt-2">
The client can run these scripts and flows and nothing else: it cannot explore the workspace,
read runs, build, or run anything outside the selection.
</p>
{#if !asSelect}
<p class="text-2xs text-secondary -mt-2">
The client can run these scripts and flows and nothing else: it cannot explore the
workspace, read runs, build, or run anything outside the selection.
</p>
{/if}
<!-- A selection names paths of one workspace, so switching workspace starts it over. -->
{#key workspaceId}
<McpScopeSelector {workspaceId} bind:scope={selection} initialScope={initialSelection} />
@@ -0,0 +1,42 @@
<script lang="ts">
import Modal2 from '$lib/components/common/modal/Modal2.svelte'
import AssistantToolsSection from '$lib/components/copilot/chat/AssistantToolsSection.svelte'
import { toolset, type ToolsetLevel } from './toolsets.svelte'
let { open = $bindable(false), level }: { open: boolean; level: ToolsetLevel } = $props()
let blocksClose = $state(false)
const tools = $derived(open ? toolset(level) : undefined)
const summaries = $derived(
(tools ?? [])
.map((t) => ({
name: t.name,
description: t.description,
parameters: { required: [], ...(t.parameters ?? {}) }
}))
.sort((a, b) => a.name.localeCompare(b.name))
)
</script>
<Modal2
bind:isOpen={open}
title="Tools the client gets"
fixedWidth="md"
fixedHeight="lg"
closeOnOutsideClick={!blocksClose}
closeOnEscape={!blocksClose}
>
<div class="flex grow min-h-0 flex-col overflow-hidden">
{#if tools}
<AssistantToolsSection
tools={summaries}
providerTools={[]}
active={open}
bind:blocksClose
description="What the AI client can call on this connection. Where a workspace's role allows less, the call is refused there."
/>
{:else}
<p class="p-4 text-xs text-secondary">Loading tools…</p>
{/if}
</div>
</Modal2>
@@ -1,6 +1,11 @@
import { SvelteMap } from 'svelte/reactivity'
export type ToolsetEntry = { name: string; description: string }
export type ToolsetEntry = {
name: string
description: string
/** The JSON Schema of its arguments. */
parameters?: Record<string, any>
}
export type ToolsetLevel = 'read' | 'read_run' | 'full'
const toolsets = new SvelteMap<ToolsetLevel, ToolsetEntry[]>()
@@ -20,8 +20,7 @@
mcpAccessOf,
type McpAccess
} from '$lib/components/mcp/McpAccessPicker.svelte'
import McpToolList from '$lib/components/mcp/McpToolList.svelte'
import { toolset } from '$lib/components/mcp/toolsets.svelte'
import McpToolsModal from '$lib/components/mcp/McpToolsModal.svelte'
import {
accessLabel,
defaultConnection,
@@ -598,10 +597,9 @@
<Button
variant="subtle"
unifiedSize="xs"
aria-expanded={toolsOpen}
onClick={() => (toolsOpen = !toolsOpen)}
onClick={() => (toolsOpen = true)}
>
{toolsOpen ? 'Hide tools' : 'Show tools'}
Show tools
</Button>
{/if}
{/snippet}
@@ -655,9 +653,6 @@
Scripts and flows as tools. Choose the workspace and its scripts and flows.
</p>
{/if}
{#if toolsOpen && connectionTools}
<McpToolList tools={toolset(connectionTools)} />
{/if}
</div>
{/if}
@@ -706,6 +701,10 @@
</div>
{/if}
{#if connectionTools}
<McpToolsModal bind:open={toolsOpen} level={connectionTools} />
{/if}
<Modal
title="Edit access"
enterConfirms={false}
@@ -714,6 +713,7 @@
<McpAccessPicker
workspaceId={scopeWorkspaceId ?? ''}
initialScopes={scopes}
asSelect
bind:scopes
bind:access={() => access, setAccess}
>