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
12 changes: 12 additions & 0 deletions pkg/controller/transportadapter/transportadapter_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import (
const (
transportAdapterRepository = "ghcr.io/agentgateway/agentgateway"
defaultTransportAdapterVersion = "0.9.0"
kgatewayMcpAppProtocol = "kgateway.dev/mcp"
)

// versionRegex validates that version strings contain only allowed characters
// (alphanumeric, dots, hyphens) to prevent potential image injection attacks
var versionRegex = regexp.MustCompile(`^[a-zA-Z0-9.\-]+$`)
var disableKgatewayMcpAppProtocol = os.Getenv("DISABLE_KGATEWAY_MCP_APP_PROTOCOL")

// Translator is the interface for translating MCPServer objects to TransportAdapter objects.
type Translator interface {
Expand Down Expand Up @@ -481,6 +483,11 @@ func (t *transportAdapterTranslator) translateTransportAdapterService(
if port == 0 {
return nil, fmt.Errorf("deployment port must be specified for MCPServer %s", server.Name)
}

appProtocol := makePtr(kgatewayMcpAppProtocol)
if disableKgatewayMcpAppProtocol == "true" {
appProtocol = nil
}
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: server.Name,
Expand All @@ -498,6 +505,7 @@ func (t *transportAdapterTranslator) translateTransportAdapterService(
TargetPort: intstr.IntOrString{
IntVal: int32(port),
},
AppProtocol: appProtocol,
}},
Selector: map[string]string{
"app.kubernetes.io/name": server.Name,
Expand Down Expand Up @@ -663,3 +671,7 @@ func getTransportAdapterImage() string {

return fmt.Sprintf("%s:%s-musl", transportAdapterRepository, transportAdapterVersion)
}

func makePtr[T any](v T) *T {
return &v
}
1 change: 1 addition & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ var _ = ginkgo.Describe("Manager", ginkgo.Ordered, func() {
g.Expect(service).NotTo(gomega.BeNil())
g.Expect(service.Spec.Ports).To(gomega.HaveLen(1))
g.Expect(service.Spec.Ports[0].Port).To(gomega.Equal(int32(3000)))
g.Expect(service.Spec.Ports[0].AppProtocol).To(gomega.HaveValue(gomega.Equal("kgateway.dev/mcp")))
}).Should(gomega.Succeed())

ginkgo.By("verifying that environment variables are loaded via envFrom")
Expand Down
Loading