feat(32.2-01): admin consent endpoint for administrator-only MCP grants

- pact: MCPAdminConsent provider interface, MCPAdminConsentRequest,
  MCPAdminConsentDecision, ErrMCPConsentNotFound, ErrMCPConsentNoScopes
- cabana: GET/POST {api}/mcp/consent/{request}, interactive-only, scope
  policy of personal tokens (requested, catalog, owned; * collapses)
- cabana: TokenScopeNames and TokenScopeLabels export the token-scope catalog
- swag views and annotations; admin.json and schema.d.ts regenerated so the
  contract and conformance inventories stay green
- phrasebook keys mcp_connect.request_not_found and no_grantable_scopes
This commit is contained in:
Jakub Zych
2026-11-21 00:14:43 +01:00
parent c63bfa3ef2
commit 97d7ee0586
18 changed files with 1296 additions and 3 deletions

View File

@@ -334,6 +334,65 @@ type MCPPersonalTokenResolver interface {
MCPResolvePersonalToken(ctx context.Context, raw string) (MCPSubject, bool, error)
}
// MCPAdminConsent serves the consent screen of administrator-only MCP
// grants (MCPGrantSubjectBackend) to the framework's admin API. One
// provider per application, published through app.Publish by the plugin
// that owns the MCP authorization server. The framework serves the
// cookie-authenticated consent endpoints for the signed-in administrator
// and owns the scope policy: it shows only requested scopes the
// administrator can grant and filters a decision the same way before it
// calls MCPAdminConsentDecide, so the provider only resolves and issues.
//
// MCPAdminConsentShow answers the pending request requestID for the
// administrator adminID; a missing, expired, used or foreign request is
// ErrMCPConsentNotFound. MCPAdminConsentDecide allows or denies it and
// answers the client redirect URI to send the browser to (carrying the
// code, or the access_denied error); ErrMCPConsentNotFound as for Show,
// ErrMCPConsentNoScopes when an allow decision leaves nothing to grant.
type MCPAdminConsent interface {
MCPAdminConsentShow(ctx context.Context, adminID uint, requestID string) (MCPAdminConsentRequest, error)
MCPAdminConsentDecide(ctx context.Context, adminID uint, requestID string, decision MCPAdminConsentDecision) (string, error)
}
// MCPAdminConsentRequest is one pending MCP authorization request as the
// administrator's consent screen shows it: the request id, the client (id,
// name, logo and the redirect URI the browser returns to), the requested
// data scopes (offline_access excluded), whether offline_access was
// requested, whether consent must be asked (false when this client was
// allowed before) and the request's expiry.
type MCPAdminConsentRequest struct {
RequestID string
ClientID string
ClientName string
LogoURL string
RedirectURI string
Scopes []string
OfflineAccess bool
ConsentRequired bool
ExpiresAt time.Time
}
// MCPAdminConsentDecision is the administrator's answer to a consent
// request: Allow, the scopes to grant (already filtered by the framework to
// requested scopes the administrator can grant, with * collapsed as for
// personal tokens) and OfflineAccess (a refresh token; only when it was
// requested). A deny carries no scopes.
type MCPAdminConsentDecision struct {
Allow bool
Scopes []string
OfflineAccess bool
}
// ErrMCPConsentNotFound is what an MCPAdminConsent answers for a consent
// request that does not exist, expired, was used or belongs to someone
// else; the admin API answers 404 request_not_found.
var ErrMCPConsentNotFound = errors.New("pact: mcp consent request not found")
// ErrMCPConsentNoScopes is what MCPAdminConsentDecide answers when an allow
// decision leaves no scope to grant; the admin API answers 422
// no_grantable_scopes.
var ErrMCPConsentNoScopes = errors.New("pact: mcp consent has no grantable scopes")
// MCPLinkedBackendResolver answers the verified backend account linked to a
// frontend user, published by the plugin that owns the link. The boolean is
// false when the user has no link.