pub struct ResourceMetadata { /* private fields */ }Expand description
An RFC 9728 protected-resource metadata document.
What an MCP server publishes to tell a client which authorization servers can issue tokens for it, and which scopes those tokens should carry.
§Wire form
Field names are the snake_case ones RFC 9728 §2 defines — unlike the rest of
MCP’s wire types, so this one derives Serialize rather than renaming to
camelCase. skip_serializing_if is not an optimisation: §3.2 says a
parameter with zero values MUST be omitted, so an empty
authorization_servers is absent rather than []. resource is the one
field that is always present.
Implementations§
Source§impl ResourceMetadata
impl ResourceMetadata
Sourcepub fn new(resource: ResourceUri) -> Self
pub fn new(resource: ResourceUri) -> Self
A document for resource, with the mandatory resource field and
nothing optional.
§Examples
use protocol_droid::domain::mcp::{ResourceMetadata, ResourceUri};
let metadata = ResourceMetadata::new(ResourceUri::new("https://example.com/mcp")?);
assert_eq!(metadata.resource().as_str(), "https://example.com/mcp");
assert!(metadata.authorization_servers().is_empty());Names an authorization server that can issue tokens for this resource.
Sourcepub fn with_scope(self, scope: impl Into<Arc<str>>) -> Self
pub fn with_scope(self, scope: impl Into<Arc<str>>) -> Self
Declares a scope a token may carry.
Sourcepub const fn resource(&self) -> &ResourceUri
pub const fn resource(&self) -> &ResourceUri
The canonical resource identifier, and the audience a token must carry.
The authorization servers this resource names.
Sourcepub fn scopes_supported(&self) -> &[Arc<str>]
pub fn scopes_supported(&self) -> &[Arc<str>]
The scopes this resource declares.
Sourcepub fn bearer_methods_supported(&self) -> &[BearerMethod]
pub fn bearer_methods_supported(&self) -> &[BearerMethod]
How a bearer token may be presented.
Sourcepub fn challenge(&self) -> Result<String, ResourceUriError>
pub fn challenge(&self) -> Result<String, ResourceUriError>
The WWW-Authenticate challenge for a request that was refused.
RFC 9728 §5.1: the challenge carries resource_metadata so the client
knows where to discover the authorization server, which is the whole
reason a server publishes the document.
§Errors
ResourceUriError::NoOrigin when the resource identifier has no
origin, which the constructor rules out.
§Examples
use protocol_droid::domain::mcp::{ResourceMetadata, ResourceUri};
let metadata = ResourceMetadata::new(ResourceUri::new("https://example.com/mcp")?);
assert_eq!(
metadata.challenge()?,
"Bearer resource_metadata=\"https://example.com/.well-known/oauth-protected-resource/mcp\"",
);