diff --git a/frontend/src/lib/components/settings/CreateToken.svelte b/frontend/src/lib/components/settings/CreateToken.svelte index de5d473dec..5e8bffac1c 100644 --- a/frontend/src/lib/components/settings/CreateToken.svelte +++ b/frontend/src/lib/components/settings/CreateToken.svelte @@ -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 { @@ -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()}
- {#if !lockWorkspace} - {@render mcpWorkspacePicker()} - {:else if mcpBoundWorkspace} -
- Workspace -

{mcpBoundWorkspace}

-
- {/if} + {@render mcpWorkspacePicker()}
- {#if workspaceUrlOffered && mcpBoundWorkspace} + {#if workspaceUrlOffered && homeWorkspace}
- Or only {mcpBoundWorkspace} - + Or only {homeWorkspace} +

The sign-in skips the workspace choice, and the client reaches no other workspace.

@@ -871,7 +870,7 @@ token={newMcpToken} mcpUrl={newMcpTokenUrl} workspaceMcpUrl={newMcpWorkspaceTokenUrl || undefined} - workspace={mcpBoundWorkspace} + workspace={homeWorkspace} /> {/if}
diff --git a/frontend/src/lib/components/settings/TokenDisplay.svelte b/frontend/src/lib/components/settings/TokenDisplay.svelte index 6c7168782a..8dc37a6f32 100644 --- a/frontend/src/lib/components/settings/TokenDisplay.svelte +++ b/frontend/src/lib/components/settings/TokenDisplay.svelte @@ -1,9 +1,8 @@ - -
- - {#if onClose} - - {/if} - -
- -
- {#if mcpUrl} - - {:else} - - {/if} -
- -
- -

- {displayTitle} -

- -
- - - {#if workspaceMcpUrl} -

Or only {workspace}

- - {/if} - - -
- - {info} - -
- - {#if mcpUrl} - -
-

- Next steps: Add this URL to your MCP-compatible client (like Claude Desktop) - as a remote MCP server. -

-
- {/if} -
-
+
+
+ {displayTitle} + {#if onClose} +
+
+ + {#if mcpUrl} +

Add it to your AI client as a remote MCP server.

+ {/if} +
+ {#if workspaceMcpUrl} +
+ Or only {workspace} + +
+ {/if} + + {mcpUrl ? 'The URL holds' : 'This is'} the token, and it is not shown again. +