Compare commits
2 Commits
main
...
copilot/su
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b562b11802 | ||
|
|
959bf99c49 |
@ -2,8 +2,14 @@ package agentgatewaybackend
|
||||
|
||||
const (
|
||||
// mcpProtocol specifies that streamable HTTP protocol is to be used for the MCP target
|
||||
mcpProtocol = "kgateway.dev/mcp"
|
||||
mcpProtocol = "agentgateway.dev/mcp"
|
||||
|
||||
// mcpProtocolSSE specifies that Server-Sent Events (SSE) protocol is to be used for the MCP target
|
||||
mcpProtocolSSE = "kgateway.dev/mcp-sse"
|
||||
mcpProtocolSSE = "agentgateway.dev/mcp-sse"
|
||||
|
||||
// mcpProtocolLegacy is the legacy protocol name for streamable HTTP, kept for backwards compatibility
|
||||
mcpProtocolLegacy = "kgateway.dev/mcp"
|
||||
|
||||
// mcpProtocolSSELegacy is the legacy protocol name for SSE, kept for backwards compatibility
|
||||
mcpProtocolSSELegacy = "kgateway.dev/mcp-sse"
|
||||
)
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
- key: test-ns/service-mcp-backend
|
||||
mcp:
|
||||
targets:
|
||||
- backend:
|
||||
port: 8080
|
||||
service:
|
||||
hostname: mcp-service.test-ns.svc.cluster.local
|
||||
namespace: test-ns
|
||||
name: mcp-service-mcp
|
||||
protocol: STREAMABLE_HTTP
|
||||
name:
|
||||
name: service-mcp-backend
|
||||
namespace: test-ns
|
||||
@ -236,7 +236,8 @@ func translateMCPBackends(ctx plugins.PolicyCtx, be *agentgateway.AgentgatewayBa
|
||||
for _, service := range matchingServices {
|
||||
for _, port := range service.Spec.Ports {
|
||||
appProtocol := ptr.OrEmpty(port.AppProtocol)
|
||||
if appProtocol != mcpProtocol && appProtocol != mcpProtocolSSE {
|
||||
if appProtocol != mcpProtocol && appProtocol != mcpProtocolSSE &&
|
||||
appProtocol != mcpProtocolLegacy && appProtocol != mcpProtocolSSELegacy {
|
||||
// not a valid MCPBackend protocol
|
||||
continue
|
||||
}
|
||||
@ -479,10 +480,10 @@ func translateAwsBackends(
|
||||
|
||||
func toMCPProtocol(appProtocol string) api.MCPTarget_Protocol {
|
||||
switch appProtocol {
|
||||
case mcpProtocol:
|
||||
case mcpProtocol, mcpProtocolLegacy:
|
||||
return api.MCPTarget_STREAMABLE_HTTP
|
||||
|
||||
case mcpProtocolSSE:
|
||||
case mcpProtocolSSE, mcpProtocolSSELegacy:
|
||||
return api.MCPTarget_SSE
|
||||
|
||||
default:
|
||||
|
||||
@ -107,6 +107,31 @@ func TestBuildMCP(t *testing.T) {
|
||||
},
|
||||
inputs: append(createMockMultipleNamespaceServices(), createMockNamespaceCollectionWithLabels()...),
|
||||
},
|
||||
{
|
||||
name: "Service selector MCPBackend backend - agentgateway.dev appProtocol",
|
||||
backend: &agentgateway.AgentgatewayBackend{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "service-mcp-backend",
|
||||
Namespace: "test-ns",
|
||||
},
|
||||
Spec: agentgateway.AgentgatewayBackendSpec{
|
||||
MCP: &agentgateway.MCPBackend{
|
||||
Targets: []agentgateway.McpTargetSelector{
|
||||
{
|
||||
Selector: &agentgateway.McpSelector{
|
||||
Service: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"app": "mcp-server",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
inputs: []any{createMockMCPServiceWithProtocol("test-ns", "mcp-service", "app=mcp-server", "agentgateway.dev/mcp")},
|
||||
},
|
||||
{
|
||||
name: "Error case - invalid service selector",
|
||||
backend: &agentgateway.AgentgatewayBackend{
|
||||
@ -699,6 +724,26 @@ func TestGetSecretValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// createMockMCPServiceWithProtocol creates a mock service with a configurable appProtocol
|
||||
func createMockMCPServiceWithProtocol(namespace, serviceName, _ /* labels */, appProtocol string) *corev1.Service {
|
||||
return &corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: serviceName,
|
||||
Namespace: namespace,
|
||||
Labels: map[string]string{"app": "mcp-server"},
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Name: "mcp",
|
||||
Port: 8080,
|
||||
AppProtocol: ptr.Of(appProtocol),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// createMockMCPService creates a mock service collection with a specific MCPBackend service
|
||||
func createMockMCPService(namespace, serviceName, labels string) *corev1.Service {
|
||||
// Parse labels
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user