pub struct Validator;
Expand description
Protocol validation utilities
Implementations§
Source§impl Validator
impl Validator
Sourcepub fn validate_uuid(uuid_str: &str) -> Result<Uuid>
pub fn validate_uuid(uuid_str: &str) -> Result<Uuid>
Sourcepub fn validate_non_empty(value: &str, field_name: &str) -> Result<()>
pub fn validate_non_empty(value: &str, field_name: &str) -> Result<()>
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<()>
pub fn validate_tool_name(name: &str) -> Result<()>
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_resource_uri(uri: &str) -> Result<()>
pub fn validate_resource_uri(uri: &str) -> Result<()>
Sourcepub fn validate_json_schema(schema: &Value) -> Result<()>
pub fn validate_json_schema(schema: &Value) -> Result<()>
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<()>
pub fn validate_tool_arguments( args: &HashMap<String, Value>, schema: &Value, ) -> Result<()>
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<()>
pub fn validate_pagination( cursor: Option<&str>, limit: Option<u32>, ) -> Result<()>
Validate pagination parameters
§Errors
Returns an error if cursor is empty, limit is 0, or limit exceeds 1000
Sourcepub fn validate_prompt_name(name: &str) -> Result<()>
pub fn validate_prompt_name(name: &str) -> Result<()>
Sourcepub fn validate_struct<T: Validate>(item: &T) -> Result<()>
pub fn validate_struct<T: Validate>(item: &T) -> Result<()>
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<()>
pub fn validate_structured_content( content: &Value, output_schema: &Value, ) -> Result<()>
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<()>
pub fn validate_tool_output_schema(output_schema: &Value) -> Result<()>
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