Skip to content

Commit 6c2c024

Browse files
authored
chore: disable unix_socket example on windows (#146)
1 parent 18346b9 commit 6c2c024

File tree

1 file changed

+62
-57
lines changed

1 file changed

+62
-57
lines changed

examples/transport/src/unix_socket.rs

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,66 @@
1-
use std::fs;
2-
3-
use common::calculator::Calculator;
4-
use rmcp::{serve_client, serve_server};
5-
use tokio::net::{UnixListener, UnixStream};
6-
71
mod common;
82

9-
const SOCKET_PATH: &str = "/tmp/rmcp_example.sock";
10-
3+
#[cfg(target_family = "unix")]
114
#[tokio::main]
125
async fn main() -> anyhow::Result<()> {
6+
use std::fs;
7+
8+
use common::calculator::Calculator;
9+
use rmcp::{serve_client, serve_server};
10+
use tokio::net::{UnixListener, UnixStream};
11+
12+
const SOCKET_PATH: &str = "/tmp/rmcp_example.sock";
13+
async fn server(unix_listener: UnixListener) -> anyhow::Result<()> {
14+
while let Ok((stream, addr)) = unix_listener.accept().await {
15+
println!("Client connected: {:?}", addr);
16+
tokio::spawn(async move {
17+
match serve_server(Calculator, stream).await {
18+
Ok(server) => {
19+
println!("Server initialized successfully");
20+
if let Err(e) = server.waiting().await {
21+
println!("Error while server waiting: {}", e);
22+
}
23+
}
24+
Err(e) => println!("Server initialization failed: {}", e),
25+
}
26+
27+
anyhow::Ok(())
28+
});
29+
}
30+
Ok(())
31+
}
32+
33+
async fn client() -> anyhow::Result<()> {
34+
println!("Client connecting to {}", SOCKET_PATH);
35+
let stream = UnixStream::connect(SOCKET_PATH).await?;
36+
37+
let client = serve_client((), stream).await?;
38+
println!("Client connected and initialized successfully");
39+
40+
// List available tools
41+
let tools = client.peer().list_tools(Default::default()).await?;
42+
println!("Available tools: {:?}", tools);
43+
44+
// Call the sum tool
45+
if let Some(sum_tool) = tools.tools.iter().find(|t| t.name.contains("sum")) {
46+
println!("Calling sum tool: {}", sum_tool.name);
47+
let result = client
48+
.peer()
49+
.call_tool(rmcp::model::CallToolRequestParam {
50+
name: sum_tool.name.clone(),
51+
arguments: Some(rmcp::object!({
52+
"a": 10,
53+
"b": 20
54+
})),
55+
})
56+
.await?;
57+
58+
println!("Result: {:?}", result);
59+
}
60+
61+
Ok(())
62+
}
63+
1364
// Remove any existing socket file
1465
let _ = fs::remove_file(SOCKET_PATH);
1566
match UnixListener::bind(SOCKET_PATH) {
@@ -30,53 +81,7 @@ async fn main() -> anyhow::Result<()> {
3081
Ok(())
3182
}
3283

33-
async fn server(unix_listener: UnixListener) -> anyhow::Result<()> {
34-
while let Ok((stream, addr)) = unix_listener.accept().await {
35-
println!("Client connected: {:?}", addr);
36-
tokio::spawn(async move {
37-
match serve_server(Calculator, stream).await {
38-
Ok(server) => {
39-
println!("Server initialized successfully");
40-
if let Err(e) = server.waiting().await {
41-
println!("Error while server waiting: {}", e);
42-
}
43-
}
44-
Err(e) => println!("Server initialization failed: {}", e),
45-
}
46-
47-
anyhow::Ok(())
48-
});
49-
}
50-
Ok(())
51-
}
52-
53-
async fn client() -> anyhow::Result<()> {
54-
println!("Client connecting to {}", SOCKET_PATH);
55-
let stream = UnixStream::connect(SOCKET_PATH).await?;
56-
57-
let client = serve_client((), stream).await?;
58-
println!("Client connected and initialized successfully");
59-
60-
// List available tools
61-
let tools = client.peer().list_tools(Default::default()).await?;
62-
println!("Available tools: {:?}", tools);
63-
64-
// Call the sum tool
65-
if let Some(sum_tool) = tools.tools.iter().find(|t| t.name.contains("sum")) {
66-
println!("Calling sum tool: {}", sum_tool.name);
67-
let result = client
68-
.peer()
69-
.call_tool(rmcp::model::CallToolRequestParam {
70-
name: sum_tool.name.clone(),
71-
arguments: Some(rmcp::object!({
72-
"a": 10,
73-
"b": 20
74-
})),
75-
})
76-
.await?;
77-
78-
println!("Result: {:?}", result);
79-
}
80-
81-
Ok(())
84+
#[cfg(not(target_family = "unix"))]
85+
fn main() {
86+
println!("Unix socket example is not supported on this platform.");
8287
}

0 commit comments

Comments
 (0)