Skip to main content

model_context_protocol/client/
mod.rs

1//! MCP Client transports for connecting to external MCP servers.
2//!
3//! This module provides client-side transports that implement the `McpTransport`
4//! trait for connecting to and communicating with external MCP servers.
5//!
6//! # Architecture
7//!
8//! ```text
9//! ┌─────────────────────────────────────────────────────────────────┐
10//! │                      Your Application                           │
11//! │                                                                 │
12//! │  ┌───────────────────────────────────────────────────────────┐ │
13//! │  │                        McpHub                              │ │
14//! │  │              (manages multiple connections)                │ │
15//! │  │                                                            │ │
16//! │  │   ┌─────────────────┐       ┌─────────────────────────┐   │ │
17//! │  │   │ StdioTransport  │       │    HttpTransport        │   │ │
18//! │  │   │ (spawn process) │       │   (HTTP POST)           │   │ │
19//! │  │   └─────────────────┘       └─────────────────────────┘   │ │
20//! │  └───────────────────────────────────────────────────────────┘ │
21//! │                            │                                    │
22//! └────────────────────────────┼────────────────────────────────────┘
23//!                              │
24//!                              ▼
25//!              ┌───────────────────────────────┐
26//!              │     External MCP Servers      │
27//!              │  (Node.js, Python, etc.)      │
28//!              └───────────────────────────────┘
29//! ```
30//!
31//! # Example
32//!
33//! ```ignore
34//! use mcp::client::StdioTransportAdapter;
35//! use mcp::transport::McpTransport;
36//!
37//! // Connect to an MCP server process
38//! let transport = StdioTransportAdapter::connect(
39//!     "node",
40//!     &["mcp-server.js".to_string()],
41//!     None,
42//!     Duration::from_secs(30),
43//! ).await?;
44//!
45//! // List available tools
46//! let tools = transport.list_tools().await?;
47//!
48//! // Call a tool
49//! let result = transport.call_tool("my_tool", json!({"arg": "value"})).await?;
50//! ```
51
52pub mod http;
53pub mod stdio;
54
55// Re-exports
56pub use stdio::{AsyncStdioTransport, StdioTransportAdapter, TokioStdioTransport};
57
58pub use http::{HttpTransport, HttpTransportAdapter};