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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
pub use ;
pub use ;
pub use McpHttpClientBuilder;
pub use ;
pub use ;
pub use ResourceNotificationHandler;
pub use ;
pub use ;
/// The official Rust MCP SDK version used by ADK-Rust.
///
/// Re-exporting it keeps advanced transports, server authoring, extension
/// metadata, and protocol types on the same major version as [`McpToolset`].
pub use rmcp;
// Re-export commonly used catalog types from rmcp for public API consumers.
pub use ;
/// Selects how the client establishes its MCP lifecycle, and the trait that
/// applies the selection.
///
/// The default connection path uses [`ClientLifecycleMode::Initialize`], the
/// handshake every MCP server has understood since `2024-11-05`. Build a client
/// with [`ClientServiceExt::serve_with_lifecycle`] to choose a different one,
/// then hand it to [`McpToolset::new`].
///
/// | Mode | Sends first | On a server that predates `2026-07-28` |
/// |------|-------------|----------------------------------------|
/// | `Initialize` (default) | `initialize` | Works |
/// | `Auto` | `server/discover` | Falls back **only** when the server answers `METHOD_NOT_FOUND` |
/// | `Discover` | `server/discover` | Fails — there is no fallback |
///
/// # Choosing a mode
///
/// Prefer the default. A `2026-07-28` server still answers `initialize`, so the
/// default already reaches both generations of server.
///
/// `Auto` buys the stateless per-request path against new servers, at a cost:
/// a server that answers an unknown method with anything other than
/// `METHOD_NOT_FOUND` — `INVALID_REQUEST`, an internal error, or a closed
/// connection — fails the connection outright. rmcp also applies no timeout to
/// the probe, so a server that ignores `server/discover` instead of refusing it
/// leaves the connection waiting.
///
/// `Discover` never falls back. Use it only for servers you control and know to
/// support `2026-07-28`.
///
/// # Example
///
/// ```no_run
/// use adk_tool::mcp::{
/// AdkClientHandler, AutoDeclineElicitationHandler, ClientLifecycleMode,
/// ClientServiceExt, McpToolset,
/// };
/// use rmcp::model::ProtocolVersion;
/// use rmcp::transport::TokioChildProcess;
/// use std::sync::Arc;
/// use tokio::process::Command;
///
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let transport = TokioChildProcess::new(Command::new("my-mcp-server"))?;
/// let client = AdkClientHandler::new(Arc::new(AutoDeclineElicitationHandler))
/// .serve_with_lifecycle(
/// transport,
/// ClientLifecycleMode::Auto {
/// preferred_versions: vec![ProtocolVersion::V_2026_07_28],
/// legacy_version: Some(ProtocolVersion::V_2025_11_25),
/// },
/// )
/// .await?;
/// let toolset = McpToolset::new(client);
/// # Ok(())
/// # }
/// ```
pub use ;