fix: accept 200 with empty body in response to notifications in addition to 202 (#849)
This commit is contained in:
parent
3529c3675f
commit
cc66e3091e
2 changed files with 79 additions and 0 deletions
|
|
@ -178,11 +178,25 @@ impl StreamableHttpClient for reqwest::Client {
|
|||
.headers()
|
||||
.get(reqwest::header::CONTENT_TYPE)
|
||||
.map(|ct| String::from_utf8_lossy(ct.as_bytes()).to_string());
|
||||
let content_length = response.content_length();
|
||||
let session_id = response
|
||||
.headers()
|
||||
.get(HEADER_SESSION_ID)
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.map(|s| s.to_string());
|
||||
// Spec requires 202 Accepted for these, but some servers return an empty 200.
|
||||
// Treat empty success responses as equivalent to Accepted.
|
||||
if status.is_success()
|
||||
&& content_length == Some(0)
|
||||
&& matches!(
|
||||
message,
|
||||
ClientJsonRpcMessage::Notification(_)
|
||||
| ClientJsonRpcMessage::Response(_)
|
||||
| ClientJsonRpcMessage::Error(_)
|
||||
)
|
||||
{
|
||||
return Ok(StreamableHttpPostResponse::Accepted);
|
||||
}
|
||||
// Non-success responses may carry valid JSON-RPC error payloads that
|
||||
// should be surfaced as McpError rather than lost in TransportSend.
|
||||
if !status.is_success() {
|
||||
|
|
|
|||
|
|
@ -257,12 +257,29 @@ impl StreamableHttpClient for UnixSocketHttpClient {
|
|||
}
|
||||
|
||||
let content_type = response.headers().get(http::header::CONTENT_TYPE).cloned();
|
||||
let content_length = response
|
||||
.headers()
|
||||
.get(http::header::CONTENT_LENGTH)
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.and_then(|v| v.parse::<u64>().ok());
|
||||
let session_id = response
|
||||
.headers()
|
||||
.get(HEADER_SESSION_ID)
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.map(|s| s.to_string());
|
||||
|
||||
if status.is_success()
|
||||
&& content_length == Some(0)
|
||||
&& matches!(
|
||||
message,
|
||||
ClientJsonRpcMessage::Notification(_)
|
||||
| ClientJsonRpcMessage::Response(_)
|
||||
| ClientJsonRpcMessage::Error(_)
|
||||
)
|
||||
{
|
||||
return Ok(StreamableHttpPostResponse::Accepted);
|
||||
}
|
||||
|
||||
match content_type {
|
||||
Some(ref ct) if ct.as_bytes().starts_with(EVENT_STREAM_MIME_TYPE.as_bytes()) => {
|
||||
let sse_stream = SseStream::new(response.into_body()).boxed();
|
||||
|
|
|
|||
Loading…
Reference in a new issue