pub struct ToolkitHooks { /* private fields */ }Expand description
The registered E1 policy and E2 validators, passed as a PARAMETER to an assembly entry point.
§Why a parameter and not a builder field
ServerBuilderExt is implemented for CORE’s pmcp::ServerBuilder, whose
fields are private. A Rust extension trait cannot add a field to a foreign
type, so a with_request_policy(self) -> Self on that trait would have
nowhere to accumulate. Two alternatives were rejected: a newtype wrapper
around ServerBuilder would force every existing ServerBuilderExt user to
change type, and adding an extension-storage mechanism to core’s
ServerBuilder is a core API change this phase did not scope.
§Example
use std::sync::Arc;
use pmcp_server_toolkit::{ArgumentRefusal, ArgumentValidator, ToolkitHooks};
use serde_json::Value;
struct Never;
impl ArgumentValidator for Never {
fn validate(&self, _args: &Value) -> Result<(), ArgumentRefusal> {
Err(ArgumentRefusal::new("this tool is disabled"))
}
}
let hooks = ToolkitHooks::default().with_argument_validator("get_line_status", Arc::new(Never));
assert_eq!(hooks.validator_names(), vec!["get_line_status"]);Implementations§
Source§impl ToolkitHooks
impl ToolkitHooks
Sourcepub fn new() -> Self
pub fn new() -> Self
No policy and no validators — the shape every pre-existing entry point passes, so a server that registers neither behaves exactly as before.
Sourcepub fn with_request_policy(self, policy: Arc<dyn RequestPolicy>) -> Self
pub fn with_request_policy(self, policy: Arc<dyn RequestPolicy>) -> Self
Register the E1 RequestPolicy, replacing any already set.
Sourcepub fn with_argument_validator(
self,
tool: impl Into<String>,
validator: Arc<dyn ArgumentValidator>,
) -> Self
pub fn with_argument_validator( self, tool: impl Into<String>, validator: Arc<dyn ArgumentValidator>, ) -> Self
Register an E2 ArgumentValidator for one tool name (last one wins).
Sourcepub fn request_policy(&self) -> Option<Arc<dyn RequestPolicy>>
pub fn request_policy(&self) -> Option<Arc<dyn RequestPolicy>>
The registered RequestPolicy, if any.
Sourcepub fn argument_validator_for(
&self,
tool: &str,
) -> Option<Arc<dyn ArgumentValidator>>
pub fn argument_validator_for( &self, tool: &str, ) -> Option<Arc<dyn ArgumentValidator>>
The ArgumentValidator registered for tool, if any.
Named argument_validator_for and NOT validator_for: the root crate’s
tests/v2_schema_tripwires.rs scans every workspace source file for the
token validator_for( as the signature of a jsonschema validator being
constructed, and requires each site to declare its dialect policy. A method
with that name here — and every call to it — would fire that security
tripwire on code that has nothing to do with JSON Schema dialects, and the
only ways out would be to bloat a dialect allowlist with non-dialect entries
or to re-fire on every future call site. Measured: the short name failed the
tripwire with two UNKNOWN sites.
Sourcepub fn validator_names(&self) -> Vec<&str>
pub fn validator_names(&self) -> Vec<&str>
Registered validator tool names, sorted.
Trait Implementations§
Source§impl Clone for ToolkitHooks
impl Clone for ToolkitHooks
Source§impl Debug for ToolkitHooks
impl Debug for ToolkitHooks
Auto Trait Implementations§
impl !RefUnwindSafe for ToolkitHooks
impl !UnwindSafe for ToolkitHooks
impl Freeze for ToolkitHooks
impl Send for ToolkitHooks
impl Sync for ToolkitHooks
impl Unpin for ToolkitHooks
impl UnsafeUnpin for ToolkitHooks
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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