fix: list the one toolset a connection gets, trimmed only for a bound workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-12-02 19:09:20 +01:00
co-authored by Claude Opus 5.5
parent 356695bc2f
commit aa1fa8f6d2
3 changed files with 31 additions and 3 deletions
@@ -6,6 +6,7 @@ import {
defaultConnection,
restriction,
servedOn,
connectionToolset,
toolsetLevel
} from './workspaceAccess'
@@ -68,6 +69,15 @@ it('lists the session tools of the lower of the picked access and the workspace
expect(toolsetLevel(ws('a', 'build_and_run'), 'selected')).toBeUndefined()
})
it('lists one toolset per connection, trimmed only for a bound workspace', () => {
expect(connectionToolset('full', undefined)).toBe('full')
expect(connectionToolset('read_run', undefined)).toBe('read_run')
expect(connectionToolset('full', { ...ws('a', 'read_and_run'), limited: true })).toBe('read_run')
expect(connectionToolset('full', ws('a', 'read_only'))).toBe('read')
expect(connectionToolset('full', ws('a', 'run_and_edit'))).toBe('full')
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)
@@ -78,6 +78,21 @@ export function toolsetLevel(
return 'full'
}
/** The tools a connection lists. One covering several workspaces lists the picked level's, and
* a role refuses per call what it does not allow; one bound to a workspace lists what its role's
* MCP limit, or a role that cannot run, leaves. `bound` is that workspace. */
export function connectionToolset(
picked: McpAccess,
bound: McpWorkspaceAccess | undefined
): ToolsetLevel | undefined {
if (picked === 'selected') return undefined
if (!bound) return picked
if (!givesAnything(bound, picked) || bound.access === 'runnables') return undefined
if (bound.access === 'read_only') return 'read'
if (bound.limited && bound.access === 'read_and_run' && picked === 'full') return 'read_run'
return picked
}
/** The MCP URL connecting to this workspace alone. */
export function workspaceMcpUrl(id: string): string {
return `${apiBaseUrl('mcp')}/api/mcp/w/${id}/mcp`
@@ -25,6 +25,7 @@
import {
accessLabel,
defaultConnection,
connectionToolset,
givesAnything,
restriction,
servedOn,
@@ -171,6 +172,7 @@
const coveredIds = $derived(isGateway ? pickedWorkspaces : [workspaceId])
const covered = $derived(workspaceAccess.filter((w) => coversAll || coveredIds.includes(w.id)))
const served = $derived(servedOn(covered, coversAll, access))
const bound = $derived(!coversAll && covered.length === 1 ? covered[0] : undefined)
const unavailable = $derived(
!coversAll && served.length > 0 && served.every((w) => !givesAnything(w, access))
)
@@ -206,7 +208,8 @@
key,
label,
ws,
level,
// One list per connection: the picked level's, or what a bound workspace leaves.
tools: givesAnything(ws[0], access) ? connectionToolset(access, bound) : undefined,
restricted: restriction(ws[0], access),
hint: ws.every((w) => w.limited) ? `${hint} Set by your role.` : hint
}
@@ -624,8 +627,8 @@
{/if}
<Tooltip small>{group.hint}</Tooltip>
{#if !named}{@render pen()}{/if}
{#if group.level}
{@const tools = open ? toolset(group.level) : undefined}
{#if group.tools}
{@const tools = open ? toolset(group.tools) : undefined}
<Button
variant="subtle"
unifiedSize="xs"