feat: one not-included card for tools workspaces on the consent page and token forms, global mcp url label

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-03 12:33:53 +01:00
co-authored by Claude Opus 5.5
parent e3c178887c
commit a361eb2dd3
8 changed files with 186 additions and 146 deletions
@@ -0,0 +1,103 @@
<script lang="ts">
import type { McpWorkspaceAccess } from '$lib/gen'
import { Button } from '$lib/components/common'
import { copyToClipboard } from '$lib/utils'
import { ChevronDown, ChevronRight, Copy } from 'lucide-svelte'
import { workspaceMcpUrl } from './workspaceAccess'
interface Props {
/** Workspaces whose role offers scripts and flows as tools, which a connection covering
* several workspaces leaves out. */
workspaces: McpWorkspaceAccess[]
/** Each needs a connection of its own, none of the others being included either. */
onTheirOwn?: boolean
/** A read-only connection, which runs no tool, so their URLs would give it nothing. */
readOnly?: boolean
/** Offers each workspace's own URL to copy. */
showUrl?: boolean
/** Narrows the connection to that workspace; none hides the button. */
onSelect?: (id: string) => void
}
let {
workspaces,
onTheirOwn = false,
readOnly = false,
showUrl = false,
onSelect
}: Props = $props()
let open = $state(false)
const one = $derived(workspaces.length === 1)
const urlHint = $derived(`add ${one ? 'its' : 'each'} workspace URL to your AI client`)
const explanation = $derived(
'Scripts and flows as tools need a connection of their own' +
(showUrl && onSelect
? `: ${urlHint}, or select it here instead.`
: showUrl
? `: ${urlHint}.`
: onSelect
? ': select it here instead.'
: '.')
)
</script>
{#if workspaces.length > 0}
<div class="flex flex-col gap-2 rounded-md border bg-surface-secondary p-3">
<Button
variant="subtle"
unifiedSize="xs"
btnClasses="-m-1 w-fit font-semibold text-emphasis"
startIcon={{ icon: open ? ChevronDown : ChevronRight }}
aria-expanded={open}
onClick={() => (open = !open)}
>
{one ? 'Workspace' : 'Workspaces'}
{workspaces.map((w) => w.name).join(', ')}
{onTheirOwn
? one
? 'connects on its own'
: 'connect on their own'
: one
? 'is not included'
: 'are not included'}
</Button>
{#if open && readOnly}
<p class="text-xs text-primary">
{one ? 'Its role offers' : 'Their roles offer'} only scripts and flows as tools, which a read-only
client cannot run.
</p>
{:else if open}
<p class="text-xs text-primary">{explanation}</p>
{#if showUrl || onSelect}
<div class="flex flex-col gap-1">
{#each workspaces as w (w.id)}
<div class="flex items-center justify-between gap-2">
{#if !one}
<span class="text-xs font-semibold text-emphasis truncate">{w.name}</span>
{/if}
<div class="flex shrink-0 gap-1">
{#if showUrl}
<Button
variant="default"
unifiedSize="xs"
startIcon={{ icon: Copy }}
title={workspaceMcpUrl(w.id)}
onClick={() => copyToClipboard(workspaceMcpUrl(w.id), true)}
>
Copy workspace URL
</Button>
{/if}
{#if onSelect}
<Button variant="default" unifiedSize="xs" onClick={() => onSelect(w.id)}>
Select it
</Button>
{/if}
</div>
</div>
{/each}
</div>
{/if}
{/if}
</div>
{/if}
@@ -1,44 +1,25 @@
<script lang="ts">
import ClipboardPanel from '$lib/components/details/ClipboardPanel.svelte'
import type { McpWorkspaceAccess } from '$lib/gen'
import type { McpAccess } from './McpAccessPicker.svelte'
import Tooltip from '$lib/components/Tooltip.svelte'
import { Badge } from '$lib/components/common'
import {
accessHint,
accessLabel,
connectsSeparately,
restriction,
workspaceMcpUrl
} from './workspaceAccess'
import { accessHint, accessLabel, restriction } from './workspaceAccess'
interface Props {
/** The workspaces the connection serves. */
workspaces: McpWorkspaceAccess[]
/** The workspaces the connection covers; with `all`, every one. */
covered: string[]
all: boolean
access: McpAccess
/** Names the workspaces on the single line, for when it sits under a level being picked. */
named?: boolean
}
let { workspaces, covered, all, access, named = false }: Props = $props()
let { workspaces, access, named = false }: Props = $props()
const listed = $derived(workspaces.filter((w) => all || covered.includes(w.id)))
const describe = (w: McpWorkspaceAccess) =>
[
accessLabel(w, access),
restriction(w, access),
accessHint(w, access),
connectsSeparately(w, all, covered, access)
].join('\n')
// Every workspace getting the same reads as one line; differing ones as one row each, and so do
// workspaces that connect separately, each row carrying its own URL.
[accessLabel(w, access), restriction(w, access), accessHint(w, access)].join('\n')
// Every workspace getting the same reads as one line; differing ones as one row each.
const same = $derived(
listed.length === 1 ||
(listed.length > 1 &&
!connectsSeparately(listed[0], all, covered, access) &&
listed.every((w) => describe(w) === describe(listed[0])))
workspaces.length > 0 && workspaces.every((w) => describe(w) === describe(workspaces[0]))
)
</script>
@@ -47,9 +28,7 @@
{#if restricted && badgeFirst}
<Badge color="gray" small>Restricted</Badge>
{/if}
{accessLabel(workspace, access)}{connectsSeparately(workspace, all, covered, access)
? ', connect separately'
: ''}
{accessLabel(workspace, access)}
{#if restricted && !badgeFirst}
<Badge color="gray" small>Restricted</Badge>
{/if}
@@ -59,26 +38,18 @@
{#if same}
<div class="flex flex-wrap items-center gap-x-1.5 text-xs text-primary">
{#if named}
<span class="text-secondary">In {listed.map((w) => w.name).join(', ')}:</span>
<span class="text-secondary">In {workspaces.map((w) => w.name).join(', ')}:</span>
{/if}
{@render access_(listed[0], false)}
{@render access_(workspaces[0], false)}
</div>
{#if connectsSeparately(listed[0], all, covered, access)}
<ClipboardPanel content={workspaceMcpUrl(listed[0].id)} size="sm" />
{/if}
{:else if listed.length > 1}
{:else if workspaces.length > 1}
<ul class="flex flex-col divide-y rounded-md border max-h-60 overflow-y-auto">
{#each listed as workspace (workspace.id)}
<li class="flex flex-col gap-1 px-2 py-1.5">
<div class="flex items-center justify-between gap-2">
<span class="text-xs text-emphasis truncate">{workspace.name}</span>
<span class="flex shrink-0 items-center gap-1.5 text-xs text-secondary">
{@render access_(workspace, true)}
</span>
</div>
{#if connectsSeparately(workspace, all, covered, access)}
<ClipboardPanel content={workspaceMcpUrl(workspace.id)} size="sm" />
{/if}
{#each workspaces as workspace (workspace.id)}
<li class="flex items-center justify-between gap-2 px-2 py-1.5">
<span class="text-xs text-emphasis truncate">{workspace.name}</span>
<span class="flex shrink-0 items-center gap-1.5 text-xs text-secondary">
{@render access_(workspace, true)}
</span>
</li>
{/each}
</ul>
@@ -2,7 +2,6 @@ import { describe, expect, it } from 'vitest'
import type { McpWorkspaceAccess } from '$lib/gen'
import {
accessLabel,
connectsSeparately,
defaultConnection,
narrows,
restriction,
@@ -79,14 +78,6 @@ it('lists one toolset per connection, trimmed only for a bound workspace', () =>
expect(connectionToolset('full', ws('a', 'runnables'))).toBeUndefined()
})
it('tools are part of a connection to their workspace alone', () => {
expect(connectsSeparately(ws('a', 'runnables'), false, ['a'], 'full')).toBe(false)
expect(connectsSeparately(ws('a', 'runnables'), false, ['a', 'b'], 'full')).toBe(true)
expect(connectsSeparately(ws('a', 'runnables'), true, [], 'full')).toBe(true)
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)
@@ -140,17 +140,6 @@ export function defaultConnection(workspaces: McpWorkspaceAccess[]): ConnectionD
return { all: false, picked: [first.id], oneEach: asTools.length > 1 }
}
/** Whether `workspace`, set to tools, needs its own connection next to the `covered` ones. A
* read-only connection runs nothing there either way. */
export function connectsSeparately(
workspace: McpWorkspaceAccess,
all: boolean,
covered: string[],
picked: McpAccess
) {
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)
@@ -32,7 +32,8 @@
import Select from '../select/Select.svelte'
import Section from '../Section.svelte'
import ClipboardPanel from '../details/ClipboardPanel.svelte'
import { narrows, workspaceMcpUrl } from '../mcp/workspaceAccess'
import { narrows, servedOn, workspaceMcpUrl } from '../mcp/workspaceAccess'
import McpNotIncludedCard from '../mcp/McpNotIncludedCard.svelte'
import McpAccessPicker, { type McpAccess } from '../mcp/McpAccessPicker.svelte'
import McpWorkspaceAccessList from '../mcp/McpWorkspaceAccessList.svelte'
import MultiSelect from '../select/MultiSelect.svelte'
@@ -400,11 +401,19 @@
const signInWorkspace = $derived(homeWorkspace ?? mcpBoundWorkspace)
const mcpAsTools = $derived(asTools(signInWorkspace))
// Shown only where a workspace gives other than the picked access.
const mcpNarrowed = $derived(
!!mcpWorkspaceAccess.current?.some(
(w) => (mcpAllWorkspaces || mcpWorkspaces.includes(w.id)) && narrows(w, mcpAccess)
const mcpCovered = $derived(
(mcpWorkspaceAccess.current ?? []).filter(
(w) => mcpAllWorkspaces || mcpWorkspaces.includes(w.id)
)
)
const mcpServed = $derived(servedOn(mcpCovered, mcpAllWorkspaces, mcpAccess))
// Left out of a token reaching several workspaces, as on the consent page.
const mcpLeftOut = $derived(
mcpAccess === 'selected'
? []
: mcpCovered.filter((w) => w.access === 'runnables' && !mcpServed.includes(w))
)
const mcpNarrowed = $derived(mcpServed.some((w) => narrows(w, mcpAccess)))
// The home page's tab also offers the workspace's own URL where `/api/mcp` is the main one.
const workspaceUrlOffered = $derived(!!homeWorkspace && !mcpAsTools)
const urlFor = (id: string | undefined) =>
@@ -447,13 +456,23 @@
<div class="mt-2">
<McpWorkspaceAccessList
named
workspaces={mcpWorkspaceAccess.current ?? []}
covered={mcpWorkspaces}
all={mcpAllWorkspaces}
workspaces={mcpServed}
access={mcpAccess}
/>
</div>
{/if}
{#if mcpLeftOut.length > 0}
<div class="mt-2">
<McpNotIncludedCard
workspaces={mcpLeftOut}
readOnly={mcpAccess === 'read'}
onSelect={(id) => {
mcpAllWorkspaces = false
mcpWorkspaces = [id]
}}
/>
</div>
{/if}
{/snippet}
{#snippet afterAccess()}
{#if canCarryAdmin}
@@ -640,7 +659,9 @@
{:else if mcpCreationMode}
<div class="flex flex-col gap-6">
<div class="flex flex-col gap-1">
<span class="text-xs font-semibold text-emphasis">MCP URL</span>
<span class="text-xs font-semibold text-emphasis"
>{workspaceUrlOffered ? 'Global MCP URL' : 'MCP URL'}</span
>
<ClipboardPanel content={mcpUrl} size="sm" />
<p class="text-2xs text-secondary">
Add it to your client as a remote MCP server.
@@ -655,7 +676,7 @@
</div>
{#if workspaceUrlOffered && homeWorkspace}
<div class="flex flex-col gap-1">
<span class="text-xs font-semibold text-emphasis">Or only {homeWorkspace}</span>
<span class="text-xs font-semibold text-emphasis">{homeWorkspace} MCP URL</span>
<ClipboardPanel content={workspaceMcpUrl(homeWorkspace)} size="sm" />
<p class="text-2xs text-secondary">
The sign-in skips the workspace choice, and the client reaches no other workspace.
@@ -3,7 +3,8 @@
import { McpOauthService, UserService } from '$lib/gen'
import { resource } from 'runed'
import McpWorkspaceAccessList from '$lib/components/mcp/McpWorkspaceAccessList.svelte'
import { narrows } from '$lib/components/mcp/workspaceAccess'
import { narrows, servedOn } from '$lib/components/mcp/workspaceAccess'
import McpNotIncludedCard from '$lib/components/mcp/McpNotIncludedCard.svelte'
import { sendUserToast } from '$lib/toast'
import Button from '../common/button/Button.svelte'
import Modal from '../common/modal/Modal.svelte'
@@ -110,11 +111,16 @@
async (on) => (on ? await McpOauthService.listMcpWorkspaceAccess({}).catch(() => []) : [])
)
const mcpAccess = $derived(mcpAccessOf(mcpScopes))
const mcpNarrowed = $derived(
(mcpWorkspaceAccess.current ?? []).some(
(w) => warnsFor.includes(w.id) && narrows(w, mcpAccess)
)
const mcpCovered = $derived(
(mcpWorkspaceAccess.current ?? []).filter((w) => warnsFor.includes(w.id))
)
const mcpServed = $derived(servedOn(mcpCovered, false, mcpAccess))
const mcpLeftOut = $derived(
mcpAccess === 'selected'
? []
: mcpCovered.filter((w) => w.access === 'runnables' && !mcpServed.includes(w))
)
const mcpNarrowed = $derived(mcpServed.some((w) => narrows(w, mcpAccess)))
// Carried over as is, the picker knowing nothing of them: dropping the workspace list
// would widen the token to every workspace, dropping `mcp:session` would move a sign-in
// back to the endpoint tools once it is given `mcp:all` again.
@@ -269,14 +275,20 @@
{#if mcpNarrowed}
<div class="mt-2">
<McpWorkspaceAccessList
named
workspaces={mcpWorkspaceAccess.current ?? []}
covered={warnsFor}
all={false}
named
workspaces={mcpServed}
access={mcpAccess}
/>
</div>
{/if}
{#if mcpLeftOut.length > 0}
<div class="mt-2">
<McpNotIncludedCard
workspaces={mcpLeftOut}
readOnly={mcpAccess === 'read'}
/>
</div>
{/if}
{/snippet}
</McpAccessPicker>
</div>
@@ -35,6 +35,9 @@
{/if}
</div>
<div class="flex flex-col gap-1">
{#if workspaceMcpUrl}
<span class="text-xs font-semibold text-emphasis">Global MCP URL</span>
{/if}
<ClipboardPanel content={mcpUrl ?? token} size="sm" />
{#if mcpUrl}
<p class="text-2xs text-secondary">Add it to your AI client as a remote MCP server.</p>
@@ -42,7 +45,7 @@
</div>
{#if workspaceMcpUrl}
<div class="flex flex-col gap-1">
<span class="text-xs font-semibold text-emphasis">Or only {workspace}</span>
<span class="text-xs font-semibold text-emphasis">{workspace} MCP URL</span>
<ClipboardPanel content={workspaceMcpUrl} size="sm" />
</div>
{/if}
@@ -18,13 +18,13 @@
type McpAccess
} from '$lib/components/mcp/McpAccessPicker.svelte'
import McpAccessSection from '$lib/components/mcp/McpAccessSection.svelte'
import McpNotIncludedCard from '$lib/components/mcp/McpNotIncludedCard.svelte'
import McpWorkspaceAccessList from '$lib/components/mcp/McpWorkspaceAccessList.svelte'
import {
defaultConnection,
connectionToolset,
givesAnything,
servedOn,
workspaceMcpUrl
servedOn
} from '$lib/components/mcp/workspaceAccess'
import {
McpOauthService,
@@ -36,8 +36,6 @@
import { sendUserToast } from '$lib/toast'
import { copyToClipboard } from '$lib/utils'
import Pencil from 'lucide-svelte/icons/pencil'
import ChevronDown from 'lucide-svelte/icons/chevron-down'
import ChevronRight from 'lucide-svelte/icons/chevron-right'
import Copy from 'lucide-svelte/icons/copy'
import Check from 'lucide-svelte/icons/check'
@@ -198,7 +196,6 @@
const connectionTools = $derived(
served.some((w) => givesAnything(w, access)) ? connectionToolset(access, bound) : undefined
)
let leftOutOpen = $state(false)
function coverDefault() {
const initial = defaultConnection(workspaceAccess)
allWorkspaces = initial.all
@@ -589,8 +586,6 @@
{#if served.length > 0}
<McpWorkspaceAccessList
workspaces={served}
covered={served.map((w) => w.id)}
all={false}
{access}
/>
{:else}
@@ -603,61 +598,16 @@
{/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">
<Button
variant="subtle"
unifiedSize="xs"
btnClasses="-m-1 w-fit font-semibold text-emphasis"
startIcon={{ icon: leftOutOpen ? ChevronDown : ChevronRight }}
aria-expanded={leftOutOpen}
onClick={() => (leftOutOpen = !leftOutOpen)}
>
{one ? 'Workspace' : 'Workspaces'}
{leftOut.map((w) => w.name).join(', ')}
{toolsOnly
? one
? 'connects on its own'
: 'connect on their own'
: one
? 'is not included'
: 'are not included'}
</Button>
{#if leftOutOpen && access === 'read'}
<p class="text-xs text-primary">
{one ? 'Its role offers' : 'Their roles offer'} only scripts and flows as tools, which
a read-only client cannot run.
</p>
{:else if leftOutOpen}
<p class="text-xs text-primary">
Scripts and flows as tools need a connection of their own: add {one
? 'its'
: 'each'} workspace URL to your AI client, or select it here instead.
</p>
<div class="flex flex-col gap-1">
{#each leftOut as w (w.id)}
<div class="flex items-center justify-between gap-2">
{#if !one}
<span class="text-xs font-semibold text-emphasis truncate">{w.name}</span>
{/if}
<div class="flex shrink-0 gap-1">
<Button
variant="default"
unifiedSize="xs"
startIcon={{ icon: Copy }}
title={workspaceMcpUrl(w.id)}
onClick={() => copyToClipboard(workspaceMcpUrl(w.id), true)}
>
Copy workspace URL
</Button>
<Button variant="default" unifiedSize="xs" onClick={() => connectOnly(w.id)}>
Select it
</Button>
</div>
</div>
{/each}
</div>
{/if}
<div class="mb-6">
<McpNotIncludedCard
workspaces={leftOut}
onTheirOwn={toolsOnly}
readOnly={access === 'read'}
showUrl
onSelect={connectOnly}
/>
</div>
{/if}
</div>
{/if}