Skip to content

Agent Mesh

node: accept a2a services with URL backends

Tomas Tormo43eeedb08c81
diff --git a/internal/node/a2a_service.go b/internal/node/a2a_service.go
new file mode 100644
index 00000000..5bf8af53
--- /dev/null
+++ b/internal/node/a2a_service.go
@@ -0,0 +1,43 @@
+// Copyright 2026 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package node
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/google/sam/api"
+)
+
+// A2AService proxies Agent2Agent (A2A) JSON-RPC/REST traffic to a local
+// agent process. URL backends only: a command backend would wire the A2A
+// route to an MCP stdio bridge no A2A client can talk to.
+type A2AService struct{ baseService }
+
+func (s *A2AService) Init(ctx context.Context) error {
+ switch x := s.backend.(type) {
+ case *api.RegisterServiceRequest_TargetUrl:
+ h, err := newReverseProxyHandler(x.TargetUrl)
+ if err != nil {
+ return err
+ }
+ s.handler = h
+ case *api.RegisterServiceRequest_Command:
+ return fmt.Errorf("command-based backends are not supported for A2AService")
+ default:
+ return fmt.Errorf("unsupported backend type %T for A2AService", s.backend)
+ }
+ return nil
+}
diff --git a/internal/node/a2a_service_test.go b/internal/node/a2a_service_test.go
new file mode 100644
index 00000000..0a0611f6
--- /dev/null
+++ b/internal/node/a2a_service_test.go
@@ -0,0 +1,59 @@
+// Copyright 2026 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package node
+
+import (
+ "context"
+ "testing"
+
+ "github.com/google/sam/api"
+)
+
+func TestA2AServiceInitRejectsCommand(t *testing.T) {
+ svc := &A2AService{baseService: baseService{
+ info: &api.ServiceInfo{Type: api.ServiceType_SERVICE_TYPE_A2A, Name: "agent"},
+ backend: &api.RegisterServiceRequest_Command{Command: &api.CommandBackend{Command: []string{"echo"}}},
+ }}
+ if err := svc.Init(context.Background()); err == nil {
+ t.Fatal("command backend must be rejected for a2a services")
+ }
+}
+
+func TestA2AServiceInitURLBackend(t *testing.T) {
+ svc := &A2AService{baseService: baseService{
+ info: &api.ServiceInfo{Type: api.ServiceType_SERVICE_TYPE_A2A, Name: "agent"},
+ backend: &api.RegisterServiceRequest_TargetUrl{TargetUrl: "http://127.0.0.1:9999"},
+ }}
+ if err := svc.Init(context.Background()); err != nil {
+ t.Fatalf("url backend must be accepted: %v", err)
+ }
+ if svc.Handler() == nil {
+ t.Fatal("nil handler after Init")
+ }
+}
+
+func TestNewServiceFromRequestA2A(t *testing.T) {
+ req := &api.RegisterServiceRequest{
+ Service: &api.ServiceInfo{Type: api.ServiceType_SERVICE_TYPE_A2A, Name: "agent"},
+ Backend: &api.RegisterServiceRequest_TargetUrl{TargetUrl: "http://127.0.0.1:9999"},
+ }
+ svc, err := NewServiceFromRequest(req)
+ if err != nil {
+ t.Fatalf("factory must accept a2a: %v", err)
+ }
+ if _, ok := svc.(*A2AService); !ok {
+ t.Fatalf("factory returned %T, want *A2AService", svc)
+ }
+}
diff --git a/internal/node/service.go b/internal/node/service.go
index 47406c83..5ab02214 100644
--- a/internal/node/service.go
+++ b/internal/node/service.go
@@ -118,11 +118,6 @@ func (b *baseService) Teardown() error {
return b.cmd.Process.Kill()
}
-// A2AService is zero-override embedding. They exist
-// so the factory produces a distinct type per ServiceType, leaving room for
-// future per-kind behaviour without churn.
-type A2AService struct{ baseService }
-
func NewServiceFromRequest(req *api.RegisterServiceRequest) (Service, error) {
info := req.Service
switch info.Type {
@@ -130,6 +125,8 @@ func NewServiceFromRequest(req *api.RegisterServiceRequest) (Service, error) {
return &MCPService{baseService: baseService{info: info, backend: req.Backend}}, nil
case api.ServiceType_SERVICE_TYPE_INFERENCE:
return &InferenceService{baseService: baseService{info: info, backend: req.Backend}}, nil
+ case api.ServiceType_SERVICE_TYPE_A2A:
+ return &A2AService{baseService: baseService{info: info, backend: req.Backend}}, nil
default:
return nil, fmt.Errorf("unspecified or unsupported service type: %v", info.Type)
}