Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/mcpproxy/review_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ func runReviewWrite(server, operation string, value interface{}) error {
return err
}
warnApprovalHolds(os.Stderr, server, response)
if operation == "security/approve" || operation == "tools/approve" {
fmt.Fprintf(os.Stderr, "Approval updates policy; it does not confirm upstream connection or tool discovery. Check server.readiness with: mcpproxy review show %s -o json. Retry only after the upstream is connected and tools have been discovered.\n", server)
}
return nil
}

Expand Down Expand Up @@ -634,6 +637,9 @@ func formatReviewResponse(format string, raw []byte, full bool) error {
}
server, _ := value["server"].(map[string]interface{})
fmt.Printf("Server: %v\n", server["name"])
if readiness, ok := server["readiness"].(string); ok {
fmt.Printf("Readiness: %s (approval is separate from connection and discovery)\n", readiness)
}
if line := reviewScanLine(server); line != "" {
fmt.Println(line)
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/mcpproxy/review_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ func TestReviewApproveReportsAppliedCountsAndWarnsOnHolds(t *testing.T) {
require.Contains(t, unknown.String(), "could not be read back")
}

func TestReviewShowTable_SeparatesReadinessFromApproval(t *testing.T) {
for _, tc := range []struct{ readiness string }{{"connecting"}, {"connected"}, {"disabled"}} {
output := captureReviewOutput(t, func() error {
return formatReviewResponse("table", []byte(`{"data":{"server":{"name":"fixture","readiness":"`+tc.readiness+`"},"tools":[]}}`), false)
})
require.Contains(t, output, "Readiness: "+tc.readiness+" (approval is separate from connection and discovery)")
}
}

func TestFormatReviewResponseTableQueueColumns(t *testing.T) {
raw := []byte(`{"data":{"servers":[{"server":"github","kind":"server_review","quarantined":true,"pending":2,"changed":1,"tier_counts":{"write":2},"scan":{"verdict":"warnings"}}]}}`)

Expand Down
50 changes: 48 additions & 2 deletions frontend/src/components/ReviewScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,40 @@ function invalidateForceRetry() { if (lastBlock.value === null) return; lastBloc
// Explicit choices are bound to the reviewed incarnation (Spec 116 FR-017, review round 2): a refresh onto a same-name replacement drops them, so the replacement starts from its own defaults.
// Each load takes a generation; only the newest response may replace the review, so an older refresh that resolves late cannot resurrect an allow the newer definitions invalidated.
let loadGeneration = 0
let readinessTimer: ReturnType<typeof setTimeout> | null = null
let readinessEventTimer: ReturnType<typeof setTimeout> | null = null
let readinessChecks = 0
let readinessRequestGeneration = 0
let active = true
function scheduleReadinessRefresh() {
if (readinessTimer) { clearTimeout(readinessTimer); readinessTimer = null }
if (!active || review.value?.server.readiness !== 'connecting' || readinessChecks >= 15) return
readinessTimer = setTimeout(() => {
readinessTimer = null
readinessChecks++
void refreshReadiness()
}, 2000)
}
async function refreshReadiness() {
if (!review.value || refreshing.value || approving.value) { scheduleReadinessRefresh(); return }
const server = props.serverName
const visit = visitGeneration
const request = ++readinessRequestGeneration
const incarnation = review.value.server.incarnation
let res
try { res = await api.getServerReview(server) }
catch { if (isCurrent(server, visit) && request === readinessRequestGeneration) scheduleReadinessRefresh(); return }
if (!isCurrent(server, visit) || request !== readinessRequestGeneration || !review.value) return
if (!res.success || !res.data) { scheduleReadinessRefresh(); return }
// Poll only the connection hint. Never replace the reviewed tool definitions
// or an operator's pending selection with a background response.
if (res.data.server.incarnation !== incarnation) return
review.value = { ...review.value, server: { ...review.value.server, readiness: res.data.server.readiness, connected: res.data.server.connected } }
scheduleReadinessRefresh()
}
// Each visit (a serverName change) takes a generation too: a response that started in an earlier visit is dropped even when the screen is back on the same server name (A -> B -> A).
let visitGeneration = 0
async function load() { if (typeof api.getServerReview !== 'function') return; const server = props.serverName; const generation = ++loadGeneration; if (!review.value) loading.value = true; refreshing.value = true; invalidateForceRetry(); if (confirmOpen.value) { closeConfirm(); notice.value = STALE_FORCE_NOTICE }; error.value = ''; const res = await api.getServerReview(server); if (server !== props.serverName || generation !== loadGeneration) return; loading.value = false; refreshing.value = false; if (!res.success || !res.data) { error.value = res.error || 'Failed to load review'; return }; if (review.value && review.value.server.incarnation !== res.data.server.incarnation) choices.clear(); review.value = res.data; allowedTools.value = mergeSelection(res.data.tools, choices); invalidateForceRetry(); if (confirmOpen.value && blindReview !== res.data) { closeConfirm(); notice.value = STALE_FORCE_NOTICE }; emit('refreshed') }
async function load() { if (typeof api.getServerReview !== 'function') return; readinessChecks = 0; readinessRequestGeneration++; const server = props.serverName; const generation = ++loadGeneration; if (!review.value) loading.value = true; refreshing.value = true; invalidateForceRetry(); if (confirmOpen.value) { closeConfirm(); notice.value = STALE_FORCE_NOTICE }; error.value = ''; const res = await api.getServerReview(server); if (server !== props.serverName || generation !== loadGeneration) return; loading.value = false; refreshing.value = false; if (!res.success || !res.data) { error.value = res.error || 'Failed to load review'; return }; if (review.value && review.value.server.incarnation !== res.data.server.incarnation) choices.clear(); review.value = res.data; allowedTools.value = mergeSelection(res.data.tools, choices); invalidateForceRetry(); if (confirmOpen.value && blindReview !== res.data) { closeConfirm(); notice.value = STALE_FORCE_NOTICE }; scheduleReadinessRefresh(); emit('refreshed') }
async function rescan() {
const server = props.serverName
const visit = visitGeneration
Expand Down Expand Up @@ -369,6 +400,14 @@ async function reloadAfterStaleReview(server: string, visit: number, message: st
}
async function blockTool(name: string) { const server = props.serverName; const visit = visitGeneration; toolNotice.value = ''; const res = await api.blockTools(server, [name], ...incarnationArgs(review.value?.server.incarnation)); if (!isCurrent(server, visit)) return; await load(); if (!res.success && isCurrent(server, visit)) toolNotice.value = res.error || 'Block failed' }
function refreshAfterReviewChange() { scanning.value = false; rescanning.value = false; void load() }
function refreshAfterServersChange() {
if (readinessEventTimer) clearTimeout(readinessEventTimer)
readinessEventTimer = setTimeout(() => {
readinessEventTimer = null
readinessChecks = 0
void refreshReadiness()
}, 150)
}
async function refreshAfterScanSettled(event: Event) {
const serverName = (event as CustomEvent<{ server_name?: string }>).detail?.server_name
if (serverName && serverName !== props.serverName) return
Expand All @@ -377,14 +416,21 @@ async function refreshAfterScanSettled(event: Event) {
void load()
}
// Component reuse across /review/A -> /review/B: scan state and any pending force retry belong to the old server.
watch(() => props.serverName, () => { visitGeneration++; choices.clear(); review.value = null; allowedTools.value = []; clearFilters(); stateFilter.value = initialStateFilter(props.change); lastBlock.value = null; notice.value = ''; toolNotice.value = ''; approving.value = false; requarantining.value = false; refreshing.value = false; forceDialog.value?.close?.(); closeConfirm(); scanning.value = false; rescanning.value = false; error.value = ''; void load() })
watch(() => props.serverName, () => { visitGeneration++; readinessChecks = 0; if (readinessTimer) clearTimeout(readinessTimer); readinessTimer = null; choices.clear(); review.value = null; allowedTools.value = []; clearFilters(); stateFilter.value = initialStateFilter(props.change); lastBlock.value = null; notice.value = ''; toolNotice.value = ''; approving.value = false; requarantining.value = false; refreshing.value = false; forceDialog.value?.close?.(); closeConfirm(); scanning.value = false; rescanning.value = false; error.value = ''; void load() })
onMounted(() => {
void load()
window.addEventListener('mcpproxy:review-changed', refreshAfterReviewChange)
window.addEventListener('mcpproxy:scan-settled', refreshAfterScanSettled)
window.addEventListener('mcpproxy:servers-changed', refreshAfterServersChange)
})
onUnmounted(() => {
active = false
visitGeneration++ // invalidate a readiness request already in flight
readinessRequestGeneration++
if (readinessTimer) clearTimeout(readinessTimer)
if (readinessEventTimer) clearTimeout(readinessEventTimer)
window.removeEventListener('mcpproxy:review-changed', refreshAfterReviewChange)
window.removeEventListener('mcpproxy:scan-settled', refreshAfterScanSettled)
window.removeEventListener('mcpproxy:servers-changed', refreshAfterServersChange)
})
</script>
11 changes: 6 additions & 5 deletions frontend/src/components/profiles/ProfileCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
{{ tierPhrase(profile.max_tier, profile.tool_counts) || 'No cap' }}
</p>
<dl class="flex flex-wrap gap-x-4 gap-y-1 text-sm" data-test="profile-counts">
<div class="flex gap-1"><dt class="opacity-70">Read</dt><dd>{{ profile.tool_counts.read }}</dd></div>
<div class="flex gap-1"><dt class="opacity-70">Write</dt><dd>{{ profile.tool_counts.write }}</dd></div>
<div class="flex gap-1"><dt class="opacity-70">Destructive</dt><dd>{{ profile.tool_counts.destructive }}</dd></div>
<div class="flex gap-1"><dt class="opacity-70">Read allowed by profile</dt><dd>{{ profile.tool_counts.read }}</dd></div>
<div class="flex gap-1"><dt class="opacity-70">Write allowed by profile</dt><dd>{{ profile.tool_counts.write }}</dd></div>
<div class="flex gap-1"><dt class="opacity-70">Destructive allowed by profile</dt><dd>{{ profile.tool_counts.destructive }}</dd></div>
</dl>
<p v-if="accessCounts?.callable !== undefined" class="text-sm font-medium" data-test="profile-access-counts">{{ accessCounts.callable }} callable now · {{ Math.max(0, accessCounts.visible - accessCounts.callable) }} held · {{ accessCounts.hidden }} hidden</p>
<p v-if="profile.tool_counts.unannotated_hidden > 0" class="text-xs opacity-70" data-test="profile-unannotated">{{ profile.tool_counts.unannotated_hidden }} unannotated hidden</p>

<!-- used_by is administrator-only: absent, never empty, for anyone else. -->
Expand Down Expand Up @@ -65,12 +66,12 @@ import { computed, ref } from 'vue'
import { useClientsStore } from '@/stores/clients'
import { isScopeParamAvailable, useScopeQuery } from '@/composables/useScopeQuery'
import { tierPhrase } from '@/utils/profiles'
import type { ProfileView } from '@/types/api'
import type { EffectiveToolsResult, ProfileView } from '@/types/api'

// Spec 108-i I17 / FR-040: one profile on the Profiles page. The four links go
// through Spec 109's link map (`linkTo`), so the profile travels as the
// `profile` URL filter and the target pages read it the same way everywhere.
const props = defineProps<{ profile: ProfileView; tenant?: boolean }>()
const props = defineProps<{ profile: ProfileView; tenant?: boolean; accessCounts?: EffectiveToolsResult['counts'] }>()
const emit = defineEmits<{ (e: 'assign'): void; (e: 'delete'): void }>()
const scope = useScopeQuery('profiles')
const menuOpen = ref(false)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ export interface ServerReviewResponse {
name: string; transport: string; command?: string; url?: string
/** Launch identity, already redacted by the core (UX-10); never read from the raw server config. */
args?: string[]; working_dir?: string
quarantined: boolean; trust_mode?: string; source_registry_id?: string; source_registry_provenance?: string; scan?: ReviewScan
quarantined: boolean; enabled?: boolean; connected?: boolean; readiness?: 'disabled' | 'quarantined' | 'connecting' | 'connected' | 'disconnected' | 'auth_required' | 'error'; trust_mode?: string; source_registry_id?: string; source_registry_provenance?: string; scan?: ReviewScan
definitions_captured: boolean
/** Spec 116 FR-017: the reviewed server's identity; sent back as expected_incarnation. */
generation?: number; incarnation?: number
Expand Down
22 changes: 14 additions & 8 deletions frontend/src/utils/reviewPresentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { ReviewScan, ReviewTool, ServerReviewResponse } from '@/types'

// Pure presentation rules for the review screen. The strings are the shared
// vocabulary of Spec 109 (fix-review-screen): the macOS app (ReviewPresentation
// in ReviewQueueView.swift) and `mcpproxy review show` use the same sentences.
// Pure presentation rules for the web review screen. The native app maintains
// its own presentation and should be updated separately for wording parity.

export type ScanBannerSeverity = 'error' | 'warning' | 'success' | 'info'
export type ScanBannerAction = 'rescan' | 'scan-now' | 'none'
Expand Down Expand Up @@ -70,20 +69,27 @@ export function reviewHeadline(review: ServerReviewResponse): ReviewHeadline {
}
const tools = review.tools
const pending = tools.filter(needsReview).length
const approvedUnblocked = tools.filter(t => t.approval_status === 'approved' && !t.disabled).length
const blocked = tools.filter(t => t.disabled).length
const readiness = review.server.readiness === 'disabled' ? 'Server disabled.'
: review.server.readiness === 'connecting' ? 'Upstream connecting; retry after discovery.'
: review.server.readiness === 'connected' ? 'Upstream connected; tool discovery may still be in progress.'
: review.server.readiness === 'auth_required' ? 'Upstream authentication required.'
: review.server.readiness === 'error' ? 'Upstream connection error; check the server status.'
: review.server.readiness === 'disconnected' ? 'Upstream disconnected; check the server status.'
: 'Approval does not confirm upstream readiness.'
if (pending > 0) {
return {
state: 'review',
title: `Review ${name}`,
subtitle: `${pending} ${plural(pending, 'tool needs', 'tools need')} review. Agents cannot call ${plural(pending, 'it', 'them')} until approved.`,
subtitle: `${pending} ${plural(pending, 'tool needs', 'tools need')} review · ${approvedUnblocked} approved and unblocked · ${blocked} blocked. ${readiness}`,
}
}
if (tools.length === 0) {
// Approved without seeing tools: still an approved server, just with nothing captured yet.
return { state: 'approved', title: `${name} is approved`, subtitle: 'No tool definitions have been captured yet. New or changed tools come back here for review.' }
return { state: 'approved', title: `${name} is approved`, subtitle: `No tool definitions have been captured yet. ${readiness}` }
}
const blocked = tools.filter(t => t.disabled).length
const summary = `All ${tools.length} ${plural(tools.length, 'tool', 'tools')} approved${blocked > 0 ? ` (${blocked} blocked)` : ''}.`
return { state: 'approved', title: `${name} is approved`, subtitle: `${summary} New or changed tools come back here for review.` }
return { state: 'approved', title: `${name} is approved`, subtitle: `${approvedUnblocked} approved and unblocked · ${blocked} blocked of ${tools.length}. ${readiness}` }
}

export type ToolControl = 'allow-toggle' | 'approve-reject' | 'approved' | 'blocked'
Expand Down
34 changes: 32 additions & 2 deletions frontend/src/views/Profiles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
v-for="profile in store.profiles"
:key="profile.name"
:profile="profile"
:access-counts="accessCounts[profile.name]"
:tenant="tenant"
@assign="assignTo = profile.name"
@delete="deleting = profile"
Expand All @@ -55,7 +56,7 @@
</template>

<script setup lang="ts">
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import ProfileCard from '@/components/profiles/ProfileCard.vue'
import ProfileCreateDialog from '@/components/profiles/ProfileCreateDialog.vue'
Expand All @@ -64,7 +65,8 @@ import AssignClientDialog from '@/components/profiles/AssignClientDialog.vue'
import { useAuthStore } from '@/stores/auth'
import { useProfilesStore } from '@/stores/profiles'
import { useClientsStore } from '@/stores/clients'
import type { ProfileView } from '@/types/api'
import api from '@/services/api'
import type { EffectiveToolsResult, ProfileView } from '@/types/api'

// Spec 108-i I17 / FR-040: the Profiles page. A server-edition tenant sees the
// profiles it can reach, read only and without `used_by`.
Expand All @@ -77,6 +79,28 @@ const tenant = computed(() => auth.principalKind === 'tenant')
const createOpen = ref(false)
const assignTo = ref('')
const deleting = ref<ProfileView | null>(null)
const accessCounts = ref<Record<string, EffectiveToolsResult['counts']>>({})
let countsGeneration = 0
let countsRefreshTimer: ReturnType<typeof setTimeout> | null = null
// Use the same live access projection as the profile preview. A profile's tier
// counts describe policy permission, and cannot tell whether its tools are callable.
async function refreshAccessCounts() {
const generation = ++countsGeneration
if (tenant.value) { accessCounts.value = {}; return } // callable/by_reason are administrator-only
const names = store.profiles.map(p => p.name)
const results = await Promise.allSettled(names.map(name => api.getProfileEffectiveTools(name)))
if (generation !== countsGeneration) return
const next: Record<string, EffectiveToolsResult['counts']> = {}
results.forEach((result, i) => {
if (result.status === 'fulfilled') next[names[i]] = result.value.counts
})
accessCounts.value = next
}
watch([() => store.profiles, tenant], () => { void refreshAccessCounts() })
function scheduleAccessCountsRefresh() {
if (countsRefreshTimer) clearTimeout(countsRefreshTimer)
countsRefreshTimer = setTimeout(() => { countsRefreshTimer = null; void refreshAccessCounts() }, 150)
}

const errorText = computed(() => {
if (store.errorStatus === 503) return 'Profile evaluation is unavailable; retry in a moment'
Expand Down Expand Up @@ -113,5 +137,11 @@ onMounted(() => {
void store.fetchProfiles()
// Who uses a profile (client names) comes from the clients store.
if (!tenant.value && (!clients.allClients.length || clients.stale)) void clients.refreshPresence()
window.addEventListener('mcpproxy:servers-changed', scheduleAccessCountsRefresh)
})
onUnmounted(() => {
countsGeneration++
if (countsRefreshTimer) clearTimeout(countsRefreshTimer)
window.removeEventListener('mcpproxy:servers-changed', scheduleAccessCountsRefresh)
})
</script>
Loading
Loading