pub struct StaticResourceHandler { /* private fields */ }Expand description
Handler for static resources loaded from configuration.
Implements the PMCP SDK ResourceHandler trait for serving pre-loaded
resources via MCP resources/list and resources/read. Storage is an
IndexMap (Pattern D) so iteration order is deterministic across runs.
§Orthogonality with skills
StaticResourceHandler is independent of [pmcp::server::skills::Skill]
and bootstrap_skill_and_prompt. Downstream consumers can register both
surfaces side-by-side; the toolkit makes no assumption about skill
registration (RESEARCH §Risks #3).
Implementations§
Source§impl StaticResourceHandler
impl StaticResourceHandler
Sourcepub fn new(resources: IndexMap<String, LoadedResource>) -> Self
pub fn new(resources: IndexMap<String, LoadedResource>) -> Self
Create a handler from a pre-built IndexMap.
This is the constructor Plan 08 will target from
impl From<&ServerConfig> for StaticResourceHandler.
§Example
use pmcp_server_toolkit::resources::StaticResourceHandler;
use indexmap::IndexMap;
let map = IndexMap::new();
let handler = StaticResourceHandler::new(map);Sourcepub fn from_configs(configs: &[ResourceConfig]) -> Result<Self>
pub fn from_configs(configs: &[ResourceConfig]) -> Result<Self>
Create a new handler from a list of resource configurations.
Insertion order is preserved — list() reflects the order configs
were supplied in.
Sourcepub fn get(&self, uri: &str) -> Option<&LoadedResource>
pub fn get(&self, uri: &str) -> Option<&LoadedResource>
Get a resource by URI (for use outside of the trait).
Trait Implementations§
Source§impl From<&ServerConfig> for StaticResourceHandler
impl From<&ServerConfig> for StaticResourceHandler
Source§fn from(cfg: &ServerConfig) -> Self
fn from(cfg: &ServerConfig) -> Self
Build a StaticResourceHandler from a parsed crate::config::ServerConfig.
Each [[resources]] entry in config becomes one LoadedResource.
Resources with no content field default to an empty body — the
strict-parse path’s crate::config::ServerConfig::validate does not
flag empty resource bodies (operators may use the placeholder form
"loaded from path.md" as a stable URI handle), so this construction
follows suit. Resources WITH content_file semantics are out of scope
for the lifted shape (Lambda runtime constraint, mirroring
LoadedResource::from_config).
Insertion order matches the order of [[resources]] declarations,
satisfying Pattern D (deterministic list() output).
§Example
use pmcp_server_toolkit::{ServerConfig, StaticResourceHandler};
let cfg = ServerConfig::default();
let handler = StaticResourceHandler::from(&cfg);
assert_eq!(handler.len(), 0); // default config has no [[resources]]Source§impl ResourceHandler for StaticResourceHandler
impl ResourceHandler for StaticResourceHandler
Auto Trait Implementations§
impl Freeze for StaticResourceHandler
impl RefUnwindSafe for StaticResourceHandler
impl Send for StaticResourceHandler
impl Sync for StaticResourceHandler
impl Unpin for StaticResourceHandler
impl UnsafeUnpin for StaticResourceHandler
impl UnwindSafe for StaticResourceHandler
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more