use super::types::Tool;
use crate::mcp::{Cursor, GenericMeta, IntoMcpRequest, MessageContent, PaginationParams, ProgressToken, RequestMeta};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::skip_serializing_none;
use std::collections::HashMap;
#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct ListToolsParams {
#[serde(rename = "_meta")]
pub meta: Option<RequestMeta>,
#[serde(flatten)]
pub pagination: PaginationParams,
}
impl ListToolsParams {
pub fn new() -> Self {
Self::default()
}
pub fn with_meta(mut self, meta: RequestMeta) -> Self {
self.meta = Some(meta);
self
}
pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
self.pagination = pagination;
self
}
pub fn with_cursor(mut self, cursor: impl Into<Cursor>) -> Self {
self.pagination.cursor = Some(cursor.into());
self
}
}
impl IntoMcpRequest<ListToolsParams> for ListToolsParams {
const METHOD: &'static str = "tools/list";
type McpResult = ListToolsResult;
}
#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ListToolsResult {
#[serde(rename = "_meta")]
pub meta: Option<GenericMeta>,
pub next_cursor: Option<Cursor>,
pub tools: Vec<Tool>,
}
#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CallToolParams {
#[serde(rename = "_meta")]
pub meta: Option<RequestMeta>,
pub name: String,
pub arguments: Option<HashMap<String, Value>>,
}
impl CallToolParams {
pub fn new(name: impl Into<String>) -> Self {
Self {
meta: None,
name: name.into(),
arguments: None,
}
}
pub fn with_meta(mut self, meta: RequestMeta) -> Self {
self.meta = Some(meta);
self
}
pub fn with_progress_token(mut self, progress_token: impl Into<ProgressToken>) -> Self {
self.meta.get_or_insert_with(RequestMeta::default).progress_token = Some(progress_token.into());
self
}
pub fn with_arguments(mut self, arguments: HashMap<String, Value>) -> Self {
self.arguments = Some(arguments);
self
}
pub fn append_argument(mut self, name: impl Into<String>, value: impl Into<Value>) -> Self {
self.arguments
.get_or_insert_with(HashMap::new)
.insert(name.into(), value.into());
self
}
}
impl IntoMcpRequest<CallToolParams> for CallToolParams {
const METHOD: &'static str = "tools/call";
type McpResult = CallToolResult;
}
#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CallToolResult {
#[serde(rename = "_meta")]
pub meta: Option<GenericMeta>,
pub content: Vec<MessageContent>,
pub is_error: Option<bool>,
}