#[macro_export]
macro_rules! elicit_newtype_methods {
(
$wrapper_name:ident => $inner_path:path,
$($methods:tt)*
) => {
$crate::elicit_newtype!($inner_path, as $wrapper_name);
$crate::__elicit_methods_impl! {
$wrapper_name,
$($methods)*
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __elicit_methods_impl {
($wrapper_name:ident,) => {};
(
$wrapper_name:ident,
$($method_tokens:tt)*
) => {
$crate::__classify_method! {
$wrapper_name,
$($method_tokens)*
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __classify_method {
(
$wrapper_name:ident,
consuming fn $method:ident ( $($param_name:ident : $param_ty:ty),* $(,)? ) -> Self ; $($rest:tt)*
) => {
$crate::__elicit_method_generate! {
$wrapper_name,
consuming fn $method($($param_name: $param_ty),*) -> Self
}
$crate::__elicit_methods_impl! {
$wrapper_name,
$($rest)*
}
};
(
$wrapper_name:ident,
consuming fn $method:ident ( $($param_name:ident : $param_ty:ty),* $(,)? ) -> $ret:ty ; $($rest:tt)*
) => {
$crate::__elicit_method_generate! {
$wrapper_name,
consuming fn $method($($param_name: $param_ty),*) -> $ret
}
$crate::__elicit_methods_impl! {
$wrapper_name,
$($rest)*
}
};
(
$wrapper_name:ident,
fn $method:ident ( $($param_name:ident : $param_ty:ty),* $(,)? ) -> $ret:ty ; $($rest:tt)*
) => {
$crate::__elicit_method_generate! {
$wrapper_name,
fn $method($($param_name: $param_ty),*) -> $ret
}
$crate::__elicit_methods_impl! {
$wrapper_name,
$($rest)*
}
};
(
$wrapper_name:ident,
consuming async fn $method:ident ( $($param_name:ident : $param_ty:ty),* $(,)? ) -> Self ; $($rest:tt)*
) => {
$crate::__elicit_method_generate! {
$wrapper_name,
consuming async fn $method($($param_name: $param_ty),*) -> Self
}
$crate::__elicit_methods_impl! {
$wrapper_name,
$($rest)*
}
};
(
$wrapper_name:ident,
consuming async fn $method:ident ( $($param_name:ident : $param_ty:ty),* $(,)? ) -> $ret:ty ; $($rest:tt)*
) => {
$crate::__elicit_method_generate! {
$wrapper_name,
consuming async fn $method($($param_name: $param_ty),*) -> $ret
}
$crate::__elicit_methods_impl! {
$wrapper_name,
$($rest)*
}
};
(
$wrapper_name:ident,
async fn $method:ident ( $($param_name:ident : $param_ty:ty),* $(,)? ) -> $ret:ty ; $($rest:tt)*
) => {
$crate::__elicit_method_generate! {
$wrapper_name,
async fn $method($($param_name: $param_ty),*) -> $ret
}
$crate::__elicit_methods_impl! {
$wrapper_name,
$($rest)*
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __elicit_method_generate {
(
$wrapper_name:ident,
consuming fn $method:ident($($param_name:ident: $param_ty:ty),*) -> Self
) => {
$crate::paste::paste! {
$crate::__elicit_param_struct! {
[<$method:camel Params>],
$($param_name: $param_ty),*
}
impl $wrapper_name {
#[doc = concat!("Consumes wrapper and delegates to inner `", stringify!($method), "` method.")]
#[doc = ""]
#[doc = "Uses hybrid strategy: unwraps Arc if single reference (zero-cost),"]
#[doc = "or clones if multiple references (requires T: Clone)."]
#[doc = ""]
#[doc = "Returns wrapped result for builder pattern chaining."]
pub fn $method(self, $($param_name: $param_ty),*) -> Self {
let inner = ::std::sync::Arc::try_unwrap(self.0)
.unwrap_or_else(|arc| (*arc).clone());
let result = inner.$method($($param_name),*);
Self::from(result) }
}
$crate::__elicit_tool_wrapper! {
$wrapper_name,
consuming fn $method($($param_name: $param_ty),*) -> Self
}
}
};
(
$wrapper_name:ident,
consuming fn $method:ident($($param_name:ident: $param_ty:ty),*) -> $ret:ty
) => {
$crate::paste::paste! {
$crate::__elicit_param_struct! {
[<$method:camel Params>],
$($param_name: $param_ty),*
}
impl $wrapper_name {
#[doc = concat!("Consumes wrapper and delegates to inner `", stringify!($method), "` method.")]
#[doc = ""]
#[doc = "Uses hybrid strategy: unwraps Arc if single reference (zero-cost),"]
#[doc = "or clones if multiple references (requires T: Clone)."]
pub fn $method(self, $($param_name: $param_ty),*) -> $ret {
let inner = ::std::sync::Arc::try_unwrap(self.0)
.unwrap_or_else(|arc| (*arc).clone());
inner.$method($($param_name),*)
}
}
$crate::__elicit_tool_wrapper! {
$wrapper_name,
consuming fn $method($($param_name: $param_ty),*) -> $ret
}
}
};
(
$wrapper_name:ident,
fn $method:ident($($param_name:ident: $param_ty:ty),*) -> $ret:ty
) => {
$crate::paste::paste! {
$crate::__elicit_param_struct! {
[<$method:camel Params>],
$($param_name: $param_ty),*
}
impl $wrapper_name {
#[doc = concat!("Delegates to inner `", stringify!($method), "` method.")]
pub fn $method(&self, $($param_name: $param_ty),*) -> $ret {
self.0.$method($($param_name),*)
}
}
$crate::__elicit_tool_wrapper! {
$wrapper_name,
fn $method($($param_name: $param_ty),*) -> $ret
}
}
};
(
$wrapper_name:ident,
consuming async fn $method:ident($($param_name:ident: $param_ty:ty),*) -> Self
) => {
$crate::paste::paste! {
$crate::__elicit_param_struct! {
[<$method:camel Params>],
$($param_name: $param_ty),*
}
impl $wrapper_name {
#[doc = concat!("Consumes wrapper and delegates to inner async `", stringify!($method), "` method.")]
#[doc = ""]
#[doc = "Uses hybrid strategy: unwraps Arc if single reference (zero-cost),"]
#[doc = "or clones if multiple references (requires T: Clone)."]
#[doc = ""]
#[doc = "Returns wrapped result for builder pattern chaining."]
pub async fn $method(self, $($param_name: $param_ty),*) -> Self {
let inner = ::std::sync::Arc::try_unwrap(self.0)
.unwrap_or_else(|arc| (*arc).clone());
let result = inner.$method($($param_name),*).await;
Self::from(result) }
}
$crate::__elicit_tool_wrapper! {
$wrapper_name,
consuming async fn $method($($param_name: $param_ty),*) -> Self
}
}
};
(
$wrapper_name:ident,
consuming async fn $method:ident($($param_name:ident: $param_ty:ty),*) -> $ret:ty
) => {
$crate::paste::paste! {
$crate::__elicit_param_struct! {
[<$method:camel Params>],
$($param_name: $param_ty),*
}
impl $wrapper_name {
#[doc = concat!("Consumes wrapper and delegates to inner async `", stringify!($method), "` method.")]
#[doc = ""]
#[doc = "Uses hybrid strategy: unwraps Arc if single reference (zero-cost),"]
#[doc = "or clones if multiple references (requires T: Clone)."]
pub async fn $method(self, $($param_name: $param_ty),*) -> $ret {
let inner = ::std::sync::Arc::try_unwrap(self.0)
.unwrap_or_else(|arc| (*arc).clone());
inner.$method($($param_name),*).await
}
}
$crate::__elicit_tool_wrapper! {
$wrapper_name,
consuming async fn $method($($param_name: $param_ty),*) -> $ret
}
}
};
(
$wrapper_name:ident,
async fn $method:ident($($param_name:ident: $param_ty:ty),*) -> $ret:ty
) => {
$crate::paste::paste! {
$crate::__elicit_param_struct! {
[<$method:camel Params>],
$($param_name: $param_ty),*
}
impl $wrapper_name {
#[doc = concat!("Delegates to inner async `", stringify!($method), "` method.")]
pub async fn $method(&self, $($param_name: $param_ty),*) -> $ret {
self.0.$method($($param_name),*).await
}
}
$crate::__elicit_tool_wrapper! {
$wrapper_name,
async fn $method($($param_name: $param_ty),*) -> $ret
}
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __elicit_param_struct {
($struct_name:ident,) => {};
($struct_name:ident, $($param_name:ident: $param_ty:ty),+) => {
#[derive(
::std::fmt::Debug,
::std::clone::Clone,
$crate::Elicit,
::schemars::JsonSchema,
::serde::Serialize,
::serde::Deserialize,
)]
pub struct $struct_name {
$(pub $param_name: $crate::__convert_param_type!($param_ty)),+
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __convert_param_type {
(&str) => { String };
(&[$inner:ty]) => { Vec<$inner> };
(&$inner:ty) => { $inner };
($ty:ty) => { $ty };
}
#[macro_export]
#[doc(hidden)]
macro_rules! __elicit_tool_wrapper {
(
$wrapper_name:ident,
consuming fn $method:ident() -> Self
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (consuming).")]
pub fn [<$method _tool>](self) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$wrapper_name>,
$crate::rmcp::ErrorData
> {
let result = self.$method();
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
consuming fn $method:ident($($param_name:ident: $param_ty:ty),+) -> Self
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (consuming).")]
pub fn [<$method _tool>](
self,
params: $crate::rmcp::handler::server::wrapper::Parameters<[<$method:camel Params>]>,
) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$wrapper_name>,
$crate::rmcp::ErrorData
> {
let result = self.$method($($crate::__convert_param_access!(params, $param_name, $param_ty)),+);
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
consuming fn $method:ident() -> $ret:ty
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (consuming).")]
pub fn [<$method _tool>](self) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$ret>,
$crate::rmcp::ErrorData
> {
let result = self.$method();
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
consuming fn $method:ident($($param_name:ident: $param_ty:ty),+) -> $ret:ty
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (consuming).")]
pub fn [<$method _tool>](
self,
params: $crate::rmcp::handler::server::wrapper::Parameters<[<$method:camel Params>]>,
) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$ret>,
$crate::rmcp::ErrorData
> {
let result = self.$method($($crate::__convert_param_access!(params, $param_name, $param_ty)),+);
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
consuming async fn $method:ident() -> Self
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (consuming, async).")]
pub async fn [<$method _tool>](self) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$wrapper_name>,
$crate::rmcp::ErrorData
> {
let result = self.$method().await;
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
consuming async fn $method:ident($($param_name:ident: $param_ty:ty),+) -> Self
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (consuming, async).")]
pub async fn [<$method _tool>](
self,
params: $crate::rmcp::handler::server::wrapper::Parameters<[<$method:camel Params>]>,
) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$wrapper_name>,
$crate::rmcp::ErrorData
> {
let result = self.$method($($crate::__convert_param_access!(params, $param_name, $param_ty)),+).await;
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
consuming async fn $method:ident() -> $ret:ty
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (consuming, async).")]
pub async fn [<$method _tool>](self) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$ret>,
$crate::rmcp::ErrorData
> {
let result = self.$method().await;
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
consuming async fn $method:ident($($param_name:ident: $param_ty:ty),+) -> $ret:ty
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (consuming, async).")]
pub async fn [<$method _tool>](
self,
params: $crate::rmcp::handler::server::wrapper::Parameters<[<$method:camel Params>]>,
) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$ret>,
$crate::rmcp::ErrorData
> {
let result = self.$method($($crate::__convert_param_access!(params, $param_name, $param_ty)),+).await;
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
fn $method:ident() -> $ret:ty
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper.")]
pub fn [<$method _tool>](&self) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$ret>,
$crate::rmcp::ErrorData
> {
let result = self.$method();
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
fn $method:ident($($param_name:ident: $param_ty:ty),+) -> $ret:ty
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper.")]
pub fn [<$method _tool>](
&self,
params: $crate::rmcp::handler::server::wrapper::Parameters<[<$method:camel Params>]>,
) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$ret>,
$crate::rmcp::ErrorData
> {
let result = self.$method($($crate::__convert_param_access!(params, $param_name, $param_ty)),+);
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
async fn $method:ident() -> $ret:ty
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (async).")]
pub async fn [<$method _tool>](&self) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$ret>,
$crate::rmcp::ErrorData
> {
let result = self.$method().await;
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
(
$wrapper_name:ident,
async fn $method:ident($($param_name:ident: $param_ty:ty),+) -> $ret:ty
) => {
$crate::paste::paste! {
impl $wrapper_name {
#[doc = concat!("`", stringify!($method), "` MCP tool wrapper (async).")]
pub async fn [<$method _tool>](
&self,
params: $crate::rmcp::handler::server::wrapper::Parameters<[<$method:camel Params>]>,
) -> ::std::result::Result<
$crate::rmcp::handler::server::wrapper::Json<$ret>,
$crate::rmcp::ErrorData
> {
let result = self.$method($($crate::__convert_param_access!(params, $param_name, $param_ty)),+).await;
Ok($crate::rmcp::handler::server::wrapper::Json(result))
}
}
}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! __convert_param_access {
($params:ident, $field:ident, &str) => {
$params.0.$field.as_str()
};
($params:ident, $field:ident, &[$inner:ty]) => {
&$params.0.$field
};
($params:ident, $field:ident, &$inner:ty) => {
&$params.0.$field
};
($params:ident, $field:ident, $ty:ty) => {
$params.0.$field
};
}