mirror of
https://github.com/RightNow-AI/openfang.git
synced 2026-07-30 06:32:17 +00:00
Merge pull request #779 from Mohl/fix/streamable-http-mcp
fix(mcp): handle Streamable HTTP MCP responses with SSE framing
This commit is contained in:
@@ -365,7 +365,21 @@ impl McpConnection {
|
||||
.await
|
||||
.map_err(|e| format!("Failed to read SSE response: {e}"))?;
|
||||
|
||||
let rpc_response: JsonRpcResponse = serde_json::from_str(&body)
|
||||
// Handle Streamable HTTP MCP responses that use SSE framing
|
||||
// (e.g. "event: message\ndata: {...}\n\n"). Extract the JSON
|
||||
// from the last `data:` line if the body looks like SSE.
|
||||
let json_body = if body.trim_start().starts_with("event:") || body.trim_start().starts_with("data:") {
|
||||
body.lines()
|
||||
.filter_map(|line| line.strip_prefix("data: ").or_else(|| line.strip_prefix("data:")))
|
||||
.filter(|s| !s.is_empty())
|
||||
.last()
|
||||
.unwrap_or(&body)
|
||||
.to_string()
|
||||
} else {
|
||||
body
|
||||
};
|
||||
|
||||
let rpc_response: JsonRpcResponse = serde_json::from_str(&json_body)
|
||||
.map_err(|e| format!("Invalid MCP SSE JSON-RPC response: {e}"))?;
|
||||
|
||||
if let Some(err) = rpc_response.error {
|
||||
|
||||
Reference in New Issue
Block a user