Skip to content

Commit d47a81e

Browse files
RahulHereRahulHere
authored andcommitted
Resolve HttpSse transport not using URL path for SSE endpoint
The HttpSse transport case was extracting the path from the URL but discarding it, causing the client to default to /rpc instead of using the correct path (e.g., /sse) specified in the server URL. Changes: - Extract and set config.http_path from URL for HttpSse transport - Set config.http_host for proper Host header - Add SSL configuration for HTTPS URLs (matching StreamableHttp behavior)
1 parent 684f359 commit d47a81e

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

src/client/mcp_client.cc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,23 +882,46 @@ McpConnectionConfig McpClient::createConnectionConfig(TransportType transport) {
882882
http_config.mode = transport::HttpSseTransportSocketConfig::Mode::CLIENT;
883883

884884
// Extract server address from URI
885-
// URI format: http://host:port or https://host:port
885+
// URI format: http://host:port/path or https://host:port/path
886886
std::string server_addr;
887+
bool is_https = false;
887888
if (current_uri_.find("http://") == 0) {
888889
server_addr = current_uri_.substr(7); // Remove "http://"
889890
} else if (current_uri_.find("https://") == 0) {
890891
server_addr = current_uri_.substr(8); // Remove "https://"
892+
is_https = true;
891893
} else {
892894
server_addr = current_uri_;
893895
}
894896

895-
// Remove any path component (everything after first /)
897+
// Extract path component (e.g., /sse from https://host/sse)
898+
std::string http_path = "/";
896899
size_t slash_pos = server_addr.find('/');
897900
if (slash_pos != std::string::npos) {
901+
http_path = server_addr.substr(slash_pos);
898902
server_addr = server_addr.substr(0, slash_pos);
899903
}
900904

901905
http_config.server_address = server_addr;
906+
config.http_path = http_path;
907+
config.http_host = server_addr;
908+
909+
// Set SSL transport for HTTPS URLs
910+
if (is_https) {
911+
http_config.underlying_transport =
912+
transport::HttpSseTransportSocketConfig::UnderlyingTransport::SSL;
913+
transport::HttpSseTransportSocketConfig::SslConfig ssl_cfg;
914+
ssl_cfg.verify_peer = false;
915+
ssl_cfg.alpn_protocols = std::vector<std::string>{"http/1.1"};
916+
std::string sni_host = server_addr;
917+
size_t colon_pos = sni_host.find(':');
918+
if (colon_pos != std::string::npos) {
919+
sni_host = sni_host.substr(0, colon_pos);
920+
}
921+
ssl_cfg.sni_hostname = mcp::make_optional(sni_host);
922+
http_config.ssl_config = mcp::make_optional(ssl_cfg);
923+
}
924+
902925
config.http_sse_config = mcp::make_optional(http_config);
903926
break;
904927
}

0 commit comments

Comments
 (0)