feat(32.1-01): publish one MCP scope list and call context

- pact gains MemberTokenScopeCatalog, MCPAdvertisedScopes and MCPCall
- an empty MCP ScopesSupported resolves to the five fixed names including backend
- pier copies advertised scopes and sets MCPCall beside WithDispatch
This commit is contained in:
2026-10-28 14:32:31 +01:00
parent 2cea3127cc
commit 63d05e8acb
11 changed files with 322 additions and 27 deletions

View File

@@ -34,7 +34,9 @@ type Options struct {
ServiceDocumentationPath string
// ScopesSupported is the RFC 8414 scopes_supported list. PHP default:
// ["read","write","ai","offline_access"].
// ["read","write","ai","offline_access"]. On the MCP flavour an empty
// or nil list resolves to those four plus backend; a non-empty list is
// used as given. OIDC discovery does not read this field.
ScopesSupported []string
// TokenEndpointAuthMethodsSupported is the RFC 8414
@@ -189,13 +191,32 @@ func (s *Server) Metadata(w http.ResponseWriter, r *http.Request) {
GrantTypesSupported: []string{"authorization_code", "refresh_token"},
CodeChallengeMethodsSupported: []string{"S256"},
TokenEndpointAuthMethodsSupported: s.opts.TokenEndpointAuthMethodsSupported,
ScopesSupported: s.opts.ScopesSupported,
ScopesSupported: s.resolvedScopes(),
ServiceDocumentation: s.opts.Issuer + s.opts.ServiceDocumentationPath,
AuthorizationResponseIssParameterSupported: s.opts.AuthorizationResponseIssParameterSupported,
}
writeExactJSON(w, http.StatusOK, doc, map[string]string{"Cache-Control": "no-cache, private"})
}
// mcpEmptyScopes is the MCP flavour's scope list when Options.ScopesSupported
// is empty or nil. A non-empty list is not widened to include backend.
var mcpEmptyScopes = []string{"read", "write", "ai", "offline_access", "backend"}
// resolvedScopes is the one scope slice Metadata advertises and
// allowedAuthorizeScopes accepts. A non-empty Options.ScopesSupported is
// cloned as given. An empty or nil list on the MCP flavour (NewServer, the
// flavour zero value) resolves to mcpEmptyScopes. The OIDC flavour is not
// given that list: its discovery document is separate.
func (s *Server) resolvedScopes() []string {
if s != nil && len(s.opts.ScopesSupported) > 0 {
return append([]string(nil), s.opts.ScopesSupported...)
}
if s != nil && s.flavour == flavourOIDC {
return append([]string(nil), s.opts.ScopesSupported...)
}
return append([]string(nil), mcpEmptyScopes...)
}
// writeExactJSON writes v as an unwrapped, no-trailing-newline JSON document
// (matching the wire/response.go WriteJSON technique) but never falls back to
// the house opaque-500 envelope: raw RFC responses must never acquire a