Files
supabase/apps/studio/components/interfaces/Account/AccessTokens/hooks/useCapabilitySummary.ts
kemal.earth ce27b4ee5b chore(studio): scoped pat mcp tool ui improvement (#49188)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Follow on from view permissions sheet and review step tidy up to show a
clear list of available mcp tools.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added an “Available MCP tools” section to scoped token reviews and
token details.
* Displays enabled tools as badges, with a clear empty state when none
are available.
* **Improvements**
  * Simplified capability cards to focus on enabled API endpoints.
* Removed per-permission MCP tool details and ungranted capability
listings.
* Updated endpoint count formatting for clearer singular and plural
labels.
* **Tests**
* Updated capability and token detail tests to reflect the new MCP tool
summary presentation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-18 12:29:12 +01:00

56 lines
1.5 KiB
TypeScript

import { useMemo } from 'react'
import {
getEntryScopes,
PERMISSION_CATALOG,
type PermissionCatalogEntry,
type PermissionMode,
type PermissionSelection,
} from '../AccessToken.permissions'
import {
getEnabledEndpointsForCapability,
type EnabledEndpoint,
type PermissionScopeMap,
} from '@/data/scoped-access-tokens/permission-scope-map-query'
interface UseCapabilitySummaryArgs {
selection: PermissionSelection
grantedScopes: string[]
permissionScopeMap: PermissionScopeMap | undefined
}
export interface CapabilitySummaryEntry {
entry: PermissionCatalogEntry
mode: PermissionMode
endpoints: EnabledEndpoint[]
}
/**
* Selection-derived summary data for the token view sheet: every granted catalog entry paired with
* the Management API endpoints it enables.
*/
export const useCapabilitySummary = ({
selection,
grantedScopes,
permissionScopeMap,
}: UseCapabilitySummaryArgs) => {
const capabilities = useMemo(() => {
const result: CapabilitySummaryEntry[] = []
for (const entry of PERMISSION_CATALOG) {
const mode = selection[entry.key] ?? 'none'
if (mode === 'none') continue
const capabilityScopes = getEntryScopes(entry, mode)
const endpoints = getEnabledEndpointsForCapability({
capabilityScopes,
allGrantedScopes: grantedScopes,
permissionScopeMap,
})
result.push({ entry, mode, endpoints })
}
return result
}, [selection, grantedScopes, permissionScopeMap])
return { capabilities }
}