pub struct DynamicResourceTemplateRegistry { /* private fields */ }Expand description
A thread-safe, cloneable handle for runtime resource template management.
Obtained from McpRouter::with_dynamic_resource_templates().
Templates registered here are merged with the router’s static templates
when handling resources/templates/list and resources/read requests.
Static templates are checked before dynamic ones.
When a template is registered or unregistered, all connected sessions
receive a notifications/resources/list_changed notification.
§Example
use tower_mcp::{McpRouter, ResourceTemplateBuilder};
let (router, registry) = McpRouter::new()
.server_info("my-server", "1.0.0")
.with_dynamic_resource_templates();
let template = ResourceTemplateBuilder::new("db://tables/{table}")
.name("Database Table")
.handler(|uri, vars| async move { /* ... */ });
registry.register(template);Implementations§
Source§impl DynamicResourceTemplateRegistry
impl DynamicResourceTemplateRegistry
Sourcepub fn register(&self, template: ResourceTemplate)
pub fn register(&self, template: ResourceTemplate)
Register a resource template.
Broadcasts ResourcesListChanged to all connected sessions.
Sourcepub fn unregister(&self, uri_template: &str) -> bool
pub fn unregister(&self, uri_template: &str) -> bool
Unregister a resource template by URI pattern.
Returns true if the template existed and was removed.
Broadcasts ResourcesListChanged only if the template was actually removed.
Sourcepub fn list(&self) -> Vec<Arc<ResourceTemplate>>
pub fn list(&self) -> Vec<Arc<ResourceTemplate>>
List all currently registered dynamic resource templates.
Trait Implementations§
Source§impl Clone for DynamicResourceTemplateRegistry
impl Clone for DynamicResourceTemplateRegistry
Source§fn clone(&self) -> DynamicResourceTemplateRegistry
fn clone(&self) -> DynamicResourceTemplateRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more