Skip to content

Commit 11f525c

Browse files
authored
feat!: add SEP-2243 HTTP standard headers (#907)
* feat: add SEP-2243 HTTP standard headers * feat!: validate Mcp-Param-* headers on server * fix: emit Mcp-Method on reinit initialized POST * fix: align header mismatch error code with draft spec * chore: remove redundant streamable HTTP client comments
1 parent 60d3e77 commit 11f525c

8 files changed

Lines changed: 1183 additions & 40 deletions

File tree

crates/rmcp/Cargo.toml

Lines changed: 7 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"]
@@ -293,6 +294,11 @@ name = "test_protocol_version_negotiation"
293294
required-features = ["server", "client"]
294295
path = "tests/test_protocol_version_negotiation.rs"
295296

297+
[[test]]
298+
name = "test_streamable_http_standard_headers"
299+
required-features = ["server", "client", "transport-streamable-http-server", "reqwest"]
300+
path = "tests/test_streamable_http_standard_headers.rs"
301+
296302
[[test]]
297303
name = "test_streamable_http_4xx_error_body"
298304
required-features = ["transport-streamable-http-client", "transport-streamable-http-client-reqwest"]

crates/rmcp/src/model.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ impl ProtocolVersion {
168168
pub const V_2024_11_05: Self = Self(Cow::Borrowed("2024-11-05"));
169169
pub const LATEST: Self = Self::V_2025_11_25;
170170

171+
/// First protocol version that requires SEP-2243 standard HTTP headers.
172+
pub const STANDARD_HEADERS: Self = Self::V_2026_07_28;
173+
171174
/// All protocol versions known to this SDK.
172175
pub const KNOWN_VERSIONS: &[Self] = &[
173176
Self::V_2024_11_05,
@@ -512,6 +515,7 @@ pub struct JsonRpcNotification<N = Notification> {
512515
pub struct ErrorCode(pub i32);
513516

514517
impl ErrorCode {
518+
pub const HEADER_MISMATCH: Self = Self(-32020);
515519
pub const RESOURCE_NOT_FOUND: Self = Self(-32002);
516520
pub const INVALID_REQUEST: Self = Self(-32600);
517521
pub const METHOD_NOT_FOUND: Self = Self(-32601);
@@ -557,7 +561,9 @@ impl ErrorData {
557561
pub fn resource_not_found(message: impl Into<Cow<'static, str>>, data: Option<Value>) -> Self {
558562
Self::new(ErrorCode::RESOURCE_NOT_FOUND, message, data)
559563
}
560-
564+
pub fn header_mismatch(message: impl Into<Cow<'static, str>>, data: Option<Value>) -> Self {
565+
Self::new(ErrorCode::HEADER_MISMATCH, message, data)
566+
}
561567
pub fn parse_error(message: impl Into<Cow<'static, str>>, data: Option<Value>) -> Self {
562568
Self::new(ErrorCode::PARSE_ERROR, message, data)
563569
}

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)