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
//! Transport abstraction for MCP connections.
//!
//! MCP defines more than one way to carry the same JSON-RPC conversation:
//! stdio to a child process, and HTTP to a (usually remote) server. Everything
//! above this module - [`crate::MCPClient`], discovery, execution - is written
//! against the crate-internal `Transport` trait and never learns which one it
//! is talking over.
use Arc;
use Duration;
use async_trait;
pub
pub
pub
pub use ;
/// Re-authenticates a connection whose bearer token has expired mid-session.
///
/// Implemented by the OAuth layer (which owns the token store); the HTTP
/// transport calls it when a request comes back `401`, then retries once. A
/// trait keeps the transport free of any OAuth/token-store knowledge.
/// How long to wait for a server to answer a request before giving up.
///
/// Generous, because a legitimate tool call can be genuinely slow (a build, a
/// network fetch). The point is only that "slow" can never become "forever" -
/// an unbounded read lets a silent server wedge the caller permanently.
pub const DEFAULT_REQUEST_TIMEOUT: Duration = from_secs;
/// How long to wait for the initial `initialize` handshake.
///
/// Much tighter than [`DEFAULT_REQUEST_TIMEOUT`]: a server that hasn't
/// completed its handshake in this long is misconfigured, not busy, and
/// blocking an agent's startup on it helps nobody.
pub const DEFAULT_CONNECT_TIMEOUT: Duration = from_secs;
/// A bidirectional MCP message channel.
///
/// Implementations own the framing and the connection lifecycle, and are
/// responsible for handling frames the *server* initiates (pings and the like)
/// without disturbing the request/response pairing the caller sees.
pub