From bc11decc0b145c94cfe084dd47d7c28915ed8fa3 Mon Sep 17 00:00:00 2001 From: Joshua Mo <102877324+joshua-mo-143@users.noreply.github.com> Date: Wed, 9 Apr 2025 23:07:55 +0100 Subject: [PATCH] feat: impl From for ToolDefinition (#385) * feat: impl From for ToolDefinition * feat(core): impl &mcp_core::types::Tool for ToolDefinition --- rig-core/src/tool.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rig-core/src/tool.rs b/rig-core/src/tool.rs index 8c4b8cc..1d9a24d 100644 --- a/rig-core/src/tool.rs +++ b/rig-core/src/tool.rs @@ -204,6 +204,28 @@ where } } +#[cfg(feature = "mcp")] +impl From<&mcp_core::types::Tool> for ToolDefinition { + fn from(val: &mcp_core::types::Tool) -> Self { + Self { + name: val.name.to_owned(), + description: val.description.to_owned().unwrap_or_default(), + parameters: val.input_schema.to_owned(), + } + } +} + +#[cfg(feature = "mcp")] +impl From for ToolDefinition { + fn from(val: mcp_core::types::Tool) -> Self { + Self { + name: val.name, + description: val.description.unwrap_or_default(), + parameters: val.input_schema, + } + } +} + #[cfg(feature = "mcp")] #[derive(Debug, thiserror::Error)] #[error("MCP tool error: {0}")]