pub struct ToolName(/* private fields */);Expand description
Tool name identifier (newtype over String).
Represents the name of an MCP tool. Using a strong type ensures tool names are not
confused with other string values, and ToolName::new enforces the same baseline
shape as ServerId::new (see validate_path_segment),
since generated tool names are ultimately used to derive output file names.
§Examples
use mcp_execution_core::ToolName;
let tool = ToolName::new("execute_code").unwrap();
assert_eq!(tool.as_str(), "execute_code");
assert!(ToolName::new("").is_err());Deserialize is routed through ToolName::new (via #[serde(try_from = "String")]),
so serde_json::from_str::<ToolName>(...) — or any struct with a ToolName field, such as
mcp_execution_introspector::ToolInfo — enforces the same invariant as calling new
directly; there is no separate, unvalidated deserialization path.
Implementations§
Source§impl ToolName
impl ToolName
Sourcepub fn new(name: impl Into<String>) -> Result<Self, ToolNameError>
pub fn new(name: impl Into<String>) -> Result<Self, ToolNameError>
Creates a new tool name, validating that name is a single non-empty path segment
with no .. or path separator.
§Errors
Returns ToolNameError::InvalidFormat if name is empty, or contains a .., a
path separator, or a root/prefix component.
§Examples
use mcp_execution_core::ToolName;
let name = ToolName::new("my_tool").unwrap();
assert_eq!(name.as_str(), "my_tool");
assert!(ToolName::new("a/b").is_err());Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the tool name as a string slice.
§Examples
use mcp_execution_core::ToolName;
let name = ToolName::new("test_tool").unwrap();
assert_eq!(name.as_str(), "test_tool");Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Consumes the ToolName and returns the inner String.
§Examples
use mcp_execution_core::ToolName;
let name = ToolName::new("tool").unwrap();
let inner: String = name.into_inner();
assert_eq!(inner, "tool");