@@ -493,6 +493,9 @@ func (r *RootCmd) mcpServer() *serpent.Command {
493
493
}
494
494
495
495
func (s * mcpServer ) startReporter (ctx context.Context , inv * serpent.Invocation ) {
496
+ // lastMessageID is the ID of the last *user* message that we saw. A user
497
+ // message only happens when interacting via the API (as opposed to
498
+ // interacting with the terminal directly).
496
499
var lastMessageID int64
497
500
shouldUpdate := func (item reportTask ) codersdk.WorkspaceAppStatusState {
498
501
// Always send self-reported updates.
@@ -505,18 +508,17 @@ func (s *mcpServer) startReporter(ctx context.Context, inv *serpent.Invocation)
505
508
codersdk .WorkspaceAppStatusStateFailure :
506
509
return item .state
507
510
}
508
- // Always send "working" when there is a new message, since this means the
509
- // user submitted a message through the API and we know the LLM will begin
510
- // work soon if it has not already.
511
+ // Always send "working" when there is a new user message, since we know the
512
+ // LLM will begin work soon if it has not already.
511
513
if item .messageID > lastMessageID {
512
514
return codersdk .WorkspaceAppStatusStateWorking
513
515
}
514
- // Otherwise, if the state is "working" and there have been no new messages,
515
- // it means either that the LLM is still working or it means the user has
516
- // interacted with the terminal directly. For now, we are ignoring these
517
- // updates. This risks missing cases where the user manually submits a new
518
- // prompt and the LLM becomes active and does not update itself, but it
519
- // avoids spamming useless status updates.
516
+ // Otherwise, if the state is "working" and there have been no new user
517
+ // messages, it means either that the LLM is still working or it means the
518
+ // user has interacted with the terminal directly. For now, we are ignoring
519
+ // these updates. This risks missing cases where the user manually submits
520
+ // a new prompt and the LLM becomes active and does not update itself, but
521
+ // it avoids spamming useless status updates.
520
522
return ""
521
523
}
522
524
var lastPayload agentsdk.PatchAppStatus
@@ -599,12 +601,14 @@ func (s *mcpServer) startWatcher(ctx context.Context, inv *serpent.Invocation) {
599
601
return
600
602
}
601
603
case agentapi.EventMessageUpdate :
602
- err := s .queue .Push (reportTask {
603
- messageID : ev .Id ,
604
- })
605
- if err != nil {
606
- cliui .Warnf (inv .Stderr , "Failed to queue update: %s" , err )
607
- return
604
+ if ev .Role == agentapi .RoleUser {
605
+ err := s .queue .Push (reportTask {
606
+ messageID : ev .Id ,
607
+ })
608
+ if err != nil {
609
+ cliui .Warnf (inv .Stderr , "Failed to queue update: %s" , err )
610
+ return
611
+ }
608
612
}
609
613
}
610
614
case err := <- errCh :
0 commit comments