feat: mcp token form reaches every workspace by default, editable everywhere; plain generated-token card

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-03 12:27:47 +01:00
co-authored by Claude Opus 5.5
parent 6656e66593
commit e3c178887c
2 changed files with 63 additions and 104 deletions
@@ -208,7 +208,6 @@
mcpCreationMode = true
void loadMcpUrlPolicy()
resetExpirationOnModeChange()
mcpAllWorkspaces = false
const current = defaultNewTokenWorkspace ?? $operatingWorkspace
// A token locked to a workspace the superadmin is not a member of works only with their rights.
mcpSuperAdmin =
@@ -216,6 +215,9 @@
!!$superadmin &&
!!current &&
!($usersWorkspaceStore?.workspaces ?? []).some((w) => w.id === current)
// Every workspace by default, as a sign-in does, with the current one kept picked for
// narrowing; but superadmin rights stay confined to the workspace that needs them.
mcpAllWorkspaces = !mcpSuperAdmin
mcpWorkspaces =
current && (lockWorkspace || mcpWorkspaceItems.some((w) => w.value === current))
? [current]
@@ -257,10 +259,8 @@
if (on) {
everyWorkspace = await listEveryWorkspace()
}
if (!lockWorkspace) {
const offered = new Set(mcpWorkspaceItems.map((w) => w.value))
mcpWorkspaces = mcpWorkspaces.filter((w) => offered.has(w))
}
const offered = new Set(mcpWorkspaceItems.map((w) => w.value))
mcpWorkspaces = mcpWorkspaces.filter((w) => offered.has(w))
}
async function createToken(mcpMode: boolean = false): Promise<void> {
@@ -291,10 +291,15 @@
if (mcpMode) {
newToken = undefined
newMcpToken = `${createdToken}`
newMcpTokenUrl = `${mcpUrl}?token=${createdToken}`
newMcpWorkspaceTokenUrl = workspaceUrlOffered
? `${workspaceMcpUrl(mcpBoundWorkspace!)}?token=${createdToken}`
: ''
newMcpTokenUrl = `${urlFor(mcpBoundWorkspace)}?token=${createdToken}`
// The token reaches the home workspace's own URL too when it covers that workspace.
newMcpWorkspaceTokenUrl =
workspaceUrlOffered &&
homeWorkspace &&
mcpBoundWorkspace !== homeWorkspace &&
(mcpAllWorkspaces || mcpWorkspaces.includes(homeWorkspace))
? `${workspaceMcpUrl(homeWorkspace)}?token=${createdToken}`
: ''
} else {
newMcpToken = undefined
newToken = `${createdToken}`
@@ -386,11 +391,14 @@
async ([on, superAdmin]) =>
on ? await McpOauthService.listMcpWorkspaceAccess({ superAdmin }).catch(() => []) : []
)
const mcpAsTools = $derived(
!!mcpWorkspaceAccess.current?.some(
(w) => w.id === mcpBoundWorkspace && w.access === 'runnables'
)
const asTools = (id: string | undefined) =>
!!id && !!mcpWorkspaceAccess.current?.some((w) => w.id === id && w.access === 'runnables')
// The home page's tab is about its own workspace, whatever the token form picks.
const homeWorkspace = $derived(
lockWorkspace ? (defaultNewTokenWorkspace ?? $operatingWorkspace) : undefined
)
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(
@@ -398,12 +406,10 @@
)
)
// The home page's tab also offers the workspace's own URL where `/api/mcp` is the main one.
const workspaceUrlOffered = $derived(lockWorkspace && !mcpAsTools && !!mcpBoundWorkspace)
const mcpUrl = $derived(
mcpAsTools && mcpBoundWorkspace
? workspaceMcpUrl(mcpBoundWorkspace)
: `${apiBaseUrl('mcp')}/api/mcp`
)
const workspaceUrlOffered = $derived(!!homeWorkspace && !mcpAsTools)
const urlFor = (id: string | undefined) =>
id && asTools(id) ? workspaceMcpUrl(id) : `${apiBaseUrl('mcp')}/api/mcp`
const mcpUrl = $derived(urlFor(signInWorkspace))
$effect(() => {
const requestedMcpMode = mcpOnly || openWithMcpMode
@@ -429,14 +435,7 @@
{#snippet mcpTokenForm()}
<div class="flex flex-col gap-3">
{#if !lockWorkspace}
{@render mcpWorkspacePicker()}
{:else if mcpBoundWorkspace}
<div class="flex flex-col gap-1">
<span class="text-emphasis text-xs font-semibold">Workspace</span>
<p class="text-xs text-primary">{mcpBoundWorkspace}</p>
</div>
{/if}
{@render mcpWorkspacePicker()}
<McpAccessPicker
workspaceId={scopeWorkspaceId}
bind:scopes={mcpScopes}
@@ -654,10 +653,10 @@
{/if}
</p>
</div>
{#if workspaceUrlOffered && mcpBoundWorkspace}
{#if workspaceUrlOffered && homeWorkspace}
<div class="flex flex-col gap-1">
<span class="text-xs font-semibold text-emphasis">Or only {mcpBoundWorkspace}</span>
<ClipboardPanel content={workspaceMcpUrl(mcpBoundWorkspace)} size="sm" />
<span class="text-xs font-semibold text-emphasis">Or only {homeWorkspace}</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.
</p>
@@ -871,7 +870,7 @@
token={newMcpToken}
mcpUrl={newMcpTokenUrl}
workspaceMcpUrl={newMcpWorkspaceTokenUrl || undefined}
workspace={mcpBoundWorkspace}
workspace={homeWorkspace}
/>
{/if}
</div>
@@ -1,9 +1,8 @@
<script lang="ts">
import { Check, Link, X } from 'lucide-svelte'
import { X } from 'lucide-svelte'
import { Button } from '$lib/components/common'
import Alert from '../common/alert/Alert.svelte'
import { classes } from '../common/alert/model'
import { shell } from 'svelte-highlight/languages'
import CopyableCodeBlock from '../details/CopyableCodeBlock.svelte'
import ClipboardPanel from '../details/ClipboardPanel.svelte'
interface Props {
token: string
@@ -17,76 +16,37 @@
let { token, mcpUrl, workspaceMcpUrl, workspace, title, onClose }: Props = $props()
const displayTitle = $derived(
title || (mcpUrl ? 'MCP URL generated successfully' : 'Token created successfully')
)
const info = $derived(
`Make sure to copy your ${mcpUrl ? 'MCP Server URL' : 'personal access token'} now. You won\'t be able to see it again!`
)
const tokenOrUrl = $derived(mcpUrl ? mcpUrl : token)
// Use alert model for consistent styling with design system
const alertStyles = classes.info
const displayTitle = $derived(title || (mcpUrl ? 'MCP URL generated' : 'Token created'))
</script>
<!-- Use surface-tertiary for elevated content according to brand guidelines -->
<div class="border bg-surface-tertiary rounded-lg mb-6 p-4 shadow-md relative">
<!-- Close button in top-right corner -->
{#if onClose}
<button
onclick={onClose}
class="absolute top-2 right-2 p-1 text-secondary hover:text-primary surface-hover hover:surface-secondary rounded transition-colors"
title="Close"
>
<X size={16} />
</button>
{/if}
<div class="flex items-start gap-3">
<!-- Icon with info alert styling -->
<div
class="flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center mt-0.5 {alertStyles.iconClass}"
>
{#if mcpUrl}
<Link size={16} />
{:else}
<Check size={16} />
{/if}
</div>
<div class="flex-1 min-w-0 pr-6">
<!-- Page title typography according to brand guidelines -->
<h4 class="text-sm font-semibold text-emphasis mb-2">
{displayTitle}
</h4>
<div class="flex flex-col gap-y-1">
<!-- Token display with proper surface and border styling -->
<CopyableCodeBlock code={tokenOrUrl} language={shell} wrap />
{#if workspaceMcpUrl}
<p class="mt-1 text-xs font-semibold text-emphasis">Or only {workspace}</p>
<CopyableCodeBlock code={workspaceMcpUrl} language={shell} wrap />
{/if}
<!-- Warning alert using existing Alert component -->
<div class="mt-1">
<Alert type="warning" title="Important" size="xs">
{info}
</Alert>
</div>
{#if mcpUrl}
<!-- Additional info using alert info styling -->
<div class="mt-1 {alertStyles.bgClass} rounded-md p-2">
<p class="text-xs {alertStyles.descriptionClass}">
<strong>Next steps:</strong> Add this URL to your MCP-compatible client (like Claude Desktop)
as a remote MCP server.
</p>
</div>
{/if}
</div>
</div>
<div class="mb-6 flex flex-col gap-3 rounded-md border bg-surface-tertiary p-4">
<div class="flex items-center justify-between gap-2">
<span class="text-sm font-semibold text-emphasis">{displayTitle}</span>
{#if onClose}
<Button
variant="subtle"
unifiedSize="xs"
iconOnly
startIcon={{ icon: X }}
aria-label="Close"
title="Close"
onClick={onClose}
/>
{/if}
</div>
<div class="flex flex-col gap-1">
<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>
{/if}
</div>
{#if workspaceMcpUrl}
<div class="flex flex-col gap-1">
<span class="text-xs font-semibold text-emphasis">Or only {workspace}</span>
<ClipboardPanel content={workspaceMcpUrl} size="sm" />
</div>
{/if}
<Alert type="warning" size="xs" title="Copy it now">
{mcpUrl ? 'The URL holds' : 'This is'} the token, and it is not shown again.
</Alert>
</div>