pub struct ServerConnectionString(/* private fields */);Expand description
Validated MCP server connection string.
Ensures server identifiers are non-empty and contain only valid characters. This prevents command injection and path traversal attacks.
§Security
- Rejects empty strings
- Rejects strings with null bytes
- Trims whitespace
§Examples
use mcp_execution_core::cli::ServerConnectionString;
let conn = ServerConnectionString::new("github").unwrap();
assert_eq!(conn.as_str(), "github");
// Empty strings are rejected
assert!(ServerConnectionString::new("").is_err());
// Whitespace is trimmed
let conn = ServerConnectionString::new(" server ").unwrap();
assert_eq!(conn.as_str(), "server");Implementations§
Source§impl ServerConnectionString
impl ServerConnectionString
Sourcepub fn new(s: impl Into<String>) -> Result<Self>
pub fn new(s: impl Into<String>) -> Result<Self>
Creates a new validated server connection string.
§Security
This function validates input to prevent command injection attacks:
- Only allows alphanumeric characters and
-_./:for safe server identifiers - Rejects shell metacharacters (
&,|,;,$,`, etc.) - Rejects control characters to prevent CRLF injection
- Length limited to 256 characters
§Errors
Returns an error if:
- The string is empty after trimming
- The string contains invalid characters
- The string contains control characters
- The string exceeds 256 characters
§Examples
use mcp_execution_core::cli::ServerConnectionString;
let conn = ServerConnectionString::new("my-server")?;
assert_eq!(conn.as_str(), "my-server");
// Shell metacharacters are rejected for security
assert!(ServerConnectionString::new("server && rm -rf /").is_err());Trait Implementations§
Source§impl Clone for ServerConnectionString
impl Clone for ServerConnectionString
Source§fn clone(&self) -> ServerConnectionString
fn clone(&self) -> ServerConnectionString
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ServerConnectionString
impl Debug for ServerConnectionString
Source§impl Display for ServerConnectionString
impl Display for ServerConnectionString
Source§impl FromStr for ServerConnectionString
impl FromStr for ServerConnectionString
Source§impl Hash for ServerConnectionString
impl Hash for ServerConnectionString
Source§impl PartialEq for ServerConnectionString
impl PartialEq for ServerConnectionString
impl Eq for ServerConnectionString
impl StructuralPartialEq for ServerConnectionString
Auto Trait Implementations§
impl Freeze for ServerConnectionString
impl RefUnwindSafe for ServerConnectionString
impl Send for ServerConnectionString
impl Sync for ServerConnectionString
impl Unpin for ServerConnectionString
impl UnwindSafe for ServerConnectionString
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
Mutably borrows from an owned value. Read more