Skip to content

Commit 9da3f84

Browse files
committed
fix: update other examples, comments and readme to take ownership of command
Updated more examples, comments and readme to take command instead of mutable ref. Also small fix in cargo toml of example to use local path.
1 parent dedf204 commit 9da3f84

File tree

7 files changed

+21
-31
lines changed

7 files changed

+21
-31
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "mai
2222

2323
### Quick start
2424

25-
Start a client in one line:
25+
Start a client:
2626

2727
```rust, ignore
2828
use rmcp::{ServiceExt, transport::TokioChildProcess};
2929
use tokio::process::Command;
3030
3131
#[tokio::main]
3232
async fn main() -> Result<(), Box<dyn std::error::Error>> {
33-
let client = ().serve(
34-
TokioChildProcess::new(Command::new("npx").arg("-y").arg("@modelcontextprotocol/server-everything"))?
35-
).await?;
33+
let mut cmd = Command::new("npx");
34+
cmd.arg("-y").arg("@modelcontextprotocol/server-everything");
35+
let client = ().serve(TokioChildProcess::new(cmd)?).await?;
3636
Ok(())
3737
}
3838
```
@@ -86,7 +86,7 @@ let server = service.serve(transport).await?;
8686
Once the server is initialized, you can send requests or notifications:
8787

8888
```rust, ignore
89-
// request
89+
// request
9090
let roots = server.list_roots().await?;
9191
9292
// or send notification

crates/rmcp/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@
6060
//! use tokio::process::Command;
6161
//!
6262
//! async fn client() -> Result<()> {
63-
//! let service = ()
64-
//! .serve(TokioChildProcess::new(
65-
//! Command::new("uvx").arg("mcp-server-git"),
66-
//! )?)
67-
//! .await?;
63+
//! let mut cmd = Command::new("uvx");
64+
//! cmd.arg("mcp-server-git");
65+
//! let service = ().serve(TokioChildProcess::new(cmd)?).await?;
6866
//!
6967
//! // Initialize
7068
//! let server_info = service.peer_info();

docs/readme/README.zh-cn.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "mai
2020
use rmcp::{ServiceExt, transport::TokioChildProcess};
2121
use tokio::process::Command;
2222

23-
let client = ().serve(
24-
TokioChildProcess::new(Command::new("npx").arg("-y").arg("@modelcontextprotocol/server-everything"))?
25-
).await?;
23+
let mut cmd = Command::new("npx");
24+
cmd.arg("-y").arg("@modelcontextprotocol/server-everything");
25+
let client = ().serve(TokioChildProcess::new(cmd)?).await?;
2626
```
2727

2828
#### 1. 构建传输层
@@ -63,7 +63,7 @@ let server = service.serve(transport).await?;
6363
一旦服务初始化完成,你可以发送请求或通知:
6464

6565
```rust, ignore
66-
// 请求
66+
// 请求
6767
let roots = server.list_roots().await?;
6868
6969
// 或发送通知

examples/clients/src/std_io.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ async fn main() -> Result<()> {
1717
cmd.arg("mcp-server-git");
1818
let service = ().serve(TokioChildProcess::new(cmd)?).await?;
1919

20-
// or
21-
// serve_client(
22-
// (),
23-
// TokioChildProcess::new(Command::new("uvx").arg("mcp-server-git"))?,
24-
// )
25-
// .await?;
20+
// or serve_client((), TokioChildProcess::new(cmd)?).await?;
2621

2722
// Initialize
2823
let server_info = service.peer_info();

examples/rig-integration/src/config/mcp.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ impl McpServerTransportConfig {
7070
envs,
7171
} => {
7272
let mut cmd = tokio::process::Command::new(command);
73-
cmd.args(args);
74-
cmd.envs(envs);
75-
cmd.stderr(Stdio::null());
73+
cmd.args(args).envs(envs).stderr(Stdio::null());
7674
let transport = rmcp::transport::TokioChildProcess::new(cmd)?;
7775
().serve(transport).await?
7876
}

examples/simple-chat-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ thiserror = "1.0"
1313
async-trait = "0.1"
1414
futures = "0.3"
1515
toml = "0.8"
16-
rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", features = [
16+
rmcp = { path = "../../crates/rmcp", features = [
1717
"client",
1818
"transport-child-process",
1919
"transport-sse",

examples/simple-chat-client/src/config.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ impl McpServerTransportConfig {
5252
args,
5353
envs,
5454
} => {
55-
let transport = rmcp::transport::child_process::TokioChildProcess::new(
56-
tokio::process::Command::new(command)
57-
.args(args)
58-
.envs(envs)
59-
.stderr(Stdio::inherit())
60-
.stdout(Stdio::inherit()),
61-
)?;
55+
let mut cmd = tokio::process::Command::new(command);
56+
cmd.args(args)
57+
.envs(envs)
58+
.stderr(Stdio::inherit())
59+
.stdout(Stdio::inherit());
60+
let transport = rmcp::transport::child_process::TokioChildProcess::new(cmd)?;
6261
().serve(transport).await?
6362
}
6463
};

0 commit comments

Comments
 (0)