pub struct DynamicResourceRegistry { /* private fields */ }Expand description
A thread-safe, cloneable handle for runtime resource management.
Obtained from McpRouter::with_dynamic_resources().
Resources registered here are merged with the router’s static resources
when handling resources/list and resources/read requests. Static
resources take precedence over dynamic resources when URIs collide.
When a resource is registered or unregistered, all connected sessions
receive a notifications/resources/list_changed notification.
§Example
use tower_mcp::{McpRouter, ResourceBuilder};
let (router, registry) = McpRouter::new()
.server_info("my-server", "1.0.0")
.with_dynamic_resources();
let resource = ResourceBuilder::new("file:///data.json")
.name("Data")
.text(r#"{"key": "value"}"#);
registry.register(resource);Implementations§
Source§impl DynamicResourceRegistry
impl DynamicResourceRegistry
Sourcepub fn register(&self, resource: Resource)
pub fn register(&self, resource: Resource)
Register a resource, replacing any existing resource with the same URI.
Broadcasts ResourcesListChanged to all connected sessions.
Sourcepub fn unregister(&self, uri: &str) -> bool
pub fn unregister(&self, uri: &str) -> bool
Unregister a resource by URI.
Returns true if the resource existed and was removed.
Broadcasts ResourcesListChanged only if the resource was actually removed.
Trait Implementations§
Source§impl Clone for DynamicResourceRegistry
impl Clone for DynamicResourceRegistry
Source§fn clone(&self) -> DynamicResourceRegistry
fn clone(&self) -> DynamicResourceRegistry
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for DynamicResourceRegistry
impl RefUnwindSafe for DynamicResourceRegistry
impl Send for DynamicResourceRegistry
impl Sync for DynamicResourceRegistry
impl Unpin for DynamicResourceRegistry
impl UnsafeUnpin for DynamicResourceRegistry
impl UnwindSafe for DynamicResourceRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more