Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add status watcher to MCP server#18320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
code-asher merged 15 commits intomainfromasher/report-task
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
5cee4c4
Add queue util
code-asherJun 10, 2025
1b3b734
Make createAgentClient use token file and errors
code-asherJun 10, 2025
722475c
Use common flags for agent client in MCP server
code-asherJun 11, 2025
56c41c8
Add status watcher to MCP server
code-asherJun 11, 2025
2cd3b45
Preserve URI only if message was blank
code-asherJun 12, 2025
9ec6ded
Test summary and link
code-asherJun 12, 2025
3d56d18
Fix lying comment
code-asherJun 12, 2025
c8dc0dd
Only report user messages
code-asherJun 12, 2025
bf78f1a
Increase queue to 100
code-asherJun 12, 2025
32f6eb9
Push and return seems fine
code-asherJun 12, 2025
f4e06c6
Configure LLM agent URL
code-asherJun 12, 2025
8dcada5
Add test for duplicate complete
code-asherJun 12, 2025
6d40d40
Check against last successfully submitted status
code-asherJun 12, 2025
866b721
Move update predicates to push phase
code-asherJun 12, 2025
a79ee72
Rename LLM to AI
code-asherJun 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Only report user messages
  • Loading branch information
@code-asher
code-asher committedJun 12, 2025
commitc8dc0dd7e94e347c331519bd15ff0cbea9e57d3b
34 changes: 19 additions & 15 deletionscli/exp_mcp.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -493,6 +493,9 @@ func (r *RootCmd) mcpServer() *serpent.Command {
}

func (s *mcpServer) startReporter(ctx context.Context, inv *serpent.Invocation) {
// lastMessageID is the ID of the last *user* message that we saw. A user
// message only happens when interacting via the API (as opposed to
// interacting with the terminal directly).
var lastMessageID int64
shouldUpdate := func(item reportTask) codersdk.WorkspaceAppStatusState {
// Always send self-reported updates.
Expand All@@ -505,18 +508,17 @@ func (s *mcpServer) startReporter(ctx context.Context, inv *serpent.Invocation)
codersdk.WorkspaceAppStatusStateFailure:
return item.state
}
// Always send "working" when there is a new message, since this means the
// user submitted a message through the API and we know the LLM will begin
// work soon if it has not already.
// Always send "working" when there is a new user message, since we know the
// LLM will begin work soon if it has not already.
if item.messageID > lastMessageID {
return codersdk.WorkspaceAppStatusStateWorking
}
// Otherwise, if the state is "working" and there have been no newmessages,
// it means either that the LLM is still working or it means the user has
// interacted with the terminal directly. For now, we are ignoring these
// updates. This risks missing cases where the user manually submits a new
// prompt and the LLM becomes active and does not update itself, but it
// avoids spamming useless status updates.
// Otherwise, if the state is "working" and there have been no newuser
//messages,it means either that the LLM is still working or it means the
//user hasinteracted with the terminal directly. For now, we are ignoring
//theseupdates. This risks missing cases where the user manually submits
//a newprompt and the LLM becomes active and does not update itself, but
//itavoids spamming useless status updates.
return ""
}
var lastPayload agentsdk.PatchAppStatus
Expand DownExpand Up@@ -599,12 +601,14 @@ func (s *mcpServer) startWatcher(ctx context.Context, inv *serpent.Invocation) {
return
}
case agentapi.EventMessageUpdate:
err := s.queue.Push(reportTask{
messageID: ev.Id,
})
if err != nil {
cliui.Warnf(inv.Stderr, "Failed to queue update: %s", err)
return
if ev.Role == agentapi.RoleUser {
err := s.queue.Push(reportTask{
messageID: ev.Id,
})
if err != nil {
cliui.Warnf(inv.Stderr, "Failed to queue update: %s", err)
return
}
}
}
case err := <-errCh:
Expand Down
25 changes: 15 additions & 10 deletionscli/exp_mcp_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -790,11 +790,12 @@ func TestExpMcpReporter(t *testing.T) {
}
}

makeMessageEvent := func(id int64) *codersdk.ServerSentEvent {
makeMessageEvent := func(id int64, role agentapi.ConversationRole) *codersdk.ServerSentEvent {
return &codersdk.ServerSentEvent{
Type: ServerSentEventTypeMessageUpdate,
Data: agentapi.EventMessageUpdate{
Id: id,
Id: id,
Role: role,
},
}
}
Expand All@@ -813,7 +814,7 @@ func TestExpMcpReporter(t *testing.T) {
return
}
// Send initial message.
send(*makeMessageEvent(0))
send(*makeMessageEvent(0, agentapi.RoleAgent))
listening <- send
<-closed
}))
Expand DownExpand Up@@ -902,13 +903,17 @@ func TestExpMcpReporter(t *testing.T) {
URI: "https://dev.coder.com",
},
},
// Terminal becomes active again according to the screen watcher, but
//message length is the same. This could be the LLM being active again,
//but itcould also be the user messing around. We will prefer not
//updating thestatus so the "working" update here should be skipped.
// Terminal becomes active again according to the screen watcher, but no
//new user message. This could be the LLM being active again, but it
// could also be the user messing around. We will prefer not updating the
// status so the "working" update here should be skipped.
{
event: makeStatusEvent(agentapi.StatusRunning),
},
// Agent messages are ignored.
{
event: makeMessageEvent(1, agentapi.RoleAgent),
},
// LLM reports that it failed and URI is blank.
{
state: codersdk.WorkspaceAppStatusStateFailure,
Expand All@@ -923,10 +928,10 @@ func TestExpMcpReporter(t *testing.T) {
{
event: makeStatusEvent(agentapi.StatusRunning),
},
// ... but this timethe message length has increasedso we know there is
//LLMactivity. This time the "working" update will not be skipped.
// ... but this timewe have a new user messageso we know there is LLM
// activity. This time the "working" update will not be skipped.
{
event: makeMessageEvent(1),
event: makeMessageEvent(2, agentapi.RoleUser),
expected: &codersdk.WorkspaceAppStatus{
State: codersdk.WorkspaceAppStatusStateWorking,
Message: "oops",
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp