VirtualMCPServer E2E Tests
November 21, 2025 ยท View on GitHub
This directory contains end-to-end tests for the VirtualMCPServer controller that run against a real Kubernetes cluster.
Prerequisites
- A Kubernetes cluster with the ToolHive operator installed
kubectlconfigured to access the cluster- The VirtualMCPServer CRDs installed
Note: The Ginkgo CLI is automatically installed by the task commands when running tests.
Running the Tests
Using the Task Command (Recommended)
The easiest way to run the tests is using the task command from the operator directory, which will:
- Create a Kind cluster
- Install CRDs
- Deploy the operator
- Run all tests from test/e2e/thv-operator/virtualmcp (including setup)
- Clean up the cluster
# Run from the project root
task thv-operator-e2e-test
Manual Testing
The tests will:
- Use the kubeconfig from
$KUBECONFIGor~/.kube/config - Create all necessary resources (MCPGroup, MCPServers, VirtualMCPServer)
- Run comprehensive MCP protocol tests
- Clean up resources after completion
cd test/e2e/thv-operator/virtualmcp
ginkgo -v
Customizing Test Parameters
You can customize the kubeconfig path using the KUBECONFIG environment variable:
export KUBECONFIG="/path/to/kubeconfig"
ginkgo -v
Running Specific Tests
# Run only discovered mode tests
ginkgo -v --focus="Discovered Mode"
# Run tests and get verbose output
ginkgo -vv
Test Structure
Files
suite_test.go- Ginkgo test suite setup with kubeconfig loadingvirtualmcp_discovered_mode_test.go- Tests VirtualMCPServer with discovered mode aggregationhelpers.go- Common helper functions for interacting with Kubernetes resourcesREADME.md- This file
Test Descriptions
Discovered Mode Tests (virtualmcp_discovered_mode_test.go)
Comprehensive E2E tests for VirtualMCPServer in discovered mode, which automatically discovers and aggregates tools from backend MCP servers in a group:
- Creates two backend MCPServers (fetch and osv) both using streamable-http transport
- Verifies VirtualMCPServer aggregates tools from all backends in the group
- Tests tool calls through the VirtualMCPServer proxy
- Validates discovered mode configuration and backend discovery
- Uses prefix conflict resolution strategy to namespace tools from different backends
Environment Variables
| Variable | Description | Default |
|---|---|---|
KUBECONFIG | Path to kubeconfig file | ~/.kube/config |
Adding New Tests
To add new test cases:
- Create a new test file following the naming pattern
*_test.go - Use the shared
k8sClientandctxvariables fromsuite_test.go - Use helper functions from
helpers.gowhen possible - Follow Ginkgo BDD style with
Describe,Context, andItblocks
Example:
var _ = Describe("VirtualMCPServer Feature", func() {
Context("when testing feature X", func() {
It("should behave as expected", func() {
// Test implementation
})
})
})
Troubleshooting
Tests fail with "kubeconfig file should exist"
Ensure your KUBECONFIG environment variable points to a valid kubeconfig file, or that ~/.kube/config exists.
Tests fail with "VirtualMCPServer should exist"
Make sure:
- The ToolHive operator is running in your cluster
- The VirtualMCPServer CRDs are installed
- The tests create their own VirtualMCPServer resources for testing
Tests timeout waiting for resources
Check:
- The operator is running:
kubectl get pods -n toolhive-system - The operator logs for errors:
kubectl logs -n toolhive-system -l app.kubernetes.io/name=thv-operator - The VirtualMCPServer status:
kubectl get virtualmcpserver -n <namespace> <name> -o yaml