pub struct ScopePolicy { /* private fields */ }Expand description
Policy mapping MCP operations to their required OAuth scopes.
Allows configuring per-tool, per-resource, and per-prompt scope requirements, with a default fallback.
§Example
use tower_mcp::oauth::ScopePolicy;
let policy = ScopePolicy::new()
.default_scope("mcp:read")
.tool_scope("dangerous_tool", "mcp:admin")
.resource_scope("secret://data", "mcp:secret");Implementations§
Source§impl ScopePolicy
impl ScopePolicy
Sourcepub fn scope_matcher(self, matcher: impl ScopeMatcher) -> Self
pub fn scope_matcher(self, matcher: impl ScopeMatcher) -> Self
Use a custom matcher for exact or hierarchical scope semantics.
The matcher receives (granted, required) and should return true
when the granted scope authorizes the required scope.
Sourcepub fn default_scope(self, scope: impl Into<String>) -> Self
pub fn default_scope(self, scope: impl Into<String>) -> Self
Set a default scope required for all operations.
Sourcepub fn default_scopes(self, requirement: ScopeRequirement) -> Self
pub fn default_scopes(self, requirement: ScopeRequirement) -> Self
Set a default scope requirement for all operations.
Sourcepub fn tool_scope(
self,
tool_name: impl Into<String>,
scope: impl Into<String>,
) -> Self
pub fn tool_scope( self, tool_name: impl Into<String>, scope: impl Into<String>, ) -> Self
Set scope requirement for a specific tool.
The tool scope is checked in addition to the default scope.
Sourcepub fn tool_scopes(
self,
tool_name: impl Into<String>,
requirement: ScopeRequirement,
) -> Self
pub fn tool_scopes( self, tool_name: impl Into<String>, requirement: ScopeRequirement, ) -> Self
Set scope requirement for a specific tool with a full requirement.
Sourcepub fn resource_scope(
self,
resource_uri: impl Into<String>,
scope: impl Into<String>,
) -> Self
pub fn resource_scope( self, resource_uri: impl Into<String>, scope: impl Into<String>, ) -> Self
Set scope requirement for a specific resource.
Sourcepub fn prompt_scope(
self,
prompt_name: impl Into<String>,
scope: impl Into<String>,
) -> Self
pub fn prompt_scope( self, prompt_name: impl Into<String>, scope: impl Into<String>, ) -> Self
Set scope requirement for a specific prompt.
Sourcepub fn check_default(&self, claims: &TokenClaims) -> Result<(), OAuthError>
pub fn check_default(&self, claims: &TokenClaims) -> Result<(), OAuthError>
Check if the given claims satisfy the default scope requirement.
Sourcepub fn check_tool(
&self,
tool_name: &str,
claims: &TokenClaims,
) -> Result<(), OAuthError>
pub fn check_tool( &self, tool_name: &str, claims: &TokenClaims, ) -> Result<(), OAuthError>
Check if the given claims satisfy the scope requirement for a tool.
Checks both default scopes and tool-specific scopes.
Sourcepub fn check_resource(
&self,
resource_uri: &str,
claims: &TokenClaims,
) -> Result<(), OAuthError>
pub fn check_resource( &self, resource_uri: &str, claims: &TokenClaims, ) -> Result<(), OAuthError>
Check if the given claims satisfy the scope requirement for a resource.
Sourcepub fn check_prompt(
&self,
prompt_name: &str,
claims: &TokenClaims,
) -> Result<(), OAuthError>
pub fn check_prompt( &self, prompt_name: &str, claims: &TokenClaims, ) -> Result<(), OAuthError>
Check if the given claims satisfy the scope requirement for a prompt.
Trait Implementations§
Source§impl Clone for ScopePolicy
impl Clone for ScopePolicy
Source§fn clone(&self) -> ScopePolicy
fn clone(&self) -> ScopePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more