Skip to content

Commit cc3e4fd

Browse files
committed
feat: add SEP-2243 HTTP standard headers
1 parent 8f5310b commit cc3e4fd

8 files changed

Lines changed: 972 additions & 7 deletions

File tree

crates/rmcp/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ server-side-http = [
139139
"dep:bytes",
140140
"dep:sse-stream",
141141
"tower",
142+
"base64",
142143
]
143144

144145
transport-worker = ["dep:tokio-stream"]
145146

146147
# SSE stream parsing utilities (used by streamable HTTP client for SSE-formatted responses)
147-
client-side-sse = ["dep:sse-stream", "dep:http"]
148+
client-side-sse = ["dep:sse-stream", "dep:http", "base64"]
148149

149150
# Streamable HTTP client
150151
transport-streamable-http-client = ["client-side-sse", "transport-worker"]

crates/rmcp/src/model.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,23 @@ impl std::fmt::Display for ProtocolVersion {
152152
}
153153

154154
impl ProtocolVersion {
155+
pub const V_2026_07_28: Self = Self(Cow::Borrowed("2026-07-28"));
155156
pub const V_2025_11_25: Self = Self(Cow::Borrowed("2025-11-25"));
156157
pub const V_2025_06_18: Self = Self(Cow::Borrowed("2025-06-18"));
157158
pub const V_2025_03_26: Self = Self(Cow::Borrowed("2025-03-26"));
158159
pub const V_2024_11_05: Self = Self(Cow::Borrowed("2024-11-05"));
159160
pub const LATEST: Self = Self::V_2025_11_25;
160161

162+
/// First protocol version that requires SEP-2243 standard HTTP headers.
163+
pub const STANDARD_HEADERS: Self = Self::V_2026_07_28;
164+
161165
/// All protocol versions known to this SDK.
162166
pub const KNOWN_VERSIONS: &[Self] = &[
163167
Self::V_2024_11_05,
164168
Self::V_2025_03_26,
165169
Self::V_2025_06_18,
166170
Self::V_2025_11_25,
171+
Self::V_2026_07_28,
167172
];
168173

169174
/// Returns the string representation of this protocol version.
@@ -193,6 +198,7 @@ impl<'de> Deserialize<'de> for ProtocolVersion {
193198
"2025-03-26" => return Ok(ProtocolVersion::V_2025_03_26),
194199
"2025-06-18" => return Ok(ProtocolVersion::V_2025_06_18),
195200
"2025-11-25" => return Ok(ProtocolVersion::V_2025_11_25),
201+
"2026-07-28" => return Ok(ProtocolVersion::V_2026_07_28),
196202
_ => {}
197203
}
198204
Ok(ProtocolVersion(Cow::Owned(s)))
@@ -500,6 +506,7 @@ pub struct JsonRpcNotification<N = Notification> {
500506
pub struct ErrorCode(pub i32);
501507

502508
impl ErrorCode {
509+
pub const HEADER_MISMATCH: Self = Self(-32001);
503510
pub const RESOURCE_NOT_FOUND: Self = Self(-32002);
504511
pub const INVALID_REQUEST: Self = Self(-32600);
505512
pub const METHOD_NOT_FOUND: Self = Self(-32601);
@@ -544,6 +551,9 @@ impl ErrorData {
544551
pub fn resource_not_found(message: impl Into<Cow<'static, str>>, data: Option<Value>) -> Self {
545552
Self::new(ErrorCode::RESOURCE_NOT_FOUND, message, data)
546553
}
554+
pub fn header_mismatch(message: impl Into<Cow<'static, str>>, data: Option<Value>) -> Self {
555+
Self::new(ErrorCode::HEADER_MISMATCH, message, data)
556+
}
547557
pub fn parse_error(message: impl Into<Cow<'static, str>>, data: Option<Value>) -> Self {
548558
Self::new(ErrorCode::PARSE_ERROR, message, data)
549559
}

crates/rmcp/src/transport/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ pub mod server_side_http;
33

44
pub mod http_header;
55

6+
#[cfg(any(feature = "client-side-sse", feature = "server-side-http"))]
7+
pub mod mcp_headers;
8+
69
#[cfg(feature = "__reqwest")]
710
mod reqwest;
811

crates/rmcp/src/transport/common/http_header.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ pub const HEADER_MCP_PROTOCOL_VERSION: &str = "MCP-Protocol-Version";
44
pub const EVENT_STREAM_MIME_TYPE: &str = "text/event-stream";
55
pub const JSON_MIME_TYPE: &str = "application/json";
66

7+
// SEP-2243 standard headers, gated on protocol version >= 2026-07-28.
8+
pub const HEADER_MCP_METHOD: &str = "Mcp-Method";
9+
pub const HEADER_MCP_NAME: &str = "Mcp-Name";
10+
pub const HEADER_MCP_PARAM_PREFIX: &str = "Mcp-Param-";
11+
12+
/// Sentinel wrapping a Base64-encoded SEP-2243 header value (`=?base64?<b64>?=`).
13+
pub const BASE64_HEADER_PREFIX: &str = "=?base64?";
14+
pub const BASE64_HEADER_SUFFIX: &str = "?=";
15+
716
/// Reserved headers that must not be overridden by user-supplied custom headers.
817
/// `MCP-Protocol-Version` is in this list but is allowed through because the worker
918
/// injects it after initialization.

0 commit comments

Comments
 (0)