Skip to content

Commit cf45070

Browse files
authored
feat(streamable-http): support both SSE and JSON response formats (#540)
What this enables: - Clients can accept either Server-Sent Events (SSE) or JSON responses - Flexible content negotiation based on server preferences - Improved interoperability with different MCP server implementations
1 parent 25e2ec4 commit cf45070

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/rmcp/src/transport/common/reqwest/streamable_http_client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl StreamableHttpClient for reqwest::Client {
3333
) -> Result<BoxStream<'static, Result<Sse, SseError>>, StreamableHttpError<Self::Error>> {
3434
let mut request_builder = self
3535
.get(uri.as_ref())
36-
.header(ACCEPT, EVENT_STREAM_MIME_TYPE)
36+
.header(ACCEPT, [EVENT_STREAM_MIME_TYPE, JSON_MIME_TYPE].join(", "))
3737
.header(HEADER_SESSION_ID, session_id.as_ref());
3838
if let Some(last_event_id) = last_event_id {
3939
request_builder = request_builder.header(HEADER_LAST_EVENT_ID, last_event_id);
@@ -48,7 +48,9 @@ impl StreamableHttpClient for reqwest::Client {
4848
let response = response.error_for_status()?;
4949
match response.headers().get(reqwest::header::CONTENT_TYPE) {
5050
Some(ct) => {
51-
if !ct.as_bytes().starts_with(EVENT_STREAM_MIME_TYPE.as_bytes()) {
51+
if !ct.as_bytes().starts_with(EVENT_STREAM_MIME_TYPE.as_bytes())
52+
&& !ct.as_bytes().starts_with(JSON_MIME_TYPE.as_bytes())
53+
{
5254
return Err(StreamableHttpError::UnexpectedContentType(Some(
5355
String::from_utf8_lossy(ct.as_bytes()).to_string(),
5456
)));

0 commit comments

Comments
 (0)