pub struct ServerId(/* private fields */);Expand description
Server identifier (newtype over String).
Represents a unique identifier for an MCP server. Using a strong type
prevents accidentally mixing server IDs with other string values, and
ServerId::new enforces that every ServerId is safe to use as a single
path segment (see validate_path_segment),
since server IDs are ultimately confined into filesystem paths (e.g.
~/.claude/servers/{server_id}).
§Examples
use mcp_execution_core::ServerId;
let id = ServerId::new("example-server").unwrap();
assert_eq!(id.as_str(), "example-server");
assert!(ServerId::new("../escape").is_err());Deserialize is routed through ServerId::new (via #[serde(try_from = "String")]),
so serde_json::from_str::<ServerId>(...) — or any struct with a ServerId field, such as
mcp_execution_introspector::ServerInfo — enforces the same invariant as calling new
directly; there is no separate, unvalidated deserialization path.
Implementations§
Source§impl ServerId
impl ServerId
Sourcepub fn new(id: impl Into<String>) -> Result<Self, ServerIdError>
pub fn new(id: impl Into<String>) -> Result<Self, ServerIdError>
Creates a new server identifier, validating that id is a single non-empty path
segment with no .. or path separator.
§Errors
Returns ServerIdError::InvalidFormat if id is empty, or contains a .., a path
separator, or a root/prefix component.
§Examples
use mcp_execution_core::ServerId;
let id = ServerId::new("my-server").unwrap();
let from_string = ServerId::new(String::from("my-server")).unwrap();
assert_eq!(id, from_string);
assert!(ServerId::new("").is_err());
assert!(ServerId::new("a/b").is_err());Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the server ID as a string slice.
§Examples
use mcp_execution_core::ServerId;
let id = ServerId::new("test").unwrap();
assert_eq!(id.as_str(), "test");Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Consumes the ServerId and returns the inner String.
§Examples
use mcp_execution_core::ServerId;
let id = ServerId::new("test").unwrap();
let inner: String = id.into_inner();
assert_eq!(inner, "test");