99 "strings"
1010 "time"
1111
12- "github.com/mark3labs/mcp-go/client"
12+ mcpclient "github.com/mark3labs/mcp-go/client"
1313 "github.com/mark3labs/mcp-go/mcp"
1414 . "github.com/onsi/ginkgo/v2"
1515 . "github.com/onsi/gomega"
@@ -18,6 +18,7 @@ import (
1818 "k8s.io/apimachinery/pkg/runtime"
1919 "k8s.io/apimachinery/pkg/types"
2020 "k8s.io/apimachinery/pkg/util/intstr"
21+ "sigs.k8s.io/controller-runtime/pkg/client"
2122
2223 mcpv1alpha1 "github.com/stacklok/toolhive/cmd/thv-operator/api/v1alpha1"
2324)
@@ -756,6 +757,71 @@ with socketserver.TCPServer(("", PORT), OIDCHandler) as httpd:
756757 }, timeout , pollingInterval ).Should (Succeed (), fmt .Sprintf ("%s should be ready" , backendName ))
757758 }
758759
760+ By ("DEBUG: Checking backend MCPServer status and configurations" )
761+ for _ , backendName := range []string {backend1Name , backend2Name , backend3Name } {
762+ server := & mcpv1alpha1.MCPServer {}
763+ err := k8sClient .Get (ctx , types.NamespacedName {
764+ Name : backendName ,
765+ Namespace : testNamespace ,
766+ }, server )
767+ if err != nil {
768+ GinkgoWriter .Printf ("ERROR: Failed to get backend %s: %v\n " , backendName , err )
769+ continue
770+ }
771+
772+ GinkgoWriter .Printf ("\n === Backend: %s ===\n " , backendName )
773+ GinkgoWriter .Printf (" Phase: %s\n " , server .Status .Phase )
774+ GinkgoWriter .Printf (" URL: %s\n " , server .Status .URL )
775+ GinkgoWriter .Printf (" Image: %s\n " , server .Spec .Image )
776+ GinkgoWriter .Printf (" Transport: %s\n " , server .Spec .Transport )
777+ GinkgoWriter .Printf (" Has ExternalAuthConfigRef: %v\n " , server .Spec .ExternalAuthConfigRef != nil )
778+ GinkgoWriter .Printf (" Has OIDCConfig: %v\n " , server .Spec .OIDCConfig != nil )
779+ if server .Spec .OIDCConfig != nil && server .Spec .OIDCConfig .Inline != nil {
780+ GinkgoWriter .Printf (" OIDC Issuer: %s\n " , server .Spec .OIDCConfig .Inline .Issuer )
781+ GinkgoWriter .Printf (" OIDC ClientID: %s\n " , server .Spec .OIDCConfig .Inline .ClientID )
782+ GinkgoWriter .Printf (" OIDC Audience: %s\n " , server .Spec .OIDCConfig .Inline .Audience )
783+ }
784+
785+ // Check pod status for this backend
786+ podList := & corev1.PodList {}
787+ if err := k8sClient .List (ctx , podList ,
788+ client .InNamespace (testNamespace ),
789+ client.MatchingLabels {
790+ "app.kubernetes.io/name" : "mcpserver" ,
791+ "app.kubernetes.io/instance" : backendName ,
792+ }); err != nil {
793+ GinkgoWriter .Printf (" ERROR: Failed to list pods: %v\n " , err )
794+ } else if len (podList .Items ) == 0 {
795+ GinkgoWriter .Printf (" WARNING: No pods found for backend\n " )
796+ } else {
797+ for _ , pod := range podList .Items {
798+ // Check if pod is ready by looking at conditions
799+ ready := false
800+ for _ , condition := range pod .Status .Conditions {
801+ if condition .Type == corev1 .ContainersReady && condition .Status == corev1 .ConditionTrue {
802+ ready = true
803+ break
804+ }
805+ }
806+ GinkgoWriter .Printf (" Pod: %s, Phase: %s, Ready: %v\n " ,
807+ pod .Name , pod .Status .Phase , ready )
808+
809+ // Get pod logs to check for issues
810+ if pod .Status .Phase == corev1 .PodRunning {
811+ logs , logErr := GetPodLogs (ctx , pod .Name , testNamespace , "" )
812+ if logErr == nil && len (logs ) > 0 {
813+ // Print last 500 chars of logs
814+ if len (logs ) > 500 {
815+ GinkgoWriter .Printf (" Pod logs (last 500 chars): ...%s\n " , logs [len (logs )- 500 :])
816+ } else {
817+ GinkgoWriter .Printf (" Pod logs: %s\n " , logs )
818+ }
819+ }
820+ }
821+ }
822+ }
823+ }
824+
759825 By ("Creating VirtualMCPServer with discovered auth mode and short token cache TTL" )
760826 // Create PodTemplateSpec with debug environment variables
761827 podTemplateSpec := corev1.PodTemplateSpec {
@@ -822,6 +888,69 @@ with socketserver.TCPServer(("", PORT), OIDCHandler) as httpd:
822888 "app.kubernetes.io/instance" : vmcpServerName ,
823889 }
824890 WaitForPodsReady (ctx , k8sClient , testNamespace , vmcpLabels , timeout )
891+
892+ By ("DEBUG: Checking vMCP server status and pod logs" )
893+ vmcpServerDebug := & mcpv1alpha1.VirtualMCPServer {}
894+ if err := k8sClient .Get (ctx , types.NamespacedName {
895+ Name : vmcpServerName ,
896+ Namespace : testNamespace ,
897+ }, vmcpServerDebug ); err != nil {
898+ GinkgoWriter .Printf ("ERROR: Failed to get vMCP server: %v\n " , err )
899+ } else {
900+ GinkgoWriter .Printf ("\n === VirtualMCPServer: %s ===\n " , vmcpServerName )
901+ GinkgoWriter .Printf (" Phase: %s\n " , vmcpServerDebug .Status .Phase )
902+ GinkgoWriter .Printf (" URL: %s\n " , vmcpServerDebug .Status .URL )
903+ GinkgoWriter .Printf (" Conditions:\n " )
904+ for _ , condition := range vmcpServerDebug .Status .Conditions {
905+ GinkgoWriter .Printf (" %s: %s - %s\n " , condition .Type , condition .Status , condition .Message )
906+ }
907+ }
908+
909+ // Get vMCP pod logs to see what backends it discovered
910+ vmcpPodList := & corev1.PodList {}
911+ if err := k8sClient .List (ctx , vmcpPodList ,
912+ client .InNamespace (testNamespace ),
913+ client .MatchingLabels (vmcpLabels )); err != nil {
914+ GinkgoWriter .Printf ("ERROR: Failed to list vMCP pods: %v\n " , err )
915+ } else {
916+ for _ , pod := range vmcpPodList .Items {
917+ GinkgoWriter .Printf ("\n === vMCP Pod: %s ===\n " , pod .Name )
918+ GinkgoWriter .Printf (" Phase: %s\n " , pod .Status .Phase )
919+
920+ // Get logs to see backend discovery
921+ if pod .Status .Phase == corev1 .PodRunning {
922+ logs , logErr := GetPodLogs (ctx , pod .Name , testNamespace , "vmcp" )
923+ if logErr == nil && len (logs ) > 0 {
924+ // Look for backend discovery messages
925+ GinkgoWriter .Printf (" Checking logs for backend discovery...\n " )
926+ if strings .Contains (logs , backend1Name ) {
927+ GinkgoWriter .Printf (" ✓ Found %s in logs\n " , backend1Name )
928+ } else {
929+ GinkgoWriter .Printf (" ✗ Did NOT find %s in logs\n " , backend1Name )
930+ }
931+ if strings .Contains (logs , backend2Name ) {
932+ GinkgoWriter .Printf (" ✓ Found %s in logs\n " , backend2Name )
933+ } else {
934+ GinkgoWriter .Printf (" ✗ Did NOT find %s in logs\n " , backend2Name )
935+ }
936+ if strings .Contains (logs , backend3Name ) {
937+ GinkgoWriter .Printf (" ✓ Found %s in logs\n " , backend3Name )
938+ } else {
939+ GinkgoWriter .Printf (" ✗ Did NOT find %s in logs\n " , backend3Name )
940+ }
941+
942+ // Print last 1000 chars of logs for context
943+ if len (logs ) > 1000 {
944+ GinkgoWriter .Printf ("\n vMCP logs (last 1000 chars): ...%s\n " , logs [len (logs )- 1000 :])
945+ } else {
946+ GinkgoWriter .Printf ("\n vMCP logs: %s\n " , logs )
947+ }
948+ } else if logErr != nil {
949+ GinkgoWriter .Printf (" ERROR getting logs: %v\n " , logErr )
950+ }
951+ }
952+ }
953+ }
825954 })
826955
827956 AfterAll (func () {
@@ -917,7 +1046,7 @@ with socketserver.TCPServer(("", PORT), OIDCHandler) as httpd:
9171046 }
9181047
9191048 By ("Cleaning up secrets" )
920- for _ , secretName := range []string {authSecret1Name , authSecret2Name } {
1049+ for _ , secretName := range []string {authSecret1Name , authSecret2Name , oidcClientSecretName } {
9211050 secret := & corev1.Secret {
9221051 ObjectMeta : metav1.ObjectMeta {
9231052 Name : secretName ,
@@ -1151,7 +1280,7 @@ with socketserver.TCPServer(("", PORT), OIDCHandler) as httpd:
11511280 It ("should aggregate tools from all backends with discovered auth" , func () {
11521281 By ("Creating MCP client for VirtualMCPServer" )
11531282 serverURL := fmt .Sprintf ("http://localhost:%d/mcp" , vmcpNodePort )
1154- mcpClient , err := client .NewStreamableHttpClient (serverURL )
1283+ mcpClient , err := mcpclient .NewStreamableHttpClient (serverURL )
11551284 Expect (err ).ToNot (HaveOccurred ())
11561285 defer mcpClient .Close ()
11571286
@@ -1191,7 +1320,7 @@ with socketserver.TCPServer(("", PORT), OIDCHandler) as httpd:
11911320 It ("should successfully call tools through VirtualMCPServer with discovered auth" , func () {
11921321 By ("Creating MCP client for VirtualMCPServer" )
11931322 serverURL := fmt .Sprintf ("http://localhost:%d/mcp" , vmcpNodePort )
1194- mcpClient , err := client .NewStreamableHttpClient (serverURL )
1323+ mcpClient , err := mcpclient .NewStreamableHttpClient (serverURL )
11951324 Expect (err ).ToNot (HaveOccurred ())
11961325 defer mcpClient .Close ()
11971326
@@ -1272,7 +1401,7 @@ with socketserver.TCPServer(("", PORT), OIDCHandler) as httpd:
12721401 // Create MCP client and call tools to generate traffic
12731402 By ("Creating MCP client for VirtualMCPServer" )
12741403 serverURL := fmt .Sprintf ("http://localhost:%d/mcp" , vmcpNodePort )
1275- mcpClient , err := client .NewStreamableHttpClient (serverURL )
1404+ mcpClient , err := mcpclient .NewStreamableHttpClient (serverURL )
12761405 Expect (err ).ToNot (HaveOccurred ())
12771406 defer mcpClient .Close ()
12781407
@@ -1421,7 +1550,7 @@ with socketserver.TCPServer(("", PORT), OIDCHandler) as httpd:
14211550
14221551 By ("Calling tools to trigger backend communication" )
14231552 serverURL := fmt .Sprintf ("http://localhost:%d/mcp" , vmcpNodePort )
1424- mcpClient , err := client .NewStreamableHttpClient (serverURL )
1553+ mcpClient , err := mcpclient .NewStreamableHttpClient (serverURL )
14251554 Expect (err ).ToNot (HaveOccurred ())
14261555 defer mcpClient .Close ()
14271556
0 commit comments