rust_mcp_sdk/
lib.rs

1pub mod error;
2#[cfg(feature = "hyper-server")]
3mod hyper_servers;
4mod mcp_handlers;
5#[cfg(feature = "hyper-server")]
6pub(crate) mod mcp_http;
7mod mcp_macros;
8mod mcp_runtimes;
9mod mcp_traits;
10#[cfg(any(feature = "server", feature = "hyper-server"))]
11pub mod session_store;
12mod utils;
13
14#[cfg(feature = "client")]
15pub mod mcp_client {
16    //! Includes the runtimes and traits required to create a type-safe MCP client.
17    //!
18    //!
19    //! **Choosing Between `client_runtime` and `client_runtime_core` ?**
20    //!
21    //! [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of runtimes that you can chose from:
22    //! - **client_runtime** : This is recommended runtime to be used for most MCP projects, and
23    //!   it works with `mcp_server_handler` trait
24    //!   that offers default implementation for common messages like  handling initialization or
25    //!   responding to ping requests, so you only need to override and customize the handler
26    //!   functions relevant to your specific needs.
27    //!
28    //! Refer to [examples/simple-mcp-client-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-stdio) for an example.
29    //!
30    //!
31    //! - **client_runtime_core**: If you need more control over MCP messages, consider using
32    //!   `client_runtime_core` that goes with works with `mcp_server_handler_core` trait which offers
33    //!   methods to manage the three MCP message types: request, notification, and error.
34    //!   While still providing type-safe objects in these methods, it allows you to determine how to
35    //!   handle each message based on its type and parameters.
36    //!
37    //! Refer to [examples/simple-mcp-client-stdio-core](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-stdio-core) for an example.
38    pub use super::mcp_handlers::mcp_client_handler::ClientHandler;
39    pub use super::mcp_handlers::mcp_client_handler_core::ClientHandlerCore;
40    pub use super::mcp_runtimes::client_runtime::mcp_client_runtime as client_runtime;
41    pub use super::mcp_runtimes::client_runtime::mcp_client_runtime_core as client_runtime_core;
42    pub use super::mcp_runtimes::client_runtime::ClientRuntime;
43    pub use super::utils::ensure_server_protocole_compatibility;
44}
45
46#[cfg(feature = "server")]
47pub mod mcp_server {
48    //! Includes the runtimes and traits required to create a type-safe MCP server.
49    //!
50    //!
51    //! **Choosing Between `server_runtime` and `server_runtime_core` ?**
52    //!
53    //! [rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of runtimes that you can chose from:
54    //! - **server_runtime** : This is recommended runtime to be used for most MCP projects, and
55    //!   it works with `mcp_server_handler` trait
56    //!   that offers default implementation for common messages like  handling initialization or
57    //!   responding to ping requests, so you only need to override and customize the handler
58    //!   functions relevant to your specific needs.
59    //!
60    //! Refer to [examples/hello-world-mcp-server-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio) for an example.
61    //!
62    //!
63    //! - **server_runtime_core**: If you need more control over MCP messages, consider using
64    //!   `server_runtime_core` that goes with works with `mcp_server_handler_core` trait which offers
65    //!   methods to manage the three MCP message types: request, notification, and error.
66    //!   While still providing type-safe objects in these methods, it allows you to determine how to
67    //!   handle each message based on its type and parameters.
68    //!
69    //! Refer to [examples/hello-world-mcp-server-stdio-core](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio-core) for an example.
70    pub use super::mcp_handlers::mcp_server_handler::{ServerHandler, ToMcpServerHandler};
71    pub use super::mcp_handlers::mcp_server_handler_core::ServerHandlerCore;
72
73    pub use super::mcp_runtimes::server_runtime::mcp_server_runtime as server_runtime;
74    pub use super::mcp_runtimes::server_runtime::mcp_server_runtime_core as server_runtime_core;
75    pub use super::mcp_runtimes::server_runtime::ServerRuntime;
76
77    #[cfg(feature = "hyper-server")]
78    pub use super::hyper_servers::hyper_server;
79    #[cfg(feature = "hyper-server")]
80    pub use super::hyper_servers::hyper_server_core;
81    #[cfg(feature = "hyper-server")]
82    pub use super::hyper_servers::*;
83    pub use super::utils::enforce_compatible_protocol_version;
84
85    #[cfg(feature = "hyper-server")]
86    pub use super::mcp_http::{McpAppState, McpHttpHandler};
87}
88
89#[cfg(feature = "client")]
90pub use mcp_traits::mcp_client::*;
91
92#[cfg(feature = "server")]
93pub use mcp_traits::mcp_server::*;
94
95pub use rust_mcp_transport::error::*;
96pub use rust_mcp_transport::*;
97
98#[cfg(feature = "macros")]
99pub mod macros {
100    pub use rust_mcp_macros::*;
101}
102
103pub mod id_generator;
104pub mod schema;