Class: OAuth2::MCP::ProtectedResourceMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/mcp.rb

Overview

Represents OAuth protected-resource metadata for an MCP HTTP endpoint.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, authorization_servers:, scopes_supported: [], **metadata) ⇒ ProtectedResourceMetadata

Returns a new instance of ProtectedResourceMetadata.

Raises:



504
505
506
507
508
509
510
511
512
513
# File 'lib/oauth2/mcp.rb', line 504

def initialize(resource:, authorization_servers:, scopes_supported: [], **)
  @resource = normalize_required_uri(resource, "resource")
  @authorization_servers = Array(authorization_servers).map do |server|
    normalize_required_uri(server, "authorization server")
  end.freeze
  raise ConfigurationError, "authorization_servers must not be empty" if @authorization_servers.empty?

  @scopes_supported = Array(scopes_supported).map(&:to_s).freeze
  @metadata = .transform_keys(&:to_sym).freeze
end

Instance Attribute Details

#authorization_serversObject (readonly)

Returns the value of attribute authorization_servers.



502
503
504
# File 'lib/oauth2/mcp.rb', line 502

def authorization_servers
  @authorization_servers
end

#metadataObject (readonly)

Returns the value of attribute metadata.



502
503
504
# File 'lib/oauth2/mcp.rb', line 502

def 
  @metadata
end

#resourceObject (readonly)

Returns the value of attribute resource.



502
503
504
# File 'lib/oauth2/mcp.rb', line 502

def resource
  @resource
end

#scopes_supportedObject (readonly)

Returns the value of attribute scopes_supported.



502
503
504
# File 'lib/oauth2/mcp.rb', line 502

def scopes_supported
  @scopes_supported
end

Instance Method Details

#to_hObject



515
516
517
518
519
520
521
# File 'lib/oauth2/mcp.rb', line 515

def to_h
  {
    resource: resource,
    authorization_servers: authorization_servers,
    scopes_supported: scopes_supported,
  }.merge().compact
end

#to_jsonObject



523
524
525
# File 'lib/oauth2/mcp.rb', line 523

def to_json(*)
  JSON.generate(to_h, *)
end