Skip to content

Commit d4932ed

Browse files
authored
feat: add kgateway mcp app protocol to service port (#117)
Support using the kgateway mcp app protocol by default which can be disabled by setting the following environment variable on the kmcp controller deployment ``` - env: - name: DISABLE_KGATEWAY_MCP_APP_PROTOCOL value: true ``` --------- Signed-off-by: JM Huibonhoa <jm.huibonhoa@solo.io>
1 parent 6bd1712 commit d4932ed

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

pkg/controller/transportadapter/transportadapter_translator.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import (
2626
const (
2727
transportAdapterRepository = "ghcr.io/agentgateway/agentgateway"
2828
defaultTransportAdapterVersion = "0.9.0"
29+
kgatewayMcpAppProtocol = "kgateway.dev/mcp"
2930
)
3031

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

3537
// Translator is the interface for translating MCPServer objects to TransportAdapter objects.
3638
type Translator interface {
@@ -481,6 +483,11 @@ func (t *transportAdapterTranslator) translateTransportAdapterService(
481483
if port == 0 {
482484
return nil, fmt.Errorf("deployment port must be specified for MCPServer %s", server.Name)
483485
}
486+
487+
appProtocol := makePtr(kgatewayMcpAppProtocol)
488+
if disableKgatewayMcpAppProtocol == "true" {
489+
appProtocol = nil
490+
}
484491
service := &corev1.Service{
485492
ObjectMeta: metav1.ObjectMeta{
486493
Name: server.Name,
@@ -498,6 +505,7 @@ func (t *transportAdapterTranslator) translateTransportAdapterService(
498505
TargetPort: intstr.IntOrString{
499506
IntVal: int32(port),
500507
},
508+
AppProtocol: appProtocol,
501509
}},
502510
Selector: map[string]string{
503511
"app.kubernetes.io/name": server.Name,
@@ -663,3 +671,7 @@ func getTransportAdapterImage() string {
663671

664672
return fmt.Sprintf("%s:%s-musl", transportAdapterRepository, transportAdapterVersion)
665673
}
674+
675+
func makePtr[T any](v T) *T {
676+
return &v
677+
}

test/e2e/e2e_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ var _ = ginkgo.Describe("Manager", ginkgo.Ordered, func() {
268268
g.Expect(service).NotTo(gomega.BeNil())
269269
g.Expect(service.Spec.Ports).To(gomega.HaveLen(1))
270270
g.Expect(service.Spec.Ports[0].Port).To(gomega.Equal(int32(3000)))
271+
g.Expect(service.Spec.Ports[0].AppProtocol).To(gomega.HaveValue(gomega.Equal("kgateway.dev/mcp")))
271272
}).Should(gomega.Succeed())
272273

273274
ginkgo.By("verifying that environment variables are loaded via envFrom")

0 commit comments

Comments
 (0)