Skip to main content

chuk_mcp/
lib.rs

1//! # chuk-mcp
2//!
3//! A Model Context Protocol (MCP) client and server library — the Rust port of
4//! the Python [`chuk-mcp`](https://github.com/chrishayuk/chuk-mcp) package.
5//!
6//! Layers mirror the Python package:
7//! - [`protocol`] — JSON-RPC messages, MCP types, versioning, feature message APIs
8//! - [`transports`] — stdio, Streamable HTTP, and (legacy) SSE transports
9//! - [`client`] — high-level [`client::McpClient`]
10//! - [`server`] — high-level [`server::McpServer`] and protocol handler
11//!
12//! ## Quick start
13//!
14//! [`connect`] takes a URL or a command line, picks the transport, detects the
15//! protocol era and completes its handshake:
16//!
17//! ```no_run
18//! # async fn run() -> Result<(), chuk_mcp::McpError> {
19//! let client = chuk_mcp::connect("https://example.com/mcp").await?;
20//! let tools = client.list_tools().await?;
21//! # Ok(())
22//! # }
23//! ```
24//!
25//! With options, or to say exactly which transport you want:
26//!
27//! ```no_run
28//! use chuk_mcp::Connect;
29//! # async fn run() -> Result<(), chuk_mcp::McpError> {
30//! let client = Connect::to_command("python", ["server.py"])
31//!     .timeout(std::time::Duration::from_secs(10))
32//!     .connect()
33//!     .await?;
34//! # Ok(())
35//! # }
36//! ```
37
38/// OAuth 2.1 authorization for HTTP transports.
39///
40/// Behind the default-on `auth` feature.
41#[cfg(feature = "auth")]
42pub mod auth;
43pub mod client;
44pub mod connect;
45pub mod protocol;
46pub mod server;
47pub mod transports;
48
49pub use client::McpClient;
50// Re-exported for compatibility; `connect` supersedes it.
51#[allow(deprecated)]
52pub use client::connect_to_server;
53pub use connect::{connect, Connect, Target};
54pub use protocol::envelope::{build_envelope, ClientIdentity, Envelope};
55pub use protocol::era::{
56    renegotiate, Detection, EndpointKey, EraCache, EraMode, ProtocolEra, ServerProfile,
57};
58pub use protocol::header_params::HeaderParam;
59pub use protocol::json_rpc::JsonRpcMessage;
60pub use protocol::meta::RequestMeta;
61pub use protocol::types::capabilities::{ClientCapabilities, ServerCapabilities};
62pub use protocol::types::errors::McpError;
63pub use protocol::types::info::{ClientInfo, ServerInfo};
64pub use server::McpServer;
65pub use transports::stdio::StdioParameters;
66
67/// The names most programs need, in one import.
68///
69/// ```no_run
70/// use chuk_mcp::prelude::*;
71///
72/// # async fn run() -> Result<(), McpError> {
73/// let client = connect("https://example.com/mcp").await?;
74/// let result = client.call_tool("greet", json!({"name": "World"})).await?;
75/// println!("{}", result.text());
76/// # Ok(()) }
77/// ```
78///
79/// Everything here is also available from the crate root; the prelude exists so
80/// a first program needs one `use` line rather than six.
81pub mod prelude {
82    pub use crate::client::McpClient;
83    pub use crate::connect::{connect, Connect};
84    pub use crate::protocol::era::{EraMode, ProtocolEra};
85    pub use crate::protocol::messages::prompts::{GetPromptResult, Prompt};
86    pub use crate::protocol::messages::resources::{ReadResourceResult, Resource};
87    pub use crate::protocol::messages::tools::{Tool, ToolResult};
88    pub use crate::protocol::types::capabilities::{ClientCapabilities, ServerCapabilities};
89    pub use crate::protocol::types::errors::McpError;
90    pub use crate::protocol::types::info::{ClientInfo, ServerInfo};
91    pub use crate::server::McpServer;
92    pub use crate::transports::stdio::StdioParameters;
93    pub use serde_json::{json, Value};
94}