1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! MCP tool trait for defining tools.
use JsonSchema;
use ;
use crateRole;
use McpConnectionTo;
/// Trait for defining MCP tools.
///
/// Implement this trait to create a tool that can be registered with an MCP server.
/// The tool's input and output types must implement JSON Schema for automatic
/// documentation.
///
/// # Example
///
/// ```rust,ignore
/// use agent_client_protocol::mcp_server::{McpTool, McpContext};
/// use schemars::JsonSchema;
/// use serde::{Deserialize, Serialize};
///
/// #[derive(JsonSchema, Deserialize)]
/// struct EchoInput {
/// message: String,
/// }
///
/// #[derive(JsonSchema, Serialize)]
/// struct EchoOutput {
/// echoed: String,
/// }
///
/// struct EchoTool;
///
/// impl<R: agent_client_protocol::role::Role> McpTool<R> for EchoTool {
/// type Input = EchoInput;
/// type Output = EchoOutput;
///
/// fn name(&self) -> String {
/// "echo".to_string()
/// }
///
/// fn description(&self) -> String {
/// "Echoes back the input message".to_string()
/// }
///
/// async fn call_tool(
/// &self,
/// input: EchoInput,
/// _context: McpContext<R>,
/// ) -> Result<EchoOutput, agent_client_protocol::Error> {
/// Ok(EchoOutput {
/// echoed: format!("Echo: {}", input.message),
/// })
/// }
/// }
/// ```