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
//! Example: MCP Server — stdio (pipe) transport.
//!
//! Shows how to expose langchainrust's built-in tools as a **local-pipe** MCP server via
//! [`MCPServer::serve_stdio`]: read JSON-RPC requests from stdin, process them, write the
//! results back to stdout — never touching the network. Clients (MCPClient / Claude Desktop /
//! Cursor, etc.) start this binary with `MCPConfig::stdio(command, args)` and talk to it
//! over the pipe.
//!
//! # Build
//!
//! ```powershell
//! cargo build --release -p langchainrust --example mcp_stdio_server
//! # Artifact: target/release/examples/mcp_stdio_server.exe
//! ```
//!
//! # Manual verification (write one JSON-RPC line to stdin)
//!
//! ```powershell
//! echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05"}}' | .\target\release\examples\mcp_stdio_server.exe
//! # it replies with an initialize response (capabilities/serverInfo)
//! ```
//!
//! # Client integration (framework, over the pipe)
//!
//! ```no_run
//! use langchainrust::mcp::{MCPClient, MCPConfig};
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let client = MCPClient::connect(MCPConfig::stdio(
//! "target/release/examples/mcp_stdio_server".into(),
//! Vec::new(),
//! ))
//! .await?;
//! let tools = client.list_tools().await?;
//! println!("connected over the pipe, {} tools", tools.len());
//! # Ok(())
//! # }
//! ```
use MCPServer;
use ;
use Arc;
/// Registers a set of ready-to-use built-in tools (the same set as `mcp_sse_server`).
async