generated from rmcguire/go-server-with-otel
move to generated mcp for econet
This commit is contained in:
@@ -0,0 +1,316 @@
|
||||
// Code generated by protoc-gen-mcp-go. DO NOT EDIT.
|
||||
// source: econet/v1alpha1/econet.proto
|
||||
|
||||
package v1alpha1mcp
|
||||
|
||||
import (
|
||||
v1alpha1 "gitea.libretechconsulting.com/rmcguire/econet-exporter/api/econet/v1alpha1"
|
||||
)
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"connectrpc.com/connect"
|
||||
grpc "google.golang.org/grpc"
|
||||
"github.com/redpanda-data/protoc-gen-go-mcp/pkg/runtime"
|
||||
)
|
||||
|
||||
var (
|
||||
EconetService_GetDeviceTool = runtime.Tool{Name: "econet_v1alpha1_EconetService_GetDevice", Description: "", RawInputSchema: json.RawMessage{0x7b, 0x22, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x22, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x3a, 0x7b, 0x22, 0x6d, 0x69, 0x6e, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x22, 0x3a, 0x31, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x7d, 0x2c, 0x22, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x7d}, RawOutputSchema: json.RawMessage{0x7b, 0x22, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x22, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x22, 0x61, 0x6c, 0x65, 0x72, 0x74, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x61, 0x77, 0x61, 0x79, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x7d, 0x2c, 0x22, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x7d, 0x2c, 0x22, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x7d, 0x2c, 0x22, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x68, 0x6f, 0x74, 0x5f, 0x77, 0x61, 0x74, 0x65, 0x72, 0x5f, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x22, 0x3a, 0x7b, 0x22, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x22, 0x3a, 0x22, 0x64, 0x61, 0x74, 0x65, 0x2d, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x5b, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x2c, 0x22, 0x6e, 0x75, 0x6c, 0x6c, 0x22, 0x5d, 0x7d, 0x2c, 0x22, 0x6d, 0x6f, 0x64, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x72, 0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x7d, 0x2c, 0x22, 0x72, 0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x73, 0x65, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x73, 0x65, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x6d, 0x61, 0x78, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x73, 0x65, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x6d, 0x69, 0x6e, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x77, 0x69, 0x66, 0x69, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x7d, 0x2c, 0x22, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x7d, 0x7d, 0x2c, 0x22, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x7d}}
|
||||
EconetService_ListDevicesTool = runtime.Tool{Name: "econet_v1alpha1_EconetService_ListDevices", Description: "", RawInputSchema: json.RawMessage{0x7b, 0x22, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x7d, 0x2c, 0x22, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x7d}, RawOutputSchema: json.RawMessage{0x7b, 0x22, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x22, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x22, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x3a, 0x7b, 0x22, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x22, 0x3a, 0x7b, 0x22, 0x61, 0x6c, 0x65, 0x72, 0x74, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x61, 0x77, 0x61, 0x79, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x7d, 0x2c, 0x22, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x7d, 0x2c, 0x22, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x7d, 0x2c, 0x22, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x6c, 0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x68, 0x6f, 0x74, 0x5f, 0x77, 0x61, 0x74, 0x65, 0x72, 0x5f, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x22, 0x3a, 0x7b, 0x22, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x22, 0x3a, 0x22, 0x64, 0x61, 0x74, 0x65, 0x2d, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x5b, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x2c, 0x22, 0x6e, 0x75, 0x6c, 0x6c, 0x22, 0x5d, 0x7d, 0x2c, 0x22, 0x6d, 0x6f, 0x64, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x72, 0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x7d, 0x2c, 0x22, 0x72, 0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x73, 0x65, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x73, 0x65, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x6d, 0x61, 0x78, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x73, 0x65, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x6d, 0x69, 0x6e, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x7d, 0x2c, 0x22, 0x77, 0x69, 0x66, 0x69, 0x5f, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x22, 0x3a, 0x7b, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x65, 0x72, 0x22, 0x7d, 0x7d, 0x2c, 0x22, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x7d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x61, 0x72, 0x72, 0x61, 0x79, 0x22, 0x7d, 0x7d, 0x2c, 0x22, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x3a, 0x5b, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a, 0x22, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x7d}}
|
||||
)
|
||||
|
||||
// EconetServiceServer is compatible with the grpc-go server interface.
|
||||
type EconetServiceServer interface {
|
||||
GetDevice(ctx context.Context, req *v1alpha1.GetDeviceRequest) (*v1alpha1.GetDeviceResponse, error)
|
||||
ListDevices(ctx context.Context, req *v1alpha1.ListDevicesRequest) (*v1alpha1.ListDevicesResponse, error)
|
||||
}
|
||||
|
||||
// RegisterEconetServiceHandler registers standard MCP handlers for EconetService
|
||||
func RegisterEconetServiceHandler(s runtime.MCPServer, srv EconetServiceServer, opts ...runtime.Option) {
|
||||
config := runtime.NewConfig()
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
GetDeviceTool := EconetService_GetDeviceTool
|
||||
GetDeviceTool = runtime.ApplyConfig(GetDeviceTool, config)
|
||||
|
||||
if config.ShouldRegister(GetDeviceTool.Name) {
|
||||
s.AddTool(GetDeviceTool, func(ctx context.Context, request *runtime.CallToolRequest) (*runtime.CallToolResult, error) {
|
||||
var req v1alpha1.GetDeviceRequest
|
||||
|
||||
message := request.Arguments
|
||||
|
||||
// Extract extra properties if configured
|
||||
for _, prop := range config.ExtraProperties {
|
||||
if propVal, ok := message[prop.Name]; ok {
|
||||
ctx = context.WithValue(ctx, prop.ContextKey, propVal)
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite oneof discriminated wrappers and recursion placeholders into the
|
||||
// protojson-native shape. Errors are model-readable for self-correction.
|
||||
if err := runtime.DecodeArguments(req.ProtoReflect().Descriptor(), message); err != nil {
|
||||
return runtime.NewToolResultError(err.Error()), nil
|
||||
}
|
||||
|
||||
marshaled, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(marshaled, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := srv.GetDevice(ctx, &req)
|
||||
if err != nil {
|
||||
return runtime.HandleError(err)
|
||||
}
|
||||
|
||||
structured, err := runtime.EncodeMessage(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return runtime.NewToolResultJSON(structured), nil
|
||||
})
|
||||
}
|
||||
ListDevicesTool := EconetService_ListDevicesTool
|
||||
ListDevicesTool = runtime.ApplyConfig(ListDevicesTool, config)
|
||||
|
||||
if config.ShouldRegister(ListDevicesTool.Name) {
|
||||
s.AddTool(ListDevicesTool, func(ctx context.Context, request *runtime.CallToolRequest) (*runtime.CallToolResult, error) {
|
||||
var req v1alpha1.ListDevicesRequest
|
||||
|
||||
message := request.Arguments
|
||||
|
||||
// Extract extra properties if configured
|
||||
for _, prop := range config.ExtraProperties {
|
||||
if propVal, ok := message[prop.Name]; ok {
|
||||
ctx = context.WithValue(ctx, prop.ContextKey, propVal)
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite oneof discriminated wrappers and recursion placeholders into the
|
||||
// protojson-native shape. Errors are model-readable for self-correction.
|
||||
if err := runtime.DecodeArguments(req.ProtoReflect().Descriptor(), message); err != nil {
|
||||
return runtime.NewToolResultError(err.Error()), nil
|
||||
}
|
||||
|
||||
marshaled, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(marshaled, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := srv.ListDevices(ctx, &req)
|
||||
if err != nil {
|
||||
return runtime.HandleError(err)
|
||||
}
|
||||
|
||||
structured, err := runtime.EncodeMessage(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return runtime.NewToolResultJSON(structured), nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// EconetServiceClient is compatible with the grpc-go client interface.
|
||||
type EconetServiceClient interface {
|
||||
GetDevice(ctx context.Context, req *v1alpha1.GetDeviceRequest, opts ...grpc.CallOption) (*v1alpha1.GetDeviceResponse, error)
|
||||
ListDevices(ctx context.Context, req *v1alpha1.ListDevicesRequest, opts ...grpc.CallOption) (*v1alpha1.ListDevicesResponse, error)
|
||||
}
|
||||
|
||||
// ConnectEconetServiceClient is compatible with the connectrpc-go client interface.
|
||||
type ConnectEconetServiceClient interface {
|
||||
GetDevice(ctx context.Context, req *connect.Request[v1alpha1.GetDeviceRequest]) (*connect.Response[v1alpha1.GetDeviceResponse], error)
|
||||
ListDevices(ctx context.Context, req *connect.Request[v1alpha1.ListDevicesRequest]) (*connect.Response[v1alpha1.ListDevicesResponse], error)
|
||||
}
|
||||
|
||||
// ForwardToConnectEconetServiceClient registers a connectrpc client, to forward MCP calls to it.
|
||||
func ForwardToConnectEconetServiceClient(s runtime.MCPServer, client ConnectEconetServiceClient, opts ...runtime.Option) {
|
||||
config := runtime.NewConfig()
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
GetDeviceTool := EconetService_GetDeviceTool
|
||||
GetDeviceTool = runtime.ApplyConfig(GetDeviceTool, config)
|
||||
|
||||
if config.ShouldRegister(GetDeviceTool.Name) {
|
||||
s.AddTool(GetDeviceTool, func(ctx context.Context, request *runtime.CallToolRequest) (*runtime.CallToolResult, error) {
|
||||
var req v1alpha1.GetDeviceRequest
|
||||
|
||||
message := request.Arguments
|
||||
|
||||
// Extract extra properties if configured
|
||||
for _, prop := range config.ExtraProperties {
|
||||
if propVal, ok := message[prop.Name]; ok {
|
||||
ctx = context.WithValue(ctx, prop.ContextKey, propVal)
|
||||
}
|
||||
}
|
||||
|
||||
if err := runtime.DecodeArguments(req.ProtoReflect().Descriptor(), message); err != nil {
|
||||
return runtime.NewToolResultError(err.Error()), nil
|
||||
}
|
||||
|
||||
marshaled, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(marshaled, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := client.GetDevice(ctx, connect.NewRequest(&req))
|
||||
if err != nil {
|
||||
return runtime.HandleError(err)
|
||||
}
|
||||
|
||||
structured, err := runtime.EncodeMessage(resp.Msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return runtime.NewToolResultJSON(structured), nil
|
||||
})
|
||||
}
|
||||
ListDevicesTool := EconetService_ListDevicesTool
|
||||
ListDevicesTool = runtime.ApplyConfig(ListDevicesTool, config)
|
||||
|
||||
if config.ShouldRegister(ListDevicesTool.Name) {
|
||||
s.AddTool(ListDevicesTool, func(ctx context.Context, request *runtime.CallToolRequest) (*runtime.CallToolResult, error) {
|
||||
var req v1alpha1.ListDevicesRequest
|
||||
|
||||
message := request.Arguments
|
||||
|
||||
// Extract extra properties if configured
|
||||
for _, prop := range config.ExtraProperties {
|
||||
if propVal, ok := message[prop.Name]; ok {
|
||||
ctx = context.WithValue(ctx, prop.ContextKey, propVal)
|
||||
}
|
||||
}
|
||||
|
||||
if err := runtime.DecodeArguments(req.ProtoReflect().Descriptor(), message); err != nil {
|
||||
return runtime.NewToolResultError(err.Error()), nil
|
||||
}
|
||||
|
||||
marshaled, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(marshaled, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := client.ListDevices(ctx, connect.NewRequest(&req))
|
||||
if err != nil {
|
||||
return runtime.HandleError(err)
|
||||
}
|
||||
|
||||
structured, err := runtime.EncodeMessage(resp.Msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return runtime.NewToolResultJSON(structured), nil
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ForwardToEconetServiceClient registers a gRPC client, to forward MCP calls to it.
|
||||
func ForwardToEconetServiceClient(s runtime.MCPServer, client EconetServiceClient, opts ...runtime.Option) {
|
||||
config := runtime.NewConfig()
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
GetDeviceTool := EconetService_GetDeviceTool
|
||||
GetDeviceTool = runtime.ApplyConfig(GetDeviceTool, config)
|
||||
|
||||
if config.ShouldRegister(GetDeviceTool.Name) {
|
||||
s.AddTool(GetDeviceTool, func(ctx context.Context, request *runtime.CallToolRequest) (*runtime.CallToolResult, error) {
|
||||
var req v1alpha1.GetDeviceRequest
|
||||
|
||||
message := request.Arguments
|
||||
|
||||
// Extract extra properties if configured
|
||||
for _, prop := range config.ExtraProperties {
|
||||
if propVal, ok := message[prop.Name]; ok {
|
||||
ctx = context.WithValue(ctx, prop.ContextKey, propVal)
|
||||
}
|
||||
}
|
||||
|
||||
if err := runtime.DecodeArguments(req.ProtoReflect().Descriptor(), message); err != nil {
|
||||
return runtime.NewToolResultError(err.Error()), nil
|
||||
}
|
||||
|
||||
marshaled, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(marshaled, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := client.GetDevice(ctx, &req)
|
||||
if err != nil {
|
||||
return runtime.HandleError(err)
|
||||
}
|
||||
|
||||
structured, err := runtime.EncodeMessage(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return runtime.NewToolResultJSON(structured), nil
|
||||
})
|
||||
}
|
||||
ListDevicesTool := EconetService_ListDevicesTool
|
||||
ListDevicesTool = runtime.ApplyConfig(ListDevicesTool, config)
|
||||
|
||||
if config.ShouldRegister(ListDevicesTool.Name) {
|
||||
s.AddTool(ListDevicesTool, func(ctx context.Context, request *runtime.CallToolRequest) (*runtime.CallToolResult, error) {
|
||||
var req v1alpha1.ListDevicesRequest
|
||||
|
||||
message := request.Arguments
|
||||
|
||||
// Extract extra properties if configured
|
||||
for _, prop := range config.ExtraProperties {
|
||||
if propVal, ok := message[prop.Name]; ok {
|
||||
ctx = context.WithValue(ctx, prop.ContextKey, propVal)
|
||||
}
|
||||
}
|
||||
|
||||
if err := runtime.DecodeArguments(req.ProtoReflect().Descriptor(), message); err != nil {
|
||||
return runtime.NewToolResultError(err.Error()), nil
|
||||
}
|
||||
|
||||
marshaled, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := (protojson.UnmarshalOptions{DiscardUnknown: true}).Unmarshal(marshaled, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := client.ListDevices(ctx, &req)
|
||||
if err != nil {
|
||||
return runtime.HandleError(err)
|
||||
}
|
||||
|
||||
structured, err := runtime.EncodeMessage(resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return runtime.NewToolResultJSON(structured), nil
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user