turbomcp_transport_streamable/lib.rs
1//! # TurboMCP Streamable HTTP Transport
2//!
3//! This crate provides core types for the MCP 2025-11-25 Streamable HTTP transport specification.
4//! It is designed to be portable across native and WASM environments.
5//!
6//! ## Features
7//!
8//! - **Session Management**: `SessionId`, `Session`, `SessionStore` trait for stateful connections
9//! - **SSE Encoding/Decoding**: Pure, no-I/O Server-Sent Events implementation
10//! - **Protocol Types**: Request/response types for streamable HTTP endpoints
11//!
12//! ## Usage
13//!
14//! ```rust,ignore
15//! use turbomcp_transport_streamable::{SessionId, SessionStore, SseEvent, SseEncoder};
16//!
17//! // Create a new session
18//! let session_id = SessionId::new();
19//!
20//! // Encode an SSE event
21//! let event = SseEvent::message("Hello, world!");
22//! let encoded = SseEncoder::encode(&event);
23//! ```
24//!
25//! ## no_std Support
26//!
27//! This crate supports `no_std` environments with the `alloc` feature:
28//!
29//! ```toml
30//! [dependencies]
31//! turbomcp-transport-streamable = { version = "3.0", default-features = false, features = ["alloc"] }
32//! ```
33
34#![cfg_attr(not(feature = "std"), no_std)]
35
36#[cfg(not(feature = "std"))]
37extern crate alloc;
38
39pub mod config;
40mod marker;
41pub mod session;
42pub mod sse;
43pub mod types;
44
45// Re-export main types
46pub use config::StreamableConfig;
47pub use session::{Session, SessionId, SessionState, SessionStore, StoredEvent};
48pub use sse::{SseEncoder, SseEvent, SseEventBuilder, SseParser};
49pub use types::{
50 HttpMethod, OriginValidation, StreamableError, StreamableRequest, StreamableResponse,
51};
52
53/// MCP 2025-11-25 Streamable HTTP header names
54pub mod headers {
55 /// Session ID header for tracking stateful connections
56 pub const MCP_SESSION_ID: &str = "Mcp-Session-Id";
57
58 /// Last event ID header for SSE resumption
59 pub const LAST_EVENT_ID: &str = "Last-Event-ID";
60
61 /// Content-Type for JSON responses
62 pub const CONTENT_TYPE_JSON: &str = "application/json";
63
64 /// Content-Type for SSE streams
65 pub const CONTENT_TYPE_SSE: &str = "text/event-stream";
66
67 /// Accept header value for SSE
68 pub const ACCEPT_SSE: &str = "text/event-stream";
69}