Skip to content

Commit 9b31fe1

Browse files
committed
Add debug log level support to VirtualMCPServer
Adds LogLevel field to VirtualMCPServer CRD OperationalConfig to allow enabling debug logging for vMCP instances. The field accepts only 'debug' as a valid value. When not set, the vmcp binary defaults to info level. The deployment builder passes the --debug flag to the vmcp container when LogLevel is set to 'debug'. This is the only log level flag supported by the vmcp binary, as the logger initializes before the config file is loaded. Bumps CRD chart version from 0.0.74 to 0.0.75. Fixes #2781 Signed-off-by: 4t8dd <wanger.xyz@gmail.com>
1 parent 2cc6c94 commit 9b31fe1

File tree

7 files changed

+79
-9
lines changed

7 files changed

+79
-9
lines changed

cmd/thv-operator/api/v1alpha1/virtualmcpserver_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ type ErrorHandling struct {
330330

331331
// OperationalConfig defines operational settings
332332
type OperationalConfig struct {
333+
// LogLevel sets the logging level for the Virtual MCP server.
334+
// Set to "debug" to enable debug logging. When not set, defaults to info level.
335+
// +kubebuilder:validation:Enum=debug
336+
// +optional
337+
LogLevel string `json:"logLevel,omitempty"`
338+
333339
// Timeouts configures timeout settings
334340
// +optional
335341
Timeouts *TimeoutConfig `json:"timeouts,omitempty"`

cmd/thv-operator/controllers/virtualmcpserver_deployment.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (r *VirtualMCPServerReconciler) deploymentForVirtualMCPServer(
7171
replicas := int32(1)
7272

7373
// Build deployment components using helper functions
74-
args := r.buildContainerArgsForVmcp()
74+
args := r.buildContainerArgsForVmcp(vmcp)
7575
volumeMounts, volumes := r.buildVolumesForVmcp(vmcp)
7676
env := r.buildEnvVarsForVmcp(ctx, vmcp, workloadNames)
7777
deploymentLabels, deploymentAnnotations := r.buildDeploymentMetadataForVmcp(ls, vmcp)
@@ -141,13 +141,24 @@ func (r *VirtualMCPServerReconciler) deploymentForVirtualMCPServer(
141141
}
142142

143143
// buildContainerArgsForVmcp builds the container arguments for vmcp
144-
func (*VirtualMCPServerReconciler) buildContainerArgsForVmcp() []string {
145-
return []string{
144+
func (*VirtualMCPServerReconciler) buildContainerArgsForVmcp(
145+
vmcp *mcpv1alpha1.VirtualMCPServer,
146+
) []string {
147+
args := []string{
146148
"serve",
147149
"--config=/etc/vmcp-config/config.yaml",
148150
"--host=0.0.0.0", // Listen on all interfaces for Kubernetes service routing
149151
"--port=4483", // Standard vmcp port
150152
}
153+
154+
// Add --debug flag if log level is set to debug
155+
// Note: vmcp binary currently only supports --debug flag, not other log levels
156+
// The flag must be passed at startup because logger.Initialize() runs before config is loaded
157+
if vmcp.Spec.Operational != nil && vmcp.Spec.Operational.LogLevel == "debug" {
158+
args = append(args, "--debug")
159+
}
160+
161+
return args
151162
}
152163

153164
// buildVolumesForVmcp builds volumes and volume mounts for vmcp

cmd/thv-operator/controllers/virtualmcpserver_deployment_test.go

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,56 @@ func TestDeploymentForVirtualMCPServer(t *testing.T) {
7979
func TestBuildContainerArgsForVmcp(t *testing.T) {
8080
t.Parallel()
8181

82-
r := &VirtualMCPServerReconciler{}
83-
args := r.buildContainerArgsForVmcp()
82+
tests := []struct {
83+
name string
84+
vmcp *mcpv1alpha1.VirtualMCPServer
85+
wantArgs []string
86+
}{
87+
{
88+
name: "without log level",
89+
vmcp: &mcpv1alpha1.VirtualMCPServer{
90+
ObjectMeta: metav1.ObjectMeta{
91+
Name: "test-vmcp",
92+
Namespace: "default",
93+
},
94+
Spec: mcpv1alpha1.VirtualMCPServerSpec{
95+
GroupRef: mcpv1alpha1.GroupRef{
96+
Name: "test-group",
97+
},
98+
},
99+
},
100+
wantArgs: []string{"serve", "--config=/etc/vmcp-config/config.yaml", "--host=0.0.0.0", "--port=4483"},
101+
},
102+
{
103+
name: "with log level debug",
104+
vmcp: &mcpv1alpha1.VirtualMCPServer{
105+
ObjectMeta: metav1.ObjectMeta{
106+
Name: "test-vmcp",
107+
Namespace: "default",
108+
},
109+
Spec: mcpv1alpha1.VirtualMCPServerSpec{
110+
GroupRef: mcpv1alpha1.GroupRef{
111+
Name: "test-group",
112+
},
113+
Operational: &mcpv1alpha1.OperationalConfig{
114+
LogLevel: "debug",
115+
},
116+
},
117+
},
118+
wantArgs: []string{"serve", "--config=/etc/vmcp-config/config.yaml", "--host=0.0.0.0", "--port=4483", "--debug"},
119+
},
120+
}
84121

85-
assert.Contains(t, args, "serve")
86-
assert.Contains(t, args, "--config=/etc/vmcp-config/config.yaml")
122+
for _, tt := range tests {
123+
tt := tt // capture range variable
124+
t.Run(tt.name, func(t *testing.T) {
125+
t.Parallel()
126+
r := &VirtualMCPServerReconciler{}
127+
args := r.buildContainerArgsForVmcp(tt.vmcp)
128+
129+
assert.Equal(t, tt.wantArgs, args)
130+
})
131+
}
87132
}
88133

89134
// TestBuildVolumesForVmcp tests volume and volume mount generation

deploy/charts/operator-crds/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: toolhive-operator-crds
33
description: A Helm chart for installing the ToolHive Operator CRDs into Kubernetes.
44
type: application
5-
version: 0.0.74
5+
version: 0.0.75
66
appVersion: "0.0.1"

deploy/charts/operator-crds/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ToolHive Operator CRDs Helm Chart
22

3-
![Version: 0.0.74](https://img.shields.io/badge/Version-0.0.74-informational?style=flat-square)
3+
![Version: 0.0.75](https://img.shields.io/badge/Version-0.0.75-informational?style=flat-square)
44
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
55

66
A Helm chart for installing the ToolHive Operator CRDs into Kubernetes.

deploy/charts/operator-crds/crds/toolhive.stacklok.dev_virtualmcpservers.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,13 @@ spec:
624624
failures before marking unhealthy
625625
type: integer
626626
type: object
627+
logLevel:
628+
description: |-
629+
LogLevel sets the logging level for the Virtual MCP server.
630+
Set to "debug" to enable debug logging. When not set, defaults to info level.
631+
enum:
632+
- debug
633+
type: string
627634
timeouts:
628635
description: Timeouts configures timeout settings
629636
properties:

docs/operator/crd-api.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)