MCPcopy
hub / github.com/google/ax / runExecServer

Function runExecServer

cmd/ax/exec.go:259–296  ·  view source on GitHub ↗
(ctx context.Context, d *internal.Display, req *proto.ExecRequest)

Source from the content-addressed store, hash-verified

257}
258
259func runExecServer(ctx context.Context, d *internal.Display, req *proto.ExecRequest) (*proto.ConfirmationContent, error) {
260 conn, err := connect(execServerAddr)
261 if err != nil {
262 return nil, err
263 }
264 defer conn.Close()
265
266 client := proto.NewControllerServiceClient(conn)
267 stream, err := client.Exec(ctx, req)
268 if err != nil {
269 return nil, fmt.Errorf("error executing: %w", err)
270 }
271
272 var confirmation *proto.ConfirmationContent
273 var lastSeq int32
274 for {
275 resp, err := stream.Recv()
276 if err == io.EOF {
277 break
278 }
279 if err != nil {
280 return nil, fmt.Errorf("error receiving response: %w", err)
281 }
282 lastSeq = resp.Seq
283 if resp.Outputs != nil {
284 for _, m := range resp.Outputs {
285 if conf := m.GetContent().GetConfirmation(); conf != nil {
286 confirmation = conf
287 }
288 }
289 displayContents(d, resp.Outputs)
290 }
291 }
292 if confirmation == nil {
293 d.FinishOutput(fmt.Sprintf("seq=%d", lastSeq))
294 }
295 return confirmation, nil
296}
297
298func displayContents(d *internal.Display, contents []*proto.Message) {
299 for _, output := range contents {

Callers

nothing calls this directly

Calls 8

ExecMethod · 0.95
connectFunction · 0.85
displayContentsFunction · 0.85
GetConfirmationMethod · 0.80
GetContentMethod · 0.80
FinishOutputMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected