-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathproxy.rs
More file actions
51 lines (45 loc) · 1.47 KB
/
proxy.rs
File metadata and controls
51 lines (45 loc) · 1.47 KB
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
//! Proxy component that provides MCP tools
use agent_client_protocol::mcp_server::McpServer;
use agent_client_protocol::{Conductor, ConnectTo, Proxy};
use agent_client_protocol_rmcp::McpServerExt as _;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// Parameters for the echo tool
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
struct EchoParams {
/// The message to echo back
message: String,
}
/// Output from the echo tool
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
struct EchoOutput {
/// The echoed message
result: String,
}
pub struct ProxyComponent;
impl ConnectTo<Conductor> for ProxyComponent {
async fn connect_to(
self,
client: impl ConnectTo<Proxy>,
) -> Result<(), agent_client_protocol::Error> {
let test_server = McpServer::builder("test")
.instructions("A simple test MCP server with an echo tool")
.tool_fn_mut(
"echo",
"Echoes back the input message",
async |params: EchoParams, _context| {
Ok(EchoOutput {
result: format!("Echo: {}", params.message),
})
},
agent_client_protocol::tool_fn_mut!(),
)
.build();
agent_client_protocol::Proxy
.builder()
.name("proxy-component")
.with_mcp_server(test_server)
.connect_to(client)
.await
}
}