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
//! 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. External clients (Claude Desktop /
//! Cursor, etc.) start this binary over the pipe and talk JSON-RPC line framing.
//!
//! # 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)
//! ```
//!
//! # In-framework access
//!
//! The 0.22.0 stateless track has no in-framework stdio client — in-framework
//! integration goes through the HTTP track: run `mcp_http_server` and connect
//! with `StatelessMcpClient::connect("http://127.0.0.1:8788/mcp")`.
//!
//! ```no_run
//! use langchainrust::mcp::StatelessMcpClient;
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let client = StatelessMcpClient::connect("http://127.0.0.1:8788/mcp");
//! let tools = client.list_tools().await?;
//! println!("{} tools", tools.len());
//! # Ok(())
//! # }
//! ```
use MCPServer;
use ;
use Arc;
/// Registers a set of ready-to-use built-in tools (the same set as `mcp_http_server`).
async