prism_mcp_rs/client/
fluent_tools.rs1use crate::core::enhanced_errors::{McpError, McpResult};
4use crate::protocol::{messages::ListToolsResult, types::CallToolResult};
5use serde_json::Value;
6use std::collections::HashMap;
7
8pub struct ToolsBuilder<'a> {
10 client: &'a crate::client::McpClient,
11 tool_name: Option<String>,
12 arguments: HashMap<String, Value>,
13}
14
15impl<'a> ToolsBuilder<'a> {
16 pub(crate) fn new(client: &'a crate::client::McpClient) -> Self {
17 Self {
18 client,
19 tool_name: None,
20 arguments: HashMap::new(),
21 }
22 }
23
24 pub fn call(mut self, name: impl Into<String>) -> Self {
26 self.tool_name = Some(name.into());
27 self
28 }
29
30 pub fn args(mut self, args: impl Into<Value>) -> Self {
32 if let Value::Object(map) = args.into() {
33 for (k, v) in map {
34 self.arguments.insert(k, v);
35 }
36 }
37 self
38 }
39
40 pub fn arg(mut self, key: impl Into<String>, value: impl Into<Value>) -> Self {
42 self.arguments.insert(key.into(), value.into());
43 self
44 }
45
46 pub async fn execute(self) -> McpResult<CallToolResult> {
48 let tool_name = self
49 .tool_name
50 .ok_or_else(|| McpError::validation("Tool name is required"))?;
51
52 self.client
53 .call_tool(
54 tool_name,
55 if self.arguments.is_empty() {
56 None
57 } else {
58 Some(self.arguments)
59 },
60 )
61 .await
62 .map_err(|e| McpError::internal(e.to_string()))
63 }
64
65 pub async fn list(self) -> McpResult<ListToolsResult> {
67 self.client
68 .list_tools(None)
69 .await
70 .map_err(|e| McpError::internal(e.to_string()))
71 }
72}