Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/release.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:

release:
needs: ["activation", "create-tag"]
if: always() && needs.activation.result == 'success' && (needs.create-tag.result == 'success' || needs.create-tag.result == 'skipped')
if: always() && needs.activation.result == 'success' && ((github.event_name == 'workflow_dispatch' && needs.create-tag.result == 'success') || (github.event_name != 'workflow_dispatch' && needs.create-tag.result == 'skipped'))
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
119 changes: 54 additions & 65 deletions internal/launcher/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,52 @@ func newTestConfig(servers map[string]*config.ServerConfig) *config.Config {
}
}

func newTestHTTPMCPServer(t *testing.T, inspectRequest func(*http.Request)) *httptest.Server {
t.Helper()

return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if inspectRequest != nil {
inspectRequest(r)
}

var request map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

switch request["method"] {
case "server/discover":
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"jsonrpc": "2.0",
"id": request["id"],
"error": map[string]interface{}{
"code": -32601,
"message": `method not found: "server/discover"`,
},
})
case "notifications/initialized":
w.WriteHeader(http.StatusAccepted)
default:
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Mcp-Session-Id", "test-session")
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"jsonrpc": "2.0",
"id": request["id"],
"result": map[string]interface{}{
"protocolVersion": "2024-11-05",
"capabilities": map[string]interface{}{},
"serverInfo": map[string]interface{}{
"name": "test-server",
"version": "1.0.0",
},
},
})
}
}))
}

func TestHTTPConnection(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -100,23 +146,9 @@ func TestHTTPConnection(t *testing.T) {
// Setup environment if needed
tt.setupEnv(t)

// Create a mock HTTP server
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := map[string]interface{}{
"jsonrpc": "2.0",
"id": 1,
"result": map[string]interface{}{
"protocolVersion": "2024-11-05",
"capabilities": map[string]interface{}{},
"serverInfo": map[string]interface{}{
"name": "test-server",
"version": "1.0.0",
},
},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}))
mockServer := newTestHTTPMCPServer(t, func(r *http.Request) {
assert.Equal(t, tt.wantAuthValue, r.Header.Get(tt.authHeader))
})
defer mockServer.Close()

// Create test config with HTTP server
Expand Down Expand Up @@ -149,6 +181,7 @@ func TestHTTPConnection(t *testing.T) {
// Test launcher
ctx := context.Background()
l := New(ctx, cfg)
t.Cleanup(l.Close)

// Get connection
conn, err := GetOrLaunch(l, tt.serverID)
Expand Down Expand Up @@ -311,22 +344,7 @@ func TestGetOrLaunch_InvalidServerID(t *testing.T) {
}

func TestGetOrLaunch_Reuse(t *testing.T) {
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := map[string]interface{}{
"jsonrpc": "2.0",
"id": 1,
"result": map[string]interface{}{
"protocolVersion": "2024-11-05",
"capabilities": map[string]interface{}{},
"serverInfo": map[string]interface{}{
"name": "test-server",
"version": "1.0.0",
},
},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}))
mockServer := newTestHTTPMCPServer(t, nil)
defer mockServer.Close()

jsonConfig := fmt.Sprintf(`{
Expand All @@ -346,6 +364,7 @@ func TestGetOrLaunch_Reuse(t *testing.T) {
cfg := loadConfigFromJSON(t, jsonConfig)
ctx := context.Background()
l := New(ctx, cfg)
t.Cleanup(l.Close)

// First call - should create new connection
conn1, err := GetOrLaunch(l, "test-server")
Expand Down Expand Up @@ -412,22 +431,7 @@ func TestServerIDs_Empty(t *testing.T) {
}

func TestClose(t *testing.T) {
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := map[string]interface{}{
"jsonrpc": "2.0",
"id": 1,
"result": map[string]interface{}{
"protocolVersion": "2024-11-05",
"capabilities": map[string]interface{}{},
"serverInfo": map[string]interface{}{
"name": "test-server",
"version": "1.0.0",
},
},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}))
mockServer := newTestHTTPMCPServer(t, nil)
defer mockServer.Close()

jsonConfig := fmt.Sprintf(`{
Expand Down Expand Up @@ -469,22 +473,7 @@ func TestClose(t *testing.T) {

func TestGetOrLaunchForSession_HTTPBackend(t *testing.T) {
// HTTP backends should use regular GetOrLaunch (stateless)
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := map[string]interface{}{
"jsonrpc": "2.0",
"id": 1,
"result": map[string]interface{}{
"protocolVersion": "2024-11-05",
"capabilities": map[string]interface{}{},
"serverInfo": map[string]interface{}{
"name": "http-test",
"version": "1.0.0",
},
},
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
}))
mockServer := newTestHTTPMCPServer(t, nil)
defer mockServer.Close()

jsonConfig := fmt.Sprintf(`{
Expand Down
12 changes: 10 additions & 2 deletions internal/mcp/oidc_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ func TestNewHTTPConnection_WithOIDCProvider(t *testing.T) {
w.Header().Set("Content-Type", "text/event-stream")
w.WriteHeader(http.StatusOK)
case http.MethodPost:
req := decodeJSONRPCRequest(r)
if handleDiscoveryProbe(w, r, req) {
return
}
// Respond with a minimal valid MCP initialize response.
resp := map[string]interface{}{
"jsonrpc": "2.0",
"id": 1,
"id": req["id"],
"result": map[string]interface{}{
"protocolVersion": "2024-11-05",
"serverInfo": map[string]interface{}{
Expand Down Expand Up @@ -114,9 +118,13 @@ func TestNewHTTPConnection_WithOIDCAndStaticHeaders(t *testing.T) {
w.Header().Set("Content-Type", "text/event-stream")
w.WriteHeader(http.StatusOK)
case http.MethodPost:
req := decodeJSONRPCRequest(r)
if handleDiscoveryProbe(w, r, req) {
return
}
resp := map[string]interface{}{
"jsonrpc": "2.0",
"id": 1,
"id": req["id"],
"result": map[string]interface{}{
"protocolVersion": "2024-11-05",
"serverInfo": map[string]interface{}{"name": "test"},
Expand Down
Loading