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
//! Bidirectional session and cancellation abstractions.
//!
//! The [`McpSession`] trait represents an open transport channel capable of
//! issuing server-to-client JSON-RPC requests and notifications. It is the
//! minimal plumbing that makes sampling (`sampling/createMessage`) and
//! elicitation (`elicitation/create`) reachable from request handlers.
//!
//! Keeping the trait here (rather than in `turbomcp-server`) lets
//! [`crate::context::RequestContext`] expose `sample()` / `elicit_*()` /
//! `notify_client()` directly, so `#[tool]` / `#[resource]` / `#[prompt]`
//! bodies — which receive `&RequestContext` — can use them.
//!
//! The traits use `Pin<Box<dyn Future>>` returns instead of `async fn` so they
//! stay object-safe and free of the `async-trait` macro (which would drag a
//! tokio dependency into `no_std` builds).
use Box;
use Debug;
use Future;
use Pin;
use Value;
use crateMcpResult;
use crate;
/// Future returned by [`McpSession`] methods.
///
/// Boxed so the trait stays object-safe (`Arc<dyn McpSession>` is the intended
/// storage shape). On native targets the future must be `Send`; WASM drops
/// the `Send` bound. (Can't write `+ MaybeSend` on a `dyn` — `MaybeSend` isn't
/// an auto trait — so we branch the type alias.)
pub type SessionFuture<'a, T> = ;
/// Future returned by [`McpSession`] methods (WASM variant, no `Send` bound).
pub type SessionFuture<'a, T> = ;
/// Bidirectional session handle.
///
/// Implementations are provided by the server transports (STDIO, HTTP, WS,
/// TCP, Unix, channel). Handlers obtain an `Arc<dyn McpSession>` via
/// [`crate::context::RequestContext::session`] — populated by the server
/// dispatcher before a request is routed.
///
/// # Example
///
/// ```rust,ignore
/// // Inside a #[tool] body:
/// async fn ask(&self, ctx: &RequestContext) -> McpResult<String> {
/// let approval = ctx.elicit_form("Allow write?", schema).await?;
/// // ...
/// }
/// ```
/// Cooperative-cancellation handle.
///
/// Keeps the context layer free of any specific cancellation crate.
/// When the `std` feature is enabled, `tokio_util::sync::CancellationToken`
/// gets a blanket `impl Cancellable` (see below), which is how the server
/// wires tokio-based cancellation into the unified [`crate::RequestContext`].