MCP: Fix HTTPS support for SSE (#68020)

* MCP: Fix HTTPS support for SSE

* Add streamable HTTP cases

* Change matching to include "://" instead
This commit is contained in:
Pawel Kopiczko
2026-06-23 12:30:07 +00:00
committed by GitHub
parent 4edb720912
commit d7ae6f8afb
3 changed files with 37 additions and 7 deletions
+23 -5
View File
@@ -58,21 +58,39 @@ import (
// It allows to make the entire cluster set up once, instead of per test,
// which speeds things up significantly.
func TestAppAccess(t *testing.T) {
// Enable MCP test servers.
sseServerURL := mcptest.MustStartSSETestServer(t)
streamableHTTPServer := mcpserver.NewTestStreamableHTTPServer(mcptest.NewServer())
streamableHTTPServerURL := fmt.Sprintf("mcp+%s/mcp", streamableHTTPServer.URL)
sseServer := httptest.NewTLSServer(mcpserver.NewSSEServer(mcptest.NewServer()))
sseServerURL := "mcp+sse+" + sseServer.URL + "/sse"
t.Cleanup(sseServer.Close)
sseTLSServer := httptest.NewTLSServer(mcpserver.NewSSEServer(mcptest.NewServer()))
sseTLSServerURL := "mcp+sse+" + sseTLSServer.URL + "/sse"
t.Cleanup(sseTLSServer.Close)
streamableHTTPServer := httptest.NewServer(mcpserver.NewStreamableHTTPServer(mcptest.NewServer()))
streamableHTTPServerURL := "mcp+" + streamableHTTPServer.URL + "/mcp"
t.Cleanup(streamableHTTPServer.Close)
streamableHTTPTLSServer := httptest.NewTLSServer(mcpserver.NewStreamableHTTPServer(mcptest.NewServer()))
streamableHTTPTLSServerURL := "mcp+" + streamableHTTPTLSServer.URL + "/mcp"
t.Cleanup(streamableHTTPServer.Close)
extraApps := []servicecfg.App{
{
Name: "test-sse",
URI: "mcp+sse+" + sseServerURL,
URI: sseServerURL,
},
{
Name: "test-sse-https",
URI: sseTLSServerURL,
},
{
Name: "test-http",
URI: streamableHTTPServerURL,
},
{
Name: "test-https",
URI: streamableHTTPTLSServerURL,
},
}
// Reusing the pack as much as we can.
+12
View File
@@ -53,13 +53,25 @@ func testMCP(pack *Pack, t *testing.T) {
testMCPDialStdioToSSE(t, pack, "test-sse")
})
t.Run("stdio to sse over HTTPS success", func(t *testing.T) {
testMCPDialStdioToSSE(t, pack, "test-sse-https")
})
t.Run("proxy streamable HTTP success", func(t *testing.T) {
testMCPProxyStreamableHTTP(t, pack, "test-http")
})
t.Run("proxy streamable HTTP over HTTPS success", func(t *testing.T) {
testMCPProxyStreamableHTTP(t, pack, "test-https")
})
t.Run("stdio to streamable HTTP success", func(t *testing.T) {
testMCPStdioToStreamableHTTP(t, pack, "test-http")
})
t.Run("stdio to streamable HTTP over HTTPS success", func(t *testing.T) {
testMCPStdioToStreamableHTTP(t, pack, "test-https")
})
}
func testMCPDialStdioNoServerFound(t *testing.T, pack *Pack) {
+2 -2
View File
@@ -114,9 +114,9 @@ func makeSSEBaseURI(app types.Application) (*url.URL, error) {
return nil, trace.Wrap(err, "parsing SSE URI")
}
switch {
case strings.HasPrefix(app.GetURI(), types.SchemeMCPSSEHTTP):
case strings.HasPrefix(app.GetURI(), types.SchemeMCPSSEHTTP+"://"):
baseURL.Scheme = "http"
case strings.HasPrefix(app.GetURI(), types.SchemeMCPSSEHTTPS):
case strings.HasPrefix(app.GetURI(), types.SchemeMCPSSEHTTPS+"://"):
baseURL.Scheme = "https"
default:
return nil, trace.BadParameter("unknown scheme type: %v", baseURL.Scheme)