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

@@ -836,6 +836,12 @@ func conformCases() []conformCase {
{"POST /account/contributions/{name}/actions/{action}", 200, "cabana.Envelope-cabana_AccountActionResultView", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
return e.send(t, http.MethodPost, "/account/contributions/conform_link/actions/open", nil, true)
}, into[cabana.Envelope[cabana.AccountActionResultView]](), nil},
{"GET /mcp/consent/{request}", 200, "cabana.Envelope-cabana_MCPConsentView", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
return e.send(t, http.MethodGet, "/mcp/consent/conform-request", nil, true)
}, into[cabana.Envelope[cabana.MCPConsentView]](), nil},
{"POST /mcp/consent/{request}", 200, "cabana.Envelope-cabana_MCPConsentDecisionView", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
return e.send(t, http.MethodPost, "/mcp/consent/conform-request", map[string]any{"decision": "allow", "scopes": []string{"admin:read"}, "offline_access": true}, true)
}, into[cabana.Envelope[cabana.MCPConsentDecisionView]](), nil},
{"POST /auth/logout", 200, "cabana.Envelope-cabana_AdminLogoutData", func(t *testing.T, e *conformEnv) *httptest.ResponseRecorder {
return e.send(t, http.MethodPost, "/auth/logout", nil, true)
}, into[cabana.Envelope[cabana.AdminLogoutData]](), nil},
@@ -1134,6 +1140,10 @@ func newConformEnv(t *testing.T) *conformEnv {
if err := app.Publish[postcard.Mailer](mailer); err != nil {
t.Fatal(err)
}
// The MCP consent routes serve a fake administrator-only consent provider.
if err := app.Publish[pact.MCPAdminConsent](conformConsent{}); err != nil {
t.Fatal(err)
}
// The acme.companions fixture serves the Phase 17 routes (dependent
// options) next to the gadgets.
plugins := []party.Plugin{conformPlugin{stamp: stamp}, companionsPlugin{app: app}}
@@ -1238,6 +1248,30 @@ func (conformSettings) TableName() string { return "cabana_conform_settin
func (conformSettings) Fillable() []string { return []string{"enabled", "api_key"} }
func (conformSettings) Rules() map[string]string { return map[string]string{} }
// conformConsent is the fake pact.MCPAdminConsent of the conformance
// suite: one pending request asking for admin:read and offline access.
type conformConsent struct{}
func (conformConsent) MCPAdminConsentShow(_ context.Context, _ uint, requestID string) (pact.MCPAdminConsentRequest, error) {
if requestID != "conform-request" {
return pact.MCPAdminConsentRequest{}, pact.ErrMCPConsentNotFound
}
return pact.MCPAdminConsentRequest{
RequestID: requestID, ClientID: "oas_conform", ClientName: "Conform agent", RedirectURI: "https://agent.example.test/callback",
Scopes: []string{"admin:read"}, OfflineAccess: true, ConsentRequired: true, ExpiresAt: time.Now().Add(10 * time.Minute),
}, nil
}
func (conformConsent) MCPAdminConsentDecide(_ context.Context, _ uint, requestID string, decision pact.MCPAdminConsentDecision) (string, error) {
if requestID != "conform-request" {
return "", pact.ErrMCPConsentNotFound
}
if len(decision.Scopes) == 0 && decision.Allow {
return "", pact.ErrMCPConsentNoScopes
}
return "https://agent.example.test/callback?code=conform", nil
}
type conformPlugin struct{ stamp string }
func (conformPlugin) ID() string { return "acme.conform" }