Skip to main content

ToolkitHooks

Struct ToolkitHooks 

Source
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

Source

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.

Source

pub fn with_request_policy(self, policy: Arc<dyn RequestPolicy>) -> Self

Register the E1 RequestPolicy, replacing any already set.

Source

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).

Source

pub fn request_policy(&self) -> Option<Arc<dyn RequestPolicy>>

The registered RequestPolicy, if any.

Source

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.

Source

pub fn validator_names(&self) -> Vec<&str>

Registered validator tool names, sorted.

Source

pub fn is_empty(&self) -> bool

Whether this value registers nothing at all — the Default shape.

Read by the assembly paths so a hooks value that registers something can be reported in the startup log, and so a path with no surface to apply a policy to can say so rather than accept it silently.

Trait Implementations§

Source§

impl Clone for ToolkitHooks

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ToolkitHooks

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ToolkitHooks

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Send for T
where T: ?Sized,

Source§

impl<T> Sync for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more