pub struct StaticPromptHandler { /* private fields */ }Expand description
Handler for a single static prompt with pre-resolved body content.
Implements pmcp::PromptHandler with required-argument validation and
metadata. Each StaticPromptHandler represents ONE prompt; use
StaticPromptHandler::from_configs to materialize a Vec of
(name, handler) pairs from a Vec<PromptConfig> and register them via
prompt_arc(name, handler) calls on the builder.
§Orthogonality with skills
StaticPromptHandler 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. The dual-surface byte-equality invariant (Phase 80 /
SEP-2640 §9) applies only when a consumer wires skill + prompt for the
SAME logical prompt — orthogonal to anything StaticPromptHandler does.
Implementations§
Source§impl StaticPromptHandler
impl StaticPromptHandler
Sourcepub fn new(
name: impl Into<String>,
description: Option<impl Into<String>>,
arguments: Vec<PromptArgument>,
body: impl Into<String>,
) -> Self
pub fn new( name: impl Into<String>, description: Option<impl Into<String>>, arguments: Vec<PromptArgument>, body: impl Into<String>, ) -> Self
Create a handler for a single prompt.
body is the message text returned from handle() after required-arg
validation succeeds. Pre-resolve any include_resources content into
body before calling new (see StaticPromptHandler::from_configs
for the canonical resolution path).
§Example
use pmcp_server_toolkit::prompts::StaticPromptHandler;
let handler = StaticPromptHandler::new(
"shipping-context",
Some("Loads shipping policy context"),
vec![],
"Policies:\n- Alcohol requires adult signature.",
);Sourcepub fn from_configs(
prompts: &[PromptConfig],
resources: &StaticResourceHandler,
) -> Vec<(String, Self)>
pub fn from_configs( prompts: &[PromptConfig], resources: &StaticResourceHandler, ) -> Vec<(String, Self)>
Materialize a Vec of (name, handler) pairs from prompt configs by
pre-resolving each include_resources against the supplied resource
handler.
Missing resources are logged at warn and skipped (matching the
lifted behavior). The resulting body is the resource contents joined
with \n\n---\n\n; if no resources resolve, the body is a
(No resources found for prompt 'name') placeholder.
Returns the same insertion order as prompts so deterministic
registration with prompt_arc(name, handler) is possible.
Trait Implementations§
Source§impl From<&ServerConfig> for StaticPromptHandler
impl From<&ServerConfig> for StaticPromptHandler
Source§fn from(cfg: &ServerConfig) -> Self
fn from(cfg: &ServerConfig) -> Self
Build a single StaticPromptHandler from a crate::config::ServerConfig.
Returns a handler for the FIRST [[prompts]] entry, or — if none are
declared — a no-op handler named "<no-prompts>" with an empty body.
Multi-prompt servers should use prompt_handlers_from_config instead.
§Example
use pmcp_server_toolkit::{ServerConfig, StaticPromptHandler};
let cfg = ServerConfig::default();
let _handler = StaticPromptHandler::from(&cfg);Source§impl PromptHandler for StaticPromptHandler
impl PromptHandler for StaticPromptHandler
Source§fn handle<'life0, 'async_trait>(
&'life0 self,
args: HashMap<String, String>,
_extra: RequestHandlerExtra,
) -> Pin<Box<dyn Future<Output = Result<GetPromptResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle<'life0, 'async_trait>(
&'life0 self,
args: HashMap<String, String>,
_extra: RequestHandlerExtra,
) -> Pin<Box<dyn Future<Output = Result<GetPromptResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn metadata(&self) -> Option<PromptInfo>
fn metadata(&self) -> Option<PromptInfo>
Auto Trait Implementations§
impl Freeze for StaticPromptHandler
impl RefUnwindSafe for StaticPromptHandler
impl Send for StaticPromptHandler
impl Sync for StaticPromptHandler
impl Unpin for StaticPromptHandler
impl UnsafeUnpin for StaticPromptHandler
impl UnwindSafe for StaticPromptHandler
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