mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-12 02:15:01 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user