Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(control-ui): manage connector context membership and sharing in-place

Miguelon Peluchon2b6b1cddb703
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index 5424dd53d..a42596066 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -2028,6 +2028,26 @@ textarea.cu-input {
gap: var(--cu-space-1);
}
+.cu-context-connector-bindings {
+ display: grid;
+ gap: var(--cu-space-2);
+}
+
+.cu-context-connector-bindings__tag {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--cu-space-1);
+}
+
+.cu-context-connector-bindings__tag .cu-btn--icon {
+ width: 1.25rem;
+ height: 1.25rem;
+}
+
+.cu-context-connector-bindings__hint {
+ margin: 0;
+}
+
.cu-connector-badge {
display: inline-block;
padding: 0.12rem 0.45rem;
diff --git a/control-ui/app/mcp-servers/page.tsx b/control-ui/app/mcp-servers/page.tsx
index 3ee79be3a..609eca96e 100644
--- a/control-ui/app/mcp-servers/page.tsx
+++ b/control-ui/app/mcp-servers/page.tsx
@@ -1,6 +1,6 @@
'use client'
-import React, { useEffect, useState } from 'react'
+import React, { useEffect, useMemo, useState } from 'react'
import { useRouter } from 'next/navigation'
import { LoadingScreen } from '@components/LoadingScreen'
import { CONTROL_ROUTES } from '@constants/routes'
@@ -12,17 +12,20 @@ import type {
ConnectorAccessPrincipal,
ConnectorAccessSummary,
ConnectorAccessSummaryMap,
+ ConnectorContextShareTargets,
} from '../../components/McpServerTable.types'
import { useToast } from '../../components/Toast'
import {
apiSend,
getContextTeams,
getContextUsers,
+ getContexts,
getHosts,
getMcpServers,
isSilentApiError,
+ updateContext,
} from '../../lib/api'
-import type { HostResource, McpServerResource } from '../../lib/api'
+import type { ContextResource, ContextSpec, HostResource, McpServerResource } from '../../lib/api'
import { buildControlUiLoginPath, getCurrentControlUiPath } from '../../lib/authRedirect'
function resourceName(resource: { metadata?: { name?: string } }): string {
@@ -46,6 +49,19 @@ function sortPrincipals(items: ConnectorAccessPrincipal[]): ConnectorAccessPrinc
return [...items].sort((a, b) => a.label.localeCompare(b.label))
}
+function mergeAccessSummaries(summaries: ConnectorAccessSummary[]): ConnectorAccessSummary {
+ const mergeGroup = (group: keyof ConnectorAccessSummary) => {
+ const items = summaries.flatMap(summary => summary[group])
+ return sortPrincipals(Array.from(new Map(items.map(item => [item.id, item] as const)).values()))
+ }
+
+ return {
+ agents: mergeGroup('agents'),
+ users: mergeGroup('users'),
+ teams: mergeGroup('teams'),
+ }
+}
+
function agentsForContext(hosts: HostResource[], contextRef: string): ConnectorAccessPrincipal[] {
return sortPrincipals(
hosts
@@ -108,9 +124,17 @@ export default function McpServersPage() {
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [mcpServers, setMcpServers] = useState<McpServerResource[]>([])
+ const [contexts, setContexts] = useState<ContextResource[]>([])
+ const [hosts, setHosts] = useState<HostResource[]>([])
const [accessByConnectorKey, setAccessByConnectorKey] = useState<ConnectorAccessSummaryMap>({})
+ const [accessByContextName, setAccessByContextName] = useState<
+ Record<string, ConnectorAccessSummary>
+ >({})
const [accessWarning, setAccessWarning] = useState('')
const [deletingKey, setDeletingKey] = useState<string | null>(null)
+ const [updatingContextMembershipKey, setUpdatingContextMembershipKey] = useState<string | null>(
+ null
+ )
const { confirm, confirmDialog } = useConfirmDialog()
async function loadAll() {
@@ -118,11 +142,21 @@ export default function McpServersPage() {
setError('')
setAccessWarning('')
try {
- const [serversResult, hostsResult] = await Promise.all([getMcpServers(), getHosts()])
+ const [serversResult, hostsResult, contextsResult] = await Promise.all([
+ getMcpServers(),
+ getHosts(),
+ getContexts(),
+ ])
const connectors = (serversResult.items || []) as McpServerResource[]
const hosts = (hostsResult.items || []) as HostResource[]
+ const nextContexts = (contextsResult.items || []) as ContextResource[]
const contextRefs = [
- ...new Set(connectors.map(connector => getContextRef(connector)).filter(Boolean)),
+ ...new Set([
+ ...connectors.map(connector => getContextRef(connector)).filter(Boolean),
+ ...nextContexts
+ .map(context => String(context.metadata?.name || context.spec?.contextId || '').trim())
+ .filter(Boolean),
+ ]),
]
const accessResults = await Promise.all(
contextRefs.map(
@@ -132,6 +166,7 @@ export default function McpServersPage() {
const accessByContext = new Map(
accessResults.map(([contextRef, [summary]]) => [contextRef, summary] as const)
)
+ const nextAccessByContextName = Object.fromEntries(accessByContext)
const accessLoadFailed = accessResults.some(([, [, failed]]) => failed)
if (accessLoadFailed) {
setAccessWarning(
@@ -140,20 +175,34 @@ export default function McpServersPage() {
}
const nextAccessByConnectorKey = connectors.reduce<ConnectorAccessSummaryMap>(
(acc, connector) => {
- const contextRef = getContextRef(connector)
- if (contextRef) {
- acc[connectorKey(connector)] = accessByContext.get(contextRef) ?? {
- agents: [],
- users: [],
- teams: [],
- }
+ const connectorName = resourceName(connector)
+ const connectorContexts = new Set(
+ [
+ getContextRef(connector),
+ ...nextContexts
+ .filter(context => context.spec?.mcpServers?.includes(connectorName))
+ .map(context =>
+ String(context.metadata?.name || context.spec?.contextId || '').trim()
+ ),
+ ].filter(Boolean)
+ )
+ if (connectorContexts.size > 0) {
+ acc[connectorKey(connector)] = mergeAccessSummaries(
+ [...connectorContexts].map(
+ contextRef =>
+ accessByContext.get(contextRef) ?? { agents: [], users: [], teams: [] }
+ )
+ )
}
return acc
},
{}
)
setMcpServers(connectors)
+ setContexts(nextContexts)
+ setHosts(hosts)
setAccessByConnectorKey(nextAccessByConnectorKey)
+ setAccessByContextName(nextAccessByContextName)
} catch (e) {
if (isSilentApiError(e)) return
setError(e instanceof Error ? e.message : 'Failed to load connectors')
@@ -191,6 +240,139 @@ export default function McpServersPage() {
router.push(CONTROL_ROUTES.contexts.connectors(trimmed))
}
+ function contextName(context: ContextResource): string {
+ return String(context.metadata?.name || context.spec?.contextId || '').trim()
+ }
+
+ function contextSpec(context: ContextResource): ContextSpec {
+ const name = contextName(context)
+ return {
+ contextId: context.spec?.contextId || name,
+ description: context.spec?.description,
+ mcpServers: Array.isArray(context.spec?.mcpServers) ? context.spec.mcpServers : [],
+ sharedFileSystems: context.spec?.sharedFileSystems ?? [],
+ }
+ }
+
+ const shareTargets = useMemo<ConnectorContextShareTargets>(() => {
+ const agentCountByContext = new Map<string, number>()
+ for (const host of hosts) {
+ const contextName = getContextRef(host)
+ if (contextName) {
+ agentCountByContext.set(contextName, (agentCountByContext.get(contextName) ?? 0) + 1)
+ }
+ }
+ const affectedAgentCount = (contextName: string) => agentCountByContext.get(contextName) ?? 0
+
+ return {
+ agents: hosts
+ .map(host => {
+ const name = resourceName(host)
+ const contextName = getContextRef(host)
+ return contextName
+ ? {
+ id: name,
+ label: name,
+ contextName,
+ affectedAgentCount: affectedAgentCount(contextName),
+ }
+ : null
+ })
+ .filter(
+ (target): target is ConnectorContextShareTargets['agents'][number] => target !== null
+ )
+ .sort((a, b) => a.label.localeCompare(b.label)),
+ teams: Object.entries(accessByContextName).flatMap(([contextName, access]) =>
+ access.teams.map(team => ({
+ id: `${team.id}:${contextName}`,
+ label: team.label,
+ contextName,
+ affectedAgentCount: affectedAgentCount(contextName),
+ }))
+ ),
+ members: Object.entries(accessByContextName).flatMap(([contextName, access]) =>
+ access.users.map(user => ({
+ id: `${user.id}:${contextName}`,
+ label: user.label,
+ contextName,
+ affectedAgentCount: affectedAgentCount(contextName),
+ }))
+ ),
+ }
+ }, [accessByContextName, hosts])
+
+ async function addConnectorToContexts(
+ server: { name: string; namespace: string },
+ contextNames: string[]
+ ) {
+ const key = `${server.namespace}/${server.name}`
+ const targets = contexts.filter(context => contextNames.includes(contextName(context)))
+ if (targets.length !== contextNames.length) {
+ setError('One or more selected contexts could not be loaded. Please refresh and try again.')
+ return
+ }
+
+ setUpdatingContextMembershipKey(key)
+ setError('')
+ try {
+ await Promise.all(
+ targets.map(context => {
+ const name = contextName(context)
+ const spec = contextSpec(context)
+ return updateContext(name, {
+ spec: {
+ ...spec,
+ mcpServers: Array.from(new Set([...spec.mcpServers, server.name])),
+ },
+ })
+ })
+ )
+ await loadAll()
+ showToast(
+ contextNames.length === 1
+ ? `Connector ${server.name} added to context.`
+ : `Connector ${server.name} added to ${contextNames.length} contexts.`,
+ { tone: 'success' }
+ )
+ } catch (e) {
+ if (isSilentApiError(e)) return
+ setError(e instanceof Error ? e.message : `Failed to add ${server.name} to contexts`)
+ } finally {
+ setUpdatingContextMembershipKey(null)
+ }
+ }
+
+ async function removeConnectorFromContext(
+ server: { name: string; namespace: string },
+ targetContextName: string
+ ) {
+ const key = `${server.namespace}/${server.name}`
+ const target = contexts.find(context => contextName(context) === targetContextName)
+ if (!target) {
+ setError('Context could not be loaded. Please refresh and try again.')
+ return
+ }
+
+ setUpdatingContextMembershipKey(key)
+ setError('')
+ try {
+ const spec = contextSpec(target)
+ await updateContext(targetContextName, {
+ spec: {
+ ...spec,
+ mcpServers: spec.mcpServers.filter(name => name !== server.name),
+ },
+ })
+ await loadAll()
+ showToast(`Connector ${server.name} removed from ${targetContextName}.`, { tone: 'success' })
+ } catch (e) {
+ if (isSilentApiError(e)) return
+ setError(e instanceof Error ? e.message : `Failed to remove ${server.name} from context`)
+ } finally {
+ setUpdatingContextMembershipKey(null)
+ }
+ }
+
useEffect(() => {
if (authState.isLoggedIn && !authState.isLoading) {
void loadAll()
@@ -222,7 +404,18 @@ export default function McpServersPage() {
<McpServerTable
items={mcpServers as any}
accessByConnectorKey={accessByConnectorKey}
+ contexts={contexts
+ .map(context => ({
+ name: contextName(context),
+ description: context.spec?.description,
+ mcpServers: context.spec?.mcpServers ?? [],
+ }))
+ .filter(context => context.name)}
+ shareTargets={shareTargets}
onOpenContext={handleOpenContext}
+ onAddToContexts={addConnectorToContexts}
+ onRemoveFromContext={removeConnectorFromContext}
+ updatingContextMembershipKey={updatingContextMembershipKey}
onDelete={handleDelete}
onEdit={server => router.push(CONTROL_ROUTES.connectors.edit(server.name))}
deletingKey={deletingKey}
diff --git a/control-ui/components/McpServerTable.tsx b/control-ui/components/McpServerTable.tsx
index 658f2553f..63a5c7a95 100644
--- a/control-ui/components/McpServerTable.tsx
+++ b/control-ui/components/McpServerTable.tsx
@@ -3,10 +3,14 @@
import React, { Fragment, useMemo, useState } from 'react'
import type {
ConnectorAccessSummary,
+ ConnectorContextBinding,
+ ConnectorContextShareTarget,
+ ConnectorContextShareTargets,
McpServerStatus,
McpServerTableProps,
} from './McpServerTable.types'
import { SectionSearchInput } from './SectionSearchInput'
+import { SelectionDropdown } from './SelectionDropdown'
import { IconCable } from './Sidebar/icons'
import { SkeletonTableRows } from './SkeletonTableRows'
import { TableHeaderRow } from './TableHeaderRow'
@@ -108,7 +112,12 @@ function AccessSummary({ summary }: { summary?: ConnectorAccessSummary }) {
export function McpServerTable({
items,
accessByConnectorKey,
+ contexts = [],
+ shareTargets,
onOpenContext,
+ onAddToContexts,
+ onRemoveFromContext,
+ updatingContextMembershipKey,
onDelete,
onEdit,
deletingKey,
@@ -121,6 +130,13 @@ export function McpServerTable({
}: McpServerTableProps) {
const [searchQuery, setSearchQuery] = useState('')
const [expandedKeys, setExpandedKeys] = useState<Set<string>>(new Set())
+ const [serverKeyAddingContexts, setServerKeyAddingContexts] = useState<string | null>(null)
+ const [selectedContextNamesToAdd, setSelectedContextNamesToAdd] = useState<string[]>([])
+ const [sharePicker, setSharePicker] = useState<{
+ key: string
+ kind: 'agents' | 'teams' | 'members'
+ } | null>(null)
+ const [selectedShareTargetIds, setSelectedShareTargetIds] = useState<string[]>([])
const rows = useMemo(
() =>
items.map(item => {
@@ -180,6 +196,38 @@ export function McpServerTable({
})
}
+ function contextsForConnector(name: string): ConnectorContextBinding[] {
+ return contexts.filter(context => context.mcpServers.includes(name))
+ }
+
+ function openAddContexts(key: string) {
+ setSelectedContextNamesToAdd([])
+ setServerKeyAddingContexts(key)
+ }
+
+ function closeAddContexts() {
+ if (updatingContextMembershipKey) return
+ setSelectedContextNamesToAdd([])
+ setServerKeyAddingContexts(null)
+ }
+
+ function openSharePicker(key: string, kind: 'agents' | 'teams' | 'members') {
+ setSelectedShareTargetIds([])
+ setSharePicker({ key, kind })
+ }
+
+ function closeSharePicker() {
+ if (updatingContextMembershipKey) return
+ setSelectedShareTargetIds([])
+ setSharePicker(null)
+ }
+
+ function shareTargetDescription(target: ConnectorContextShareTarget): string {
+ const agentLabel =
+ target.affectedAgentCount === 1 ? '1 agent' : `${target.affectedAgentCount} agents`
+ return `Context: ${target.contextName} · ${agentLabel} affected`
+ }
+
const isInitialLoad = loading && items.length === 0
return (
@@ -267,6 +315,9 @@ export function McpServerTable({
const spec = item.spec || {}
const expanded = expandedKeys.has(key)
const contextRef = spec.contextRef || ''
+ const assignedContexts = contextsForConnector(name)
+ const assignedContextNames = new Set(assignedContexts.map(context => context.name))
+ const contextMembershipBusy = updatingContextMembershipKey === key
return (
<Fragment key={key}>
<tr
@@ -355,7 +406,7 @@ export function McpServerTable({
<TransportBadge type={spec.transport?.type} />
</div>
<div className="cu-expandable-field">
- <span className="cu-expandable-field__label">Context</span>
+ <span className="cu-expandable-field__label">Default context</span>
{contextRef && onOpenContext ? (
<button
type="button"
@@ -368,6 +419,117 @@ export function McpServerTable({
<span className="cu-muted">{contextRef || '—'}</span>
)}
</div>
+ {onAddToContexts && onRemoveFromContext ? (
+ <div className="cu-expandable-field cu-expandable-field--wide">
+ <span className="cu-expandable-field__label">
+ Available in contexts
+ </span>
+ <div className="cu-context-connector-bindings">
+ {assignedContexts.length === 0 ? (
+ <span className="cu-muted">No contexts assigned</span>
+ ) : (
+ <div className="cu-expandable-tags">
+ {assignedContexts.map(context => (
+ <span
+ className="cu-registry-tag cu-context-connector-bindings__tag"
+ key={context.name}
+ >
+ {onOpenContext ? (
+ <button
+ type="button"
+ className="cu-link"
+ onClick={() => onOpenContext(context.name)}
+ >
+ {context.name}
+ </button>
+ ) : (
+ context.name
+ )}
+ <button
+ type="button"
+ className="cu-btn cu-btn--icon cu-btn--danger-icon"
+ disabled={contextMembershipBusy}
+ aria-label={`Remove connector ${name} from context ${context.name}`}
+ title={`Remove from ${context.name}`}
+ onClick={() =>
+ void onRemoveFromContext(
+ { namespace, name },
+ context.name
+ )
+ }
+ >
+ <IconX width={14} height={14} />
+ </button>
+ </span>
+ ))}
+ </div>
+ )}
+ <button
+ type="button"
+ className="cu-btn cu-btn--secondary cu-btn--sm"
+ disabled={contextMembershipBusy}
+ onClick={() => openAddContexts(key)}
+ >
+ Add contexts
+ </button>
+ </div>
+ </div>
+ ) : null}
+ {onAddToContexts && shareTargets ? (
+ <div className="cu-expandable-field cu-expandable-field--wide">
+ <span className="cu-expandable-field__label">
+ Share connector
+ </span>
+ <div className="cu-context-connector-bindings">
+ <p className="cu-muted cu-context-connector-bindings__hint">
+ Select an agent, team, or member. The connector is added to
+ the Context they use; other agents in that Context also gain
+ access.
+ </p>
+ <div className="cu-table-actions">
+ <button
+ type="button"
+ className="cu-btn cu-btn--secondary cu-btn--sm"
+ disabled={
+ contextMembershipBusy ||
+ !shareTargets.agents.some(
+ target => !assignedContextNames.has(target.contextName)
+ )
+ }
+ onClick={() => openSharePicker(key, 'agents')}
+ >
+ Add agents
+ </button>
+ <button
+ type="button"
+ className="cu-btn cu-btn--secondary cu-btn--sm"
+ disabled={
+ contextMembershipBusy ||
+ !shareTargets.teams.some(
+ target => !assignedContextNames.has(target.contextName)
+ )
+ }
+ onClick={() => openSharePicker(key, 'teams')}
+ >
+ Add teams
+ </button>
+ <button
+ type="button"
+ className="cu-btn cu-btn--secondary cu-btn--sm"
+ disabled={
+ contextMembershipBusy ||
+ !shareTargets.members.some(
+ target => !assignedContextNames.has(target.contextName)
+ )
+ }
+ onClick={() => openSharePicker(key, 'members')}
+ >
+ Add members
+ </button>
+ </div>
+ </div>
+ </div>
+ ) : null}
<div className="cu-expandable-field cu-expandable-field--wide">
<span className="cu-expandable-field__label">Access</span>
<AccessSummary summary={accessByConnectorKey?.[key]} />
@@ -403,6 +565,248 @@ export function McpServerTable({
</table>
</div>
)}
+ {serverKeyAddingContexts
+ ? (() => {
+ const row = rows.find(candidate => candidate.key === serverKeyAddingContexts)
+ if (!row || !onAddToContexts) return null
+ const assignedNames = new Set(
+ contextsForConnector(row.name).map(context => context.name)
+ )
+ const contextOptions = contexts
+ .filter(context => !assignedNames.has(context.name))
+ .map(context => ({
+ value: context.name,
+ label: context.name,
+ description: context.description || undefined,
+ }))
+ const busy = updatingContextMembershipKey === row.key
+ return (
+ <div
+ style={{
+ position: 'fixed',
+ inset: 0,
+ background: 'rgba(0, 0, 0, 0.6)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ zIndex: 1000,
+ padding: '1rem',
+ }}
+ role="presentation"
+ onClick={event => {
+ if (event.target === event.currentTarget && !busy) closeAddContexts()
+ }}
+ >
+ <div
+ className="cu-modal-panel cu-modal-panel--selection"
+ role="dialog"
+ aria-labelledby="add-connector-context-title"
+ onClick={event => event.stopPropagation()}
+ >
+ <div className="cu-modal-panel__head">
+ <strong
+ id="add-connector-context-title"
+ style={{ fontSize: '1rem', lineHeight: 1.35 }}
+ >
+ Add connector to contexts
+ </strong>
+ <button
+ type="button"
+ className="cu-btn cu-btn--icon cu-btn--ghost"
+ onClick={closeAddContexts}
+ disabled={busy}
+ aria-label="Close"
+ >
+ <IconX width={18} height={18} />
+ </button>
+ </div>
+
+ <div className="cu-field">
+ <label htmlFor="connector-context-picker">Contexts</label>
+ <SelectionDropdown
+ id="connector-context-picker"
+ inline
+ value={selectedContextNamesToAdd}
+ onChange={setSelectedContextNamesToAdd}
+ options={contextOptions}
+ placeholder="Select contexts"
+ searchPlaceholder="Search contexts..."
+ selectionLabel="Selected contexts"
+ emptyLabel="No available contexts."
+ disabled={busy}
+ />
+ </div>
+
+ <div className="cu-modal-panel__foot">
+ <button
+ type="button"
+ className="cu-btn cu-btn--ghost cu-btn--sm"
+ onClick={closeAddContexts}
+ disabled={busy}
+ >
+ Cancel
+ </button>
+ <button
+ type="button"
+ className="cu-btn cu-btn--primary"
+ onClick={async () => {
+ if (selectedContextNamesToAdd.length === 0) return
+ await onAddToContexts(
+ { namespace: row.namespace, name: row.name },
+ selectedContextNamesToAdd
+ )
+ setSelectedContextNamesToAdd([])
+ setServerKeyAddingContexts(null)
+ }}
+ disabled={busy || selectedContextNamesToAdd.length === 0}
+ >
+ {selectedContextNamesToAdd.length > 1 ? 'Add to contexts' : 'Add to context'}
+ </button>
+ </div>
+ </div>
+ </div>
+ )
+ })()
+ : null}
+ {sharePicker
+ ? (() => {
+ const row = rows.find(candidate => candidate.key === sharePicker.key)
+ if (!row || !onAddToContexts || !shareTargets) return null
+ const assignedNames = new Set(
+ contextsForConnector(row.name).map(context => context.name)
+ )
+ const targets = shareTargets[sharePicker.kind].filter(
+ target => !assignedNames.has(target.contextName)
+ )
+ const targetById = new Map(targets.map(target => [target.id, target] as const))
+ const contextNames = Array.from(
+ new Set(
+ selectedShareTargetIds
+ .map(targetId => targetById.get(targetId)?.contextName)
+ .filter((contextName): contextName is string => Boolean(contextName))
+ )
+ )
+ const affectedAgents = contextNames.reduce(
+ (count, contextName) =>
+ count +
+ (targets.find(target => target.contextName === contextName)?.affectedAgentCount ??
+ 0),
+ 0
+ )
+ const busy = updatingContextMembershipKey === row.key
+ const labels = {
+ agents: { singular: 'agent', plural: 'agents', title: 'Add connector to agents' },
+ teams: { singular: 'team', plural: 'teams', title: 'Add connector through teams' },
+ members: {
+ singular: 'member',
+ plural: 'members',
+ title: 'Add connector through members',
+ },
+ }[sharePicker.kind]
+ return (
+ <div
+ style={{
+ position: 'fixed',
+ inset: 0,
+ background: 'rgba(0, 0, 0, 0.6)',
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ zIndex: 1000,
+ padding: '1rem',
+ }}
+ role="presentation"
+ onClick={event => {
+ if (event.target === event.currentTarget && !busy) closeSharePicker()
+ }}
+ >
+ <div
+ className="cu-modal-panel cu-modal-panel--selection"
+ role="dialog"
+ aria-labelledby="add-connector-share-title"
+ onClick={event => event.stopPropagation()}
+ >
+ <div className="cu-modal-panel__head">
+ <strong
+ id="add-connector-share-title"
+ style={{ fontSize: '1rem', lineHeight: 1.35 }}
+ >
+ {labels.title}
+ </strong>
+ <button
+ type="button"
+ className="cu-btn cu-btn--icon cu-btn--ghost"
+ onClick={closeSharePicker}
+ disabled={busy}
+ aria-label="Close"
+ >
+ <IconX width={18} height={18} />
+ </button>
+ </div>
+
+ <div className="cu-field">
+ <label htmlFor="connector-share-picker">
+ {labels.plural.charAt(0).toUpperCase() + labels.plural.slice(1)}
+ </label>
+ <SelectionDropdown
+ id="connector-share-picker"
+ inline
+ value={selectedShareTargetIds}
+ onChange={setSelectedShareTargetIds}
+ options={targets.map(target => ({
+ value: target.id,
+ label: target.label,
+ description: shareTargetDescription(target),
+ }))}
+ placeholder={`Select ${labels.plural}`}
+ searchPlaceholder={`Search ${labels.plural}...`}
+ selectionLabel={`Selected ${labels.plural}`}
+ emptyLabel={`No ${labels.plural} with an available Context.`}
+ disabled={busy}
+ />
+ </div>
+
+ {contextNames.length > 0 ? (
+ <p className="cu-form-section__description">
+ This adds the connector to{' '}
+ {contextNames.length === 1 ? 'Context' : 'Contexts'}{' '}
+ <strong>{contextNames.join(', ')}</strong>. Approximately {affectedAgents}{' '}
+ agent
+ {affectedAgents === 1 ? '' : 's'} will gain access through those Contexts.
+ </p>
+ ) : null}
+
+ <div className="cu-modal-panel__foot">
+ <button
+ type="button"
+ className="cu-btn cu-btn--ghost cu-btn--sm"
+ onClick={closeSharePicker}
+ disabled={busy}
+ >
+ Cancel
+ </button>
+ <button
+ type="button"
+ className="cu-btn cu-btn--primary"
+ onClick={async () => {
+ if (contextNames.length === 0) return
+ await onAddToContexts(
+ { namespace: row.namespace, name: row.name },
+ contextNames
+ )
+ setSelectedShareTargetIds([])
+ setSharePicker(null)
+ }}
+ disabled={busy || contextNames.length === 0}
+ >
+ Grant access to {contextNames.length === 1 ? labels.singular : labels.plural}
+ </button>
+ </div>
+ </div>
+ </div>
+ )
+ })()
+ : null}
</div>
)
}
diff --git a/control-ui/components/McpServerTable.types.ts b/control-ui/components/McpServerTable.types.ts
index dae4ac99e..4ff18797d 100644
--- a/control-ui/components/McpServerTable.types.ts
+++ b/control-ui/components/McpServerTable.types.ts
@@ -50,10 +50,34 @@ export type McpServerItem = {
export type ServerRef = { name: string; namespace: string }
+export type ConnectorContextBinding = {
+ name: string
+ description?: string
+ mcpServers: string[]
+}
+
+export type ConnectorContextShareTarget = {
+ id: string
+ label: string
+ contextName: string
+ affectedAgentCount: number
+}
+
+export type ConnectorContextShareTargets = {
+ agents: ConnectorContextShareTarget[]
+ teams: ConnectorContextShareTarget[]
+ members: ConnectorContextShareTarget[]
+}
+
export type McpServerTableProps = {
items: McpServerItem[]
accessByConnectorKey?: Record<string, ConnectorAccessSummary>
+ contexts?: ConnectorContextBinding[]
+ shareTargets?: ConnectorContextShareTargets
onOpenContext?: (contextName: string) => void
+ onAddToContexts?: (server: ServerRef, contextNames: string[]) => Promise<void>
+ onRemoveFromContext?: (server: ServerRef, contextName: string) => Promise<void>
+ updatingContextMembershipKey?: string | null
onDelete?: (server: ServerRef) => Promise<void>
onEdit?: (server: ServerRef) => void
deletingKey?: string | null
diff --git a/control-ui/components/__tests__/McpServerTable.test.tsx b/control-ui/components/__tests__/McpServerTable.test.tsx
index 39ee9c2be..ba34d2b43 100644
--- a/control-ui/components/__tests__/McpServerTable.test.tsx
+++ b/control-ui/components/__tests__/McpServerTable.test.tsx
@@ -1,4 +1,4 @@
-import { afterEach, describe, expect, it } from 'vitest'
+import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { McpServerTable } from '../McpServerTable'
@@ -237,3 +237,101 @@ describe('McpServerTable — connector access summaries', () => {
expect(screen.queryByText('search-server')).not.toBeInTheDocument()
})
})
+
+describe('McpServerTable — context membership', () => {
+ it('shows attached contexts and lets an operator remove the connector from one', async () => {
+ const onRemoveFromContext = vi.fn().mockResolvedValue(undefined)
+ const items = [makeItem({ name: 'airtable-server' })]
+ render(
+ <McpServerTable
+ items={items}
+ contexts={[
+ { name: 'research', description: 'Research tools', mcpServers: ['airtable-server'] },
+ { name: 'sales', mcpServers: [] },
+ ]}
+ onAddToContexts={vi.fn().mockResolvedValue(undefined)}
+ onRemoveFromContext={onRemoveFromContext}
+ />
+ )
+
+ fireEvent.click(screen.getByRole('button', { name: 'Expand connector airtable-server' }))
+
+ expect(screen.getByText('Available in contexts')).toBeInTheDocument()
+ expect(screen.getByText('research')).toBeInTheDocument()
+ fireEvent.click(
+ screen.getByRole('button', {
+ name: 'Remove connector airtable-server from context research',
+ })
+ )
+
+ expect(onRemoveFromContext).toHaveBeenCalledWith(
+ { namespace: 'mcp-server', name: 'airtable-server' },
+ 'research'
+ )
+ })
+
+ it('uses the Context detail selection modal to add the connector to more contexts', () => {
+ const items = [makeItem({ name: 'airtable-server' })]
+ render(
+ <McpServerTable
+ items={items}
+ contexts={[
+ { name: 'research', mcpServers: ['airtable-server'] },
+ { name: 'sales', description: 'Sales tools', mcpServers: [] },
+ ]}
+ onAddToContexts={vi.fn().mockResolvedValue(undefined)}
+ onRemoveFromContext={vi.fn().mockResolvedValue(undefined)}
+ />
+ )
+
+ fireEvent.click(screen.getByRole('button', { name: 'Expand connector airtable-server' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Add contexts' }))
+
+ expect(screen.getByRole('dialog', { name: 'Add connector to contexts' })).toBeInTheDocument()
+ expect(screen.getByText('Contexts')).toBeInTheDocument()
+ expect(screen.getByText('No available contexts.')).not.toBeInTheDocument()
+ })
+
+ it('offers agent sharing with the agent Context and affected-agent impact visible', () => {
+ const onAddToContexts = vi.fn().mockResolvedValue(undefined)
+ const items = [makeItem({ name: 'airtable-server' })]
+ render(
+ <McpServerTable
+ items={items}
+ contexts={[{ name: 'research', mcpServers: [] }]}
+ shareTargets={{
+ agents: [
+ {
+ id: 'research-agent',
+ label: 'Research Agent',
+ contextName: 'research',
+ affectedAgentCount: 3,
+ },
+ ],
+ teams: [],
+ members: [],
+ }}
+ onAddToContexts={onAddToContexts}
+ onRemoveFromContext={vi.fn().mockResolvedValue(undefined)}
+ />
+ )
+
+ fireEvent.click(screen.getByRole('button', { name: 'Expand connector airtable-server' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Add agents' }))
+
+ expect(screen.getByRole('dialog', { name: 'Add connector to agents' })).toBeInTheDocument()
+ expect(screen.getByRole('option', { name: 'Research Agent' })).toHaveTextContent(
+ 'Context: research · 3 agents affected'
+ )
+
+ fireEvent.click(screen.getByRole('option', { name: 'Research Agent' }))
+ expect(screen.getByText(/This adds the connector to Context research/)).toBeInTheDocument()
+ expect(screen.getByText(/Approximately 3 agents will gain access/)).toBeInTheDocument()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Grant access to agent' }))
+ expect(onAddToContexts).toHaveBeenCalledWith(
+ { namespace: 'mcp-server', name: 'airtable-server' },
+ ['research']
+ )
+ })
+})