mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-04 08:09:16 +00:00
* feat: cap mcp access per workspace role Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep read-and-run tools under a selection, audit capped calls Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: no hub scripts under an mcp limit, count role changes once stored Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: choose mcp scripts and flows per workspace, not on instance roles Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: limit mcp access of a role with a toggle Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: point ee ref at the companion merged with ee main Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: read a role's instance mcp limit only from its own key Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: disable scripts and flows as tools on a role that cannot run Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: approve-only mcp connect page showing per-workspace access Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name only what a connection gets, refuse scoped callers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: align the limit access fold Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: show the access the server gives, keep picked workspaces Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name what a non-authoring role edits over mcp Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep the workspace picked under a selection, cap the tool count query Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: show what a role limit leaves a new mcp token Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: preview a token's mcp access with its superadmin rights Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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> * fix: bind a tools-only connection to its workspace, list a run-and-edit role's full tools Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: shorten the run-and-edit access label, list the edits in its tooltip Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name a non-authoring role's access build and run, with a restricted badge Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name the workspace that connects on its own, set its two ways apart Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: bold title and two subheaders for a workspace that connects on its own Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: list the one toolset a connection gets, trimmed only for a bound workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: one tool list per connection, fold the workspaces that connect on their own Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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> * feat: one access select in the token form and the consent page, workspace url beside /api/mcp Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: one per-workspace access list on the consent page and token forms, in place of the narrowing alert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: list a role's scripts and flows as tools on the consent page, restricted badge before the access Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep withheld admin rights in the tools preview, name what a partial author or the deploy rules hold back Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: refuse the tools preview to a token withholding superadmin rights, restricted badge after a single access line Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: workspace line before the token form's access, one workspace's access as a line, plainer hints Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: preview tools with the rights the credential carries, one access section shared by the consent page and token forms Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: list a role's runnable tools under the workspace route, authenticated there as any workspace call Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: put the consent page's pens next to their section titles Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: leave a tools workspace out of a read-only connection's list and say why in its card, select it from the card Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep one row and url per workspace that connects separately Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: offer the access pen unless every covered workspace's role settles the access Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 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> * 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> * fix: close the consent page's card markup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: show the not-included card under the workspaces it is about Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: quiet show tools action at the right of the access title Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: one access line on the mcp consent page, limit access capped at it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: same access line on the mcp token forms as on the consent page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: mcp tool listing reckons access as the consent page does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: token form shows the tools the connection lists, drop the old toolset guess Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: one mcp access check for calls, tool listing and the consent page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: pens next to the workspace and access values on the mcp consent page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: limit access dialog keeps the clamped level when it opens Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: mcp refusal names the workspace and what the session can do there Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: no limit pen on a tools workspace, stricter-of note in the limit dialog Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: one sentence for the role cap on the mcp page, dialog and token form Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: role mcp access as a select with what members get and the urls to share Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: name the top mcp level everything your role allows; keep the pen for a requested selection Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep read only for a role that cannot run, which still holds its admins Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: tools workspaces selectable for a selection, one full-access label for external clients Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: workspace role mcp access always starts from the instance's setting Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: a stored read only holds admins too in the members-get line Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep the limit pen once a selection is made on a tools workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 4a19159ab6f634de29673aa530b76d9a9710ab78 This commit updates the EE repository reference after PR #1033 was merged in windmill-ee-private. Previous ee-repo-ref: 8317dbf5116aaca61acfe2f20e4c2340b3f17377 New ee-repo-ref: 4a19159ab6f634de29673aa530b76d9a9710ab78 Automated by sync-ee-ref workflow. * chore: update ee-repo-ref to 4a19159ab6f634de29673aa530b76d9a9710ab78 This commit updates the EE repository reference after PR #1033 was merged in windmill-ee-private. Previous ee-repo-ref: 8317dbf5116aaca61acfe2f20e4c2340b3f17377 New ee-repo-ref: 4a19159ab6f634de29673aa530b76d9a9710ab78 Automated by sync-ee-ref workflow. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com> Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
888 lines
30 KiB
Svelte
888 lines
30 KiB
Svelte
<script lang="ts">
|
|
import { onMount, untrack } from 'svelte'
|
|
import { resource } from 'runed'
|
|
import {
|
|
enterpriseLicense,
|
|
superadmin,
|
|
userStore,
|
|
userWorkspaces,
|
|
usersWorkspaceStore,
|
|
type UserWorkspace
|
|
} from '$lib/stores'
|
|
import { Alert, Button, Skeleton } from '../common'
|
|
import { triggerableByAI } from '$lib/actions/triggerableByAI.svelte'
|
|
import Toggle from '../Toggle.svelte'
|
|
import {
|
|
McpOauthService,
|
|
SettingService,
|
|
SettingsService,
|
|
UserService,
|
|
type NewToken
|
|
} from '$lib/gen'
|
|
import { listEveryWorkspace, mcpTokenUrlDisabled } from '$lib/mcpAuth'
|
|
import { apiBaseUrl } from '$lib/apiBaseUrl.svelte'
|
|
import TokenDisplay from './TokenDisplay.svelte'
|
|
import TokenInspector from './TokenInspector.svelte'
|
|
import CollapseLink from '../CollapseLink.svelte'
|
|
import ScopesPicker from './ScopesPicker.svelte'
|
|
import AdminRelianceNotice from './AdminRelianceNotice.svelte'
|
|
import { parseMaxTokenExpirationDays } from '$lib/tokenExpiration'
|
|
|
|
import TextInput from '../text_input/TextInput.svelte'
|
|
import Select from '../select/Select.svelte'
|
|
import Section from '../Section.svelte'
|
|
import ClipboardPanel from '../details/ClipboardPanel.svelte'
|
|
import { servedOn, workspaceMcpUrl } from '../mcp/workspaceAccess'
|
|
import McpNotIncludedCard from '../mcp/McpNotIncludedCard.svelte'
|
|
import McpAccessPicker, { type McpAccess } from '../mcp/McpAccessPicker.svelte'
|
|
import McpAccessLine from '../mcp/McpAccessLine.svelte'
|
|
import MultiSelect from '../select/MultiSelect.svelte'
|
|
import ToggleButtonGroup from '../common/toggleButton-v2/ToggleButtonGroup.svelte'
|
|
import ToggleButton from '../common/toggleButton-v2/ToggleButton.svelte'
|
|
import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte'
|
|
|
|
const operatingWorkspace = useOperatingWorkspace()
|
|
|
|
interface Props {
|
|
showMcpMode?: boolean
|
|
openWithMcpMode?: boolean
|
|
mcpOnly?: boolean
|
|
lockWorkspace?: boolean
|
|
title?: string
|
|
newTokenLabel?: string
|
|
defaultNewTokenWorkspace?: string
|
|
scopes?: string[]
|
|
onTokenCreated: (token: string) => void
|
|
displayCreateToken?: boolean
|
|
}
|
|
|
|
let {
|
|
showMcpMode = false,
|
|
openWithMcpMode = false,
|
|
mcpOnly = false,
|
|
lockWorkspace = false,
|
|
title = 'Add a new token',
|
|
defaultNewTokenWorkspace,
|
|
scopes,
|
|
onTokenCreated,
|
|
newTokenLabel = $bindable(undefined),
|
|
displayCreateToken = true
|
|
}: Props = $props()
|
|
|
|
let newToken = $state<string | undefined>(undefined)
|
|
let newTokenTestWorkspace = $state<string | undefined>(undefined)
|
|
let newTokenTestOpen = $state(false)
|
|
let newMcpToken = $state<string | undefined>(undefined)
|
|
let newMcpTokenUrl = $state('')
|
|
let newMcpWorkspaceTokenUrl = $state('')
|
|
// What an MCP token may do, as the access picker sets it.
|
|
let mcpAccess = $state<McpAccess>('full')
|
|
let mcpScopes = $state<string[]>(['mcp:all'])
|
|
// What the user picked; `newTokenExpiration` is that pick held within the ceiling.
|
|
let pickedExpiration = $state<number | undefined>(undefined)
|
|
// A token is bound to one workspace unless the user picks all of them: a bound token reaches
|
|
// only that workspace's routes, none of the instance-level ones.
|
|
const initialTokenWorkspace = () => defaultNewTokenWorkspace ?? $operatingWorkspace
|
|
let newTokenWorkspace = $state<string | undefined>(untrack(initialTokenWorkspace))
|
|
let newTokenReach = $state<'workspace' | 'all'>(
|
|
untrack(initialTokenWorkspace) ? 'workspace' : 'all'
|
|
)
|
|
// The owner's admin and superadmin rights are carried only when asked for.
|
|
let carryAdmin = $state(false)
|
|
let carrySuperAdmin = $state(false)
|
|
// The workspaces an MCP token reaches. One binds the token to it; several leave it unbound
|
|
// and are listed in its scopes; all of them leaves it unbound with no list, so it also
|
|
// reaches the workspaces its owner joins later.
|
|
let mcpWorkspaces = $state<string[]>([])
|
|
let mcpAllWorkspaces = $state(false)
|
|
// A superadmin's MCP token reaches only their memberships unless it carries their rights.
|
|
let mcpSuperAdmin = $state(false)
|
|
let everyWorkspace = $state<{ id: string; name: string }[]>([])
|
|
let mcpCreationMode = $state(false)
|
|
let lastRequestedMcpMode = $state<boolean | undefined>(undefined)
|
|
let mcpLabelAutofilled = $state(false)
|
|
|
|
let pickedScopes = $state<string[] | null>(null)
|
|
let readOnly = $state(false)
|
|
let allowedIpsText = $state('')
|
|
let allowedIps = $derived(
|
|
allowedIpsText
|
|
.split(/[\s,]+/)
|
|
.map((s) => s.trim())
|
|
.filter((s) => s.length > 0)
|
|
)
|
|
// The address this browser calls from, as the server's IP checks resolve it.
|
|
let clientIp = $state<string | undefined>(undefined)
|
|
let clientIpRequested = false
|
|
// While a whole private range is trusted, any host there is believed when it names a client:
|
|
// an allowlist then holds only against callers outside the instance's network.
|
|
let privateRangesTrusted = $state<boolean | undefined>(undefined)
|
|
$effect(() => {
|
|
if ($enterpriseLicense && !clientIpRequested) {
|
|
clientIpRequested = true
|
|
SettingsService.getClientIp()
|
|
.then((ip) => (clientIp = ip.trim() || undefined))
|
|
.catch(() => {})
|
|
SettingService.getClientIpTrust()
|
|
.then((t) => (privateRangesTrusted = t.private_ranges_trusted))
|
|
.catch(() => {})
|
|
}
|
|
})
|
|
function addClientIp() {
|
|
if (clientIp && !allowedIps.includes(clientIp)) {
|
|
allowedIpsText = [...allowedIps, clientIp].join(', ')
|
|
}
|
|
}
|
|
// How this instance lets an MCP client in. `oauth` means it refuses `?token=`, so a
|
|
// generated token would not get a client in and the URL is handed over bare instead.
|
|
// A failed read lands on `oauth`: the bare URL works whichever way the setting is,
|
|
// whereas guessing `token` mints a non-expiring credential the server may refuse.
|
|
type McpUrlPolicy = 'loading' | 'token' | 'oauth'
|
|
let mcpUrlPolicy = $state<McpUrlPolicy>('loading')
|
|
|
|
async function loadMcpUrlPolicy() {
|
|
mcpUrlPolicy = 'loading'
|
|
try {
|
|
mcpUrlPolicy = (await mcpTokenUrlDisabled()) ? 'oauth' : 'token'
|
|
} catch (err) {
|
|
console.error('Failed to load the MCP token setting:', err)
|
|
mcpUrlPolicy = 'oauth'
|
|
}
|
|
}
|
|
|
|
const DAY_SECS = 24 * 60 * 60
|
|
const EXPIRATION_CHOICES = [
|
|
{ label: '15 minutes', value: 15 * 60 },
|
|
{ label: '30 minutes', value: 30 * 60 },
|
|
{ label: '1 hour', value: 60 * 60 },
|
|
{ label: '1 day', value: DAY_SECS },
|
|
{ label: '7 days', value: 7 * DAY_SECS },
|
|
{ label: '30 days', value: 30 * DAY_SECS },
|
|
{ label: '90 days', value: 90 * DAY_SECS },
|
|
{ label: '180 days', value: 180 * DAY_SECS },
|
|
{ label: '365 days', value: 365 * DAY_SECS }
|
|
]
|
|
|
|
// The `max_token_expiration_days` instance setting. The server shortens any token that asks
|
|
// for longer, or for no expiration, so with it set the form only offers what would be kept.
|
|
let maxExpirationDays = $state<number | undefined>(undefined)
|
|
|
|
onMount(async () => {
|
|
let value: unknown
|
|
try {
|
|
value = await SettingService.getGlobal({ key: 'max_token_expiration_days' })
|
|
} catch {
|
|
// The server still shortens tokens itself; the form just offers every choice.
|
|
return
|
|
}
|
|
const days = parseMaxTokenExpirationDays(value)
|
|
if (days == undefined) {
|
|
return
|
|
}
|
|
maxExpirationDays = days
|
|
})
|
|
|
|
// Without a ceiling the expiration field is hidden in MCP mode, so a value picked on one side
|
|
// of the toggle must not ride along unseen. With one, the field shows in both modes and keeps
|
|
// its value.
|
|
function resetExpirationOnModeChange() {
|
|
if (maxExpirationSecs == undefined) {
|
|
pickedExpiration = undefined
|
|
}
|
|
}
|
|
|
|
function ensureCurrentWorkspaceIncluded(
|
|
workspacesList: UserWorkspace[],
|
|
currentWorkspace: string | undefined
|
|
) {
|
|
if (!currentWorkspace) {
|
|
return workspacesList
|
|
}
|
|
const hasCurrentWorkspace = workspacesList.some((w) => w.id === currentWorkspace)
|
|
if (hasCurrentWorkspace) {
|
|
return workspacesList
|
|
}
|
|
return [{ id: currentWorkspace, name: currentWorkspace }, ...workspacesList]
|
|
}
|
|
|
|
function enterMcpMode() {
|
|
mcpCreationMode = true
|
|
void loadMcpUrlPolicy()
|
|
resetExpirationOnModeChange()
|
|
const current = defaultNewTokenWorkspace ?? $operatingWorkspace
|
|
// A token locked to a workspace the superadmin is not a member of works only with their rights.
|
|
mcpSuperAdmin =
|
|
lockWorkspace &&
|
|
!!$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]
|
|
: []
|
|
newToken = undefined
|
|
newMcpToken = undefined
|
|
if (!newTokenLabel) {
|
|
newTokenLabel = 'MCP token'
|
|
mcpLabelAutofilled = true
|
|
} else {
|
|
mcpLabelAutofilled = false
|
|
}
|
|
}
|
|
|
|
function exitMcpMode() {
|
|
mcpCreationMode = false
|
|
resetExpirationOnModeChange()
|
|
newTokenWorkspace = initialTokenWorkspace()
|
|
newTokenReach = newTokenWorkspace ? 'workspace' : 'all'
|
|
newMcpToken = undefined
|
|
readOnly = false
|
|
if (mcpLabelAutofilled) {
|
|
newTokenLabel = undefined
|
|
}
|
|
mcpLabelAutofilled = false
|
|
}
|
|
|
|
// Selected scripts and flows are listed per workspace, so a selection keeps one of them.
|
|
function setMcpAccess(access: McpAccess) {
|
|
mcpAccess = access
|
|
if (access === 'selected') {
|
|
mcpAllWorkspaces = false
|
|
mcpWorkspaces = mcpWorkspaces.slice(0, 1)
|
|
}
|
|
}
|
|
|
|
async function setMcpSuperAdmin(on: boolean) {
|
|
mcpSuperAdmin = on
|
|
if (on) {
|
|
everyWorkspace = await listEveryWorkspace()
|
|
}
|
|
const offered = new Set(mcpWorkspaceItems.map((w) => w.value))
|
|
mcpWorkspaces = mcpWorkspaces.filter((w) => offered.has(w))
|
|
}
|
|
|
|
async function createToken(mcpMode: boolean = false): Promise<void> {
|
|
try {
|
|
let date: Date | undefined
|
|
if (newTokenExpiration) {
|
|
date = new Date(new Date().getTime() + newTokenExpiration * 1000)
|
|
}
|
|
|
|
const pickedOrFixed = scopes ?? (mcpMode ? mcpScopes : pickedScopes) ?? undefined
|
|
const tokenScopes =
|
|
pickedOrFixed && workspacesScope ? [...pickedOrFixed, workspacesScope] : pickedOrFixed
|
|
|
|
const createdToken = await UserService.createToken({
|
|
requestBody: {
|
|
label: newTokenLabel,
|
|
expiration: date?.toISOString(),
|
|
scopes: tokenScopes,
|
|
workspace_id: tokenWorkspaceId,
|
|
read_only: mcpMode ? false : readOnly,
|
|
super_admin: mcpMode ? mcpSuperAdmin : carrySuperAdmin,
|
|
admin: carryAdmin,
|
|
allowed_ips:
|
|
$enterpriseLicense && !mcpMode && allowedIps.length > 0 ? allowedIps : undefined
|
|
} as NewToken
|
|
})
|
|
|
|
if (mcpMode) {
|
|
newToken = undefined
|
|
newMcpToken = `${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}`
|
|
newTokenTestWorkspace = tokenWorkspaceId ?? $operatingWorkspace
|
|
newTokenTestOpen = false
|
|
}
|
|
|
|
onTokenCreated(`${createdToken}`)
|
|
if (!mcpOnly) {
|
|
mcpCreationMode = false
|
|
}
|
|
} catch (err) {
|
|
console.error('Failed to create token:', err)
|
|
}
|
|
}
|
|
|
|
const workspaces = $derived(ensureCurrentWorkspaceIncluded($userWorkspaces, $operatingWorkspace))
|
|
// `$userWorkspaces` offers a superadmin workspaces they are not a member of, which only a
|
|
// token carrying their rights reaches.
|
|
const mcpWorkspaceItems = $derived(
|
|
($superadmin
|
|
? mcpSuperAdmin
|
|
? everyWorkspace
|
|
: ($usersWorkspaceStore?.workspaces ?? [])
|
|
: workspaces
|
|
).map((w) => ({ label: w.name, value: w.id }))
|
|
)
|
|
const mcpBoundWorkspace = $derived(
|
|
!mcpAllWorkspaces && mcpWorkspaces.length === 1 ? mcpWorkspaces[0] : undefined
|
|
)
|
|
const mcpReachesWorkspaces = $derived(mcpAllWorkspaces || mcpWorkspaces.length > 0)
|
|
const tokenWorkspaceId = $derived(
|
|
mcpCreationMode ? mcpBoundWorkspace : newTokenReach === 'all' ? undefined : newTokenWorkspace
|
|
)
|
|
// Offered to who holds admin rights here; the server holds the token within the owner's
|
|
// rights in each workspace, so this only hides a switch that would do nothing.
|
|
const canCarryAdmin = $derived(!!$userStore?.is_admin || !!$superadmin)
|
|
const standardScopes = $derived(scopes ?? pickedScopes ?? undefined)
|
|
const tokenWorkspaceItems = $derived(workspaces.map((w) => ({ label: w.name, value: w.id })))
|
|
const workspacesScope = $derived(
|
|
mcpCreationMode && !mcpAllWorkspaces && mcpWorkspaces.length > 1
|
|
? `mcp:workspaces:${mcpWorkspaces.join(',')}`
|
|
: undefined
|
|
)
|
|
|
|
// Mirrors the server's exemption for tokens owned by a service account: one in the workspace
|
|
// the token is for, or in any workspace for a workspace-less token.
|
|
const isServiceAccount = $derived.by(() => {
|
|
const memberships = $usersWorkspaceStore?.workspaces ?? []
|
|
return tokenWorkspaceId == undefined
|
|
? memberships.some((w) => w.is_service_account)
|
|
: memberships.some((w) => w.id === tokenWorkspaceId && w.is_service_account)
|
|
})
|
|
const maxExpirationSecs = $derived(
|
|
maxExpirationDays == undefined || isServiceAccount ? undefined : maxExpirationDays * DAY_SECS
|
|
)
|
|
const maxExpirationLabel = $derived(
|
|
maxExpirationDays === 1 ? '1 day' : `${maxExpirationDays} days`
|
|
)
|
|
const expirationItems = $derived(
|
|
maxExpirationSecs == undefined
|
|
? [{ label: 'No expiration', value: undefined }, ...EXPIRATION_CHOICES]
|
|
: [
|
|
...EXPIRATION_CHOICES.filter((choice) => choice.value < maxExpirationSecs),
|
|
{ label: `${maxExpirationLabel} (maximum)`, value: maxExpirationSecs }
|
|
]
|
|
)
|
|
// A ceiling can start applying after the pick: once the setting loads, or when the MCP workspace
|
|
// moves to one where the account is not a service account.
|
|
const newTokenExpiration = $derived(
|
|
maxExpirationSecs != undefined &&
|
|
(pickedExpiration == undefined || pickedExpiration > maxExpirationSecs)
|
|
? maxExpirationSecs
|
|
: pickedExpiration
|
|
)
|
|
// The workspace used to browse scripts/flows/endpoints in the scope picker: the first
|
|
// picked one, or the current one for a token reaching all of them.
|
|
const scopeWorkspaceId = $derived(
|
|
(mcpCreationMode && !mcpAllWorkspaces ? mcpWorkspaces[0] : tokenWorkspaceId) ||
|
|
$operatingWorkspace ||
|
|
''
|
|
)
|
|
// The server builds this URL's OAuth metadata from the same API base url, and a client
|
|
// rejects a mismatch. One URL whatever the access, as the token's scopes decide which tools it
|
|
// gets, but for a workspace whose role offers scripts and flows as tools: those are served to a
|
|
// connection to that workspace alone, which its own URL makes of any sign-in.
|
|
const mcpWorkspaceAccess = resource(
|
|
() => [mcpCreationMode, mcpSuperAdmin] as const,
|
|
async ([on, superAdmin]) =>
|
|
on ? await McpOauthService.listMcpWorkspaceAccess({ superAdmin }).catch(() => []) : []
|
|
)
|
|
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 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))
|
|
)
|
|
// 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) =>
|
|
id && asTools(id) ? workspaceMcpUrl(id) : `${apiBaseUrl('mcp')}/api/mcp`
|
|
const mcpUrl = $derived(urlFor(signInWorkspace))
|
|
|
|
$effect(() => {
|
|
const requestedMcpMode = mcpOnly || openWithMcpMode
|
|
if (requestedMcpMode === lastRequestedMcpMode) {
|
|
return
|
|
}
|
|
|
|
if (requestedMcpMode) {
|
|
enterMcpMode()
|
|
} else {
|
|
exitMcpMode()
|
|
}
|
|
|
|
lastRequestedMcpMode = requestedMcpMode
|
|
})
|
|
|
|
$effect(() => {
|
|
if (mcpLabelAutofilled && newTokenLabel !== 'MCP token') {
|
|
mcpLabelAutofilled = false
|
|
}
|
|
})
|
|
</script>
|
|
|
|
{#snippet mcpTokenForm()}
|
|
<div class="flex flex-col gap-3">
|
|
{@render mcpWorkspacePicker()}
|
|
{#if mcpLeftOut.length > 0}
|
|
<McpNotIncludedCard
|
|
workspaces={mcpLeftOut}
|
|
readOnly={mcpAccess === 'read'}
|
|
onSelect={(id) => {
|
|
mcpAllWorkspaces = false
|
|
mcpWorkspaces = [id]
|
|
}}
|
|
/>
|
|
{/if}
|
|
<McpAccessPicker
|
|
workspaceId={scopeWorkspaceId}
|
|
bind:scopes={mcpScopes}
|
|
bind:access={() => mcpAccess, setMcpAccess}
|
|
showTools
|
|
served={mcpServed}
|
|
>
|
|
{#snippet belowAccess()}
|
|
<div class="mt-1"><McpAccessLine workspaces={mcpServed} access={mcpAccess} /></div>
|
|
{/snippet}
|
|
{#snippet afterAccess()}
|
|
{#if canCarryAdmin}
|
|
{@render adminToggle(mcpSuperAdmin)}
|
|
{/if}
|
|
{#if $superadmin}
|
|
<Toggle
|
|
bind:checked={() => mcpSuperAdmin, setMcpSuperAdmin}
|
|
disabled={mcpWorkspaceAccess.loading}
|
|
options={{
|
|
right: 'Superadmin rights',
|
|
rightTooltip:
|
|
'The token carries your superadmin rights: admin in every workspace of the instance, including ones you are not a member of.'
|
|
}}
|
|
size="xs"
|
|
/>
|
|
{/if}
|
|
{#if carryAdmin || mcpSuperAdmin}
|
|
{@render scopesBoundRights(true, true)}
|
|
{/if}
|
|
{/snippet}
|
|
</McpAccessPicker>
|
|
{#if !mcpOnly}
|
|
<div>
|
|
<span class="block mb-1 text-emphasis text-xs font-semibold"
|
|
>Label <span class="text-xs text-primary">(optional)</span></span
|
|
>
|
|
<TextInput inputProps={{ type: 'text' }} bind:value={newTokenLabel} class="w-full" />
|
|
</div>
|
|
{/if}
|
|
{#if maxExpirationSecs != undefined}
|
|
<div>
|
|
<span class="block mb-1 text-xs text-emphasis font-semibold">Expires in</span>
|
|
<Select
|
|
bind:value={() => newTokenExpiration, (v) => (pickedExpiration = v)}
|
|
placeholder="Pick an expiration"
|
|
inputClass="w-full"
|
|
items={expirationItems}
|
|
/>
|
|
<p class="mt-1 text-xs text-tertiary"
|
|
>This instance limits tokens to {maxExpirationLabel}.</p
|
|
>
|
|
</div>
|
|
{/if}
|
|
{#if canCarryAdmin && !carryAdmin && !mcpSuperAdmin}
|
|
<AdminRelianceNotice
|
|
workspaceIds={mcpAllWorkspaces ? undefined : mcpWorkspaces}
|
|
scopes={mcpScopes}
|
|
/>
|
|
{/if}
|
|
<div class="flex">
|
|
<Button
|
|
onclick={() => createToken(true)}
|
|
disabled={!mcpReachesWorkspaces || mcpScopes.length === 0}
|
|
variant="default"
|
|
unifiedSize="sm"
|
|
>
|
|
Generate URL with token
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
{/snippet}
|
|
|
|
{#snippet adminToggle(inSuperadmin: boolean)}
|
|
{#if inSuperadmin}
|
|
<Toggle
|
|
checked
|
|
disabled
|
|
options={{
|
|
right: 'Workspace admin rights',
|
|
rightTooltip:
|
|
'Included in superadmin rights: the token is admin in every workspace it reaches.'
|
|
}}
|
|
size="xs"
|
|
/>
|
|
{:else}
|
|
<Toggle
|
|
bind:checked={carryAdmin}
|
|
options={{
|
|
right: 'Workspace admin rights',
|
|
rightTooltip:
|
|
'The token carries your admin rights in the workspaces it reaches, within its scopes. Off, it acts as a regular member there.'
|
|
}}
|
|
size="xs"
|
|
/>
|
|
{/if}
|
|
{/snippet}
|
|
|
|
{#snippet scopesBoundRights(scoped: boolean, mcp: boolean)}
|
|
<p class="text-2xs text-hint">
|
|
{#if mcp}
|
|
Its access above still applies: these rights reach items you are not a member of, only through
|
|
the tools that access allows.
|
|
{:else if scoped}
|
|
Its scopes still apply: these rights reach items you are not a member of, only for what the
|
|
scopes allow. They add nothing the scopes leave out.
|
|
{:else}
|
|
With no scopes, the token can do everything these rights let you do. Pick scopes below to
|
|
bound it.
|
|
{/if}
|
|
</p>
|
|
{/snippet}
|
|
|
|
{#snippet mcpWorkspacePicker()}
|
|
<div class="flex flex-col gap-1">
|
|
{#if mcpAccess === 'selected'}
|
|
<span class="block text-emphasis text-xs font-semibold">Workspace</span>
|
|
<Select
|
|
bind:value={() => mcpWorkspaces[0], (v) => (mcpWorkspaces = v ? [v] : [])}
|
|
items={mcpWorkspaceItems}
|
|
placeholder="Pick a workspace"
|
|
/>
|
|
{:else}
|
|
<span class="block text-emphasis text-xs font-semibold">Workspaces</span>
|
|
<Toggle
|
|
bind:checked={mcpAllWorkspaces}
|
|
options={{
|
|
right: mcpSuperAdmin
|
|
? 'All workspaces, including ones created later'
|
|
: 'All my workspaces, including ones I join later'
|
|
}}
|
|
size="xs"
|
|
/>
|
|
{#if !mcpAllWorkspaces}
|
|
<MultiSelect
|
|
bind:value={mcpWorkspaces}
|
|
items={mcpWorkspaceItems}
|
|
placeholder="Pick workspaces"
|
|
reorderable={false}
|
|
/>
|
|
{/if}
|
|
{#if mcpAllWorkspaces || mcpWorkspaces.length > 1}
|
|
<p class="text-xs text-tertiary">
|
|
Tools take a <code>workspace_id</code> argument naming the workspace they act in.
|
|
</p>
|
|
{/if}
|
|
{/if}
|
|
{#if $superadmin && !mcpSuperAdmin && (mcpAccess === 'selected' || !mcpAllWorkspaces)}
|
|
<p class="text-xs text-tertiary">
|
|
Showing workspaces you are a member of. Superadmin rights, under Access, opens the rest.
|
|
</p>
|
|
{/if}
|
|
</div>
|
|
{/snippet}
|
|
|
|
<div>
|
|
<!-- Stays bounded by the panel width: a content-driven width (min-w-min) would let a long
|
|
scope chip stretch this card and push the rest of the form out of view. -->
|
|
<div class="p-4 rounded-md bg-surface-tertiary {!mcpOnly || newMcpToken ? 'mb-6' : ''}">
|
|
{#if !mcpOnly}
|
|
<h3 class="pb-2 font-semibold text-emphasis text-sm">{title}</h3>
|
|
{/if}
|
|
|
|
{#if showMcpMode && !mcpOnly}
|
|
<div
|
|
class="mb-4 flex flex-row flex-shrink-0"
|
|
use:triggerableByAI={{
|
|
id: 'account-settings-create-mcp-token',
|
|
description: 'Create a new MCP token to authenticate to the Windmill API'
|
|
}}
|
|
>
|
|
<Toggle
|
|
on:change={(e) => {
|
|
if (e.detail) {
|
|
enterMcpMode()
|
|
} else {
|
|
exitMcpMode()
|
|
}
|
|
}}
|
|
checked={mcpCreationMode}
|
|
options={{
|
|
right: 'Generate MCP URL',
|
|
rightTooltip:
|
|
'Generate a new MCP URL to make your scripts, flows, and API endpoints available as tools through your LLM clients.',
|
|
rightDocumentationLink: 'https://www.windmill.dev/docs/core_concepts/mcp'
|
|
}}
|
|
size="xs"
|
|
/>
|
|
</div>
|
|
{/if}
|
|
|
|
{#if mcpCreationMode && mcpUrlPolicy === 'loading'}
|
|
<Skeleton layout={[[2], 0.5, [1]]} />
|
|
{: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"
|
|
>{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.
|
|
{#if mcpAsTools}
|
|
It opens a Windmill page where you sign in, and gives the client the scripts and flows
|
|
your role offers in this workspace as tools.
|
|
{:else}
|
|
It opens a Windmill page where you sign in and choose the workspaces. You can limit
|
|
what the client may do there.
|
|
{/if}
|
|
</p>
|
|
</div>
|
|
{#if workspaceUrlOffered && homeWorkspace}
|
|
<div class="flex flex-col gap-1">
|
|
<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.
|
|
</p>
|
|
</div>
|
|
{/if}
|
|
|
|
{#if mcpUrlPolicy === 'token'}
|
|
<Section label="Use a token instead of signing in" small collapsable collapsed>
|
|
{@render mcpTokenForm()}
|
|
</Section>
|
|
{/if}
|
|
|
|
{#if !mcpOnly}
|
|
<div class="flex justify-end">
|
|
<Button onClick={exitMcpMode} variant="default">Cancel</Button>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
{:else}
|
|
{#if scopes != undefined}
|
|
<div class="mb-4">
|
|
<span class="block mb-1 text-emphasis text-xs font-semibold">Scope</span>
|
|
{#each scopes as scope (scope)}
|
|
<TextInput inputProps={{ disabled: true }} value={scope} class="mb-2 w-full" />
|
|
{/each}
|
|
<div class="text-tertiary">
|
|
<Toggle
|
|
bind:checked={readOnly}
|
|
options={{
|
|
right: 'Read-only',
|
|
rightTooltip:
|
|
'Restricts this token to GET/HEAD endpoints. Any mutating request (POST/PUT/PATCH/DELETE) or job-run action will be rejected with 403, regardless of the scopes listed above.'
|
|
}}
|
|
size="2xs"
|
|
/>
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
{#if !mcpOnly}
|
|
<div class="flex flex-col gap-1">
|
|
<span class="text-xs font-semibold text-emphasis">
|
|
Label <span class="font-normal text-secondary">(optional)</span>
|
|
</span>
|
|
<TextInput inputProps={{ type: 'text' }} bind:value={newTokenLabel} class="w-full" />
|
|
</div>
|
|
{/if}
|
|
|
|
<div class="flex flex-col gap-1">
|
|
<span class="text-xs font-semibold text-emphasis">
|
|
Expires in
|
|
{#if maxExpirationSecs == undefined}
|
|
<span class="font-normal text-secondary">(optional)</span>
|
|
{/if}
|
|
</span>
|
|
<Select
|
|
bind:value={() => newTokenExpiration, (v) => (pickedExpiration = v)}
|
|
placeholder={maxExpirationSecs == undefined ? 'No expiration' : 'Pick an expiration'}
|
|
inputClass="w-full"
|
|
items={expirationItems}
|
|
/>
|
|
{#if maxExpirationSecs != undefined}
|
|
<p class="text-2xs text-hint">
|
|
This instance limits tokens to {maxExpirationLabel}.
|
|
</p>
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
|
|
{#if !lockWorkspace}
|
|
<div class="mt-4 flex flex-col gap-1">
|
|
<span class="text-xs font-semibold text-emphasis">Works in</span>
|
|
<div class="flex flex-row flex-wrap items-center gap-2">
|
|
<ToggleButtonGroup bind:selected={newTokenReach} allowEmpty={false}>
|
|
{#snippet children({ item })}
|
|
<ToggleButton {item} value="workspace" label="One workspace" />
|
|
<ToggleButton {item} value="all" label="All workspaces (instance-wide)" />
|
|
{/snippet}
|
|
</ToggleButtonGroup>
|
|
{#if newTokenReach === 'workspace'}
|
|
<div class="min-w-48">
|
|
<Select
|
|
bind:value={newTokenWorkspace}
|
|
placeholder="Pick a workspace"
|
|
inputClass="w-full"
|
|
items={tokenWorkspaceItems}
|
|
/>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
<p class="text-2xs text-hint">
|
|
{#if newTokenReach === 'all'}
|
|
Works in every workspace you are a member of, and on instance-level endpoints. The CLI
|
|
needs this.
|
|
{:else}
|
|
Works only in this workspace. Other workspaces and instance-level endpoints refuse it.
|
|
{/if}
|
|
</p>
|
|
</div>
|
|
{/if}
|
|
|
|
{#if canCarryAdmin || $superadmin}
|
|
<div class="mt-4 flex flex-col gap-2">
|
|
{#if canCarryAdmin}
|
|
{@render adminToggle(carrySuperAdmin)}
|
|
{/if}
|
|
{#if $superadmin}
|
|
<Toggle
|
|
bind:checked={carrySuperAdmin}
|
|
options={{
|
|
right: 'Superadmin rights',
|
|
rightTooltip:
|
|
'The token carries your superadmin rights: admin in every workspace it reaches, including ones you are not a member of. Instance settings also need All workspaces. Off, it acts with your membership in each workspace only.'
|
|
}}
|
|
size="xs"
|
|
/>
|
|
{/if}
|
|
{#if carryAdmin || carrySuperAdmin}
|
|
{@render scopesBoundRights((standardScopes?.length ?? 0) > 0, false)}
|
|
{/if}
|
|
</div>
|
|
{/if}
|
|
|
|
{#if $enterpriseLicense}
|
|
<div class="mt-4 flex flex-col gap-1">
|
|
<span class="text-xs font-semibold text-emphasis">
|
|
Allowed IPs <span class="font-normal text-secondary">(optional)</span>
|
|
</span>
|
|
<TextInput
|
|
inputProps={{ type: 'text', placeholder: '203.0.113.4, 10.0.0.0/8' }}
|
|
bind:value={allowedIpsText}
|
|
class="w-full"
|
|
/>
|
|
<p class="text-2xs text-hint">
|
|
IP addresses or CIDR ranges, separated by commas. Requests from any other address are
|
|
refused. Leave empty to allow any.
|
|
</p>
|
|
{#if privateRangesTrusted && allowedIps.length > 0}
|
|
<Alert type="warning" size="xs" title="Insiders can claim an allowed address">
|
|
This instance trusts a whole private range as proxies, so a host on its private
|
|
network, a job included, can name its own client address. The allowlist holds against
|
|
callers outside that network only. An instance admin can list the reverse proxies on
|
|
the Client IP instance settings page.
|
|
</Alert>
|
|
{/if}
|
|
{#if clientIp}
|
|
<div class="flex items-center gap-2 text-2xs text-secondary">
|
|
<span>Windmill sees this browser's IP as <code>{clientIp}</code></span>
|
|
{#if !allowedIps.includes(clientIp)}
|
|
<Button variant="subtle" unifiedSize="2xs" onclick={addClientIp}>Add</Button>
|
|
{/if}
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
{:else}
|
|
<p class="mt-4 text-2xs text-hint">
|
|
Restricting a token to IP ranges requires Enterprise Edition.
|
|
</p>
|
|
{/if}
|
|
|
|
{#if !scopes || scopes.length === 0}
|
|
<div class="mt-4">
|
|
<ScopesPicker workspaceId={scopeWorkspaceId} bind:value={pickedScopes} bind:readOnly />
|
|
</div>
|
|
{/if}
|
|
|
|
{#if canCarryAdmin && !carryAdmin && !carrySuperAdmin}
|
|
<div class="mt-4">
|
|
<AdminRelianceNotice
|
|
workspaceIds={tokenWorkspaceId ? [tokenWorkspaceId] : undefined}
|
|
scopes={standardScopes}
|
|
{readOnly}
|
|
/>
|
|
</div>
|
|
{/if}
|
|
|
|
<div class="mt-4 flex justify-end gap-2 flex-row">
|
|
{#if !mcpOnly}
|
|
<Button
|
|
on:click={() => {
|
|
exitMcpMode()
|
|
}}
|
|
variant="default"
|
|
>
|
|
Cancel
|
|
</Button>
|
|
{/if}
|
|
<Button
|
|
on:click={() => createToken()}
|
|
disabled={!lockWorkspace && newTokenReach === 'workspace' && !newTokenWorkspace}
|
|
variant="accent">New token</Button
|
|
>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
|
|
{#if newToken && displayCreateToken}
|
|
<TokenDisplay token={newToken} />
|
|
<div class="-mt-4 mb-6">
|
|
<CollapseLink text="Check what this token can do" bind:open={newTokenTestOpen}>
|
|
{#key newToken}
|
|
<TokenInspector token={newToken} workspace={newTokenTestWorkspace} />
|
|
{/key}
|
|
</CollapseLink>
|
|
</div>
|
|
{/if}
|
|
|
|
{#if newMcpToken && displayCreateToken}
|
|
<TokenDisplay
|
|
token={newMcpToken}
|
|
mcpUrl={newMcpTokenUrl}
|
|
workspaceMcpUrl={newMcpWorkspaceTokenUrl || undefined}
|
|
workspace={homeWorkspace}
|
|
/>
|
|
{/if}
|
|
</div>
|