pub struct Validator;
Expand description
Protocol validation utilities
Implementations§
Source§impl Validator
impl Validator
Sourcepub fn validate_non_empty(value: &str, field_name: &str) -> Result<(), Error>
pub fn validate_non_empty(value: &str, field_name: &str) -> Result<(), Error>
Validate that a string is not empty
§Errors
Returns an error if the string is empty or contains only whitespace
Sourcepub fn validate_tool_name(name: &str) -> Result<(), Error>
pub fn validate_tool_name(name: &str) -> Result<(), Error>
Validate a tool name (must be alphanumeric with underscores)
§Errors
Returns an error if the name is empty or contains invalid characters
Sourcepub fn validate_json_schema(schema: &Value) -> Result<(), Error>
pub fn validate_json_schema(schema: &Value) -> Result<(), Error>
Validate JSON schema
§Errors
Returns an error if the schema is not a valid JSON object with a type field
Sourcepub fn validate_tool_arguments(
args: &HashMap<String, Value>,
schema: &Value,
) -> Result<(), Error>
pub fn validate_tool_arguments( args: &HashMap<String, Value>, schema: &Value, ) -> Result<(), Error>
Validate tool arguments against a schema
§Errors
Returns an error if required arguments are missing from the provided arguments
Sourcepub fn validate_pagination(
cursor: Option<&str>,
limit: Option<u32>,
) -> Result<(), Error>
pub fn validate_pagination( cursor: Option<&str>, limit: Option<u32>, ) -> Result<(), Error>
Validate pagination parameters
§Errors
Returns an error if cursor is empty, limit is 0, or limit exceeds 1000
Sourcepub fn validate_struct<T>(item: &T) -> Result<(), Error>where
T: Validate,
pub fn validate_struct<T>(item: &T) -> Result<(), Error>where
T: Validate,
Validate a struct using the validator crate
§Errors
Returns an error if the struct fails validation according to its validation rules
Sourcepub fn validate_structured_content(
content: &Value,
output_schema: &Value,
) -> Result<(), Error>
pub fn validate_structured_content( content: &Value, output_schema: &Value, ) -> Result<(), Error>
Validate structured content against a JSON schema
§Errors
Returns an error if the content doesn’t match the schema or if the schema is invalid
Sourcepub fn validate_tool_output_schema(output_schema: &Value) -> Result<(), Error>
pub fn validate_tool_output_schema(output_schema: &Value) -> Result<(), Error>
Validate that a tool’s output schema is properly defined
§Errors
Returns an error if the output schema is invalid or incompatible with MCP requirements
Sourcepub fn format_validation_errors<'a>(
errors: impl Iterator<Item = ValidationError<'a>>,
) -> String
pub fn format_validation_errors<'a>( errors: impl Iterator<Item = ValidationError<'a>>, ) -> String
Extract validation errors in a user-friendly format
§Errors
Returns formatted validation error messages
Auto Trait Implementations§
impl Freeze for Validator
impl RefUnwindSafe for Validator
impl Send for Validator
impl Sync for Validator
impl Unpin for Validator
impl UnwindSafe for Validator
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