Skip to content

fix: surface human thread replies to MCP agents#6

Merged
alexgorbatchev merged 1 commit intomainfrom
fix/mcp-thread-replies
Mar 10, 2026
Merged

fix: surface human thread replies to MCP agents#6
alexgorbatchev merged 1 commit intomainfrom
fix/mcp-thread-replies

Conversation

@alexgorbatchev
Copy link
Owner

Summary

  • Fixed agentation_watch_annotations to detect thread.message SSE events from humans, not just annotation.created events. Agent replies are correctly filtered out so they don't trigger false wakeups.
  • Added getAnnotationsNeedingAttention store method that returns both pending annotations AND non-pending annotations where the last thread message is from a human (unread reply). Updated the /pending HTTP endpoints and SSE initial sync to use this broader check.
  • Added integration tests covering all thread reply visibility scenarios: acknowledged annotations with human replies, resolved annotations with human replies, agent-only replies not resurfacing, and SSE watcher detecting thread.message events.

Problem

When a human replied to an annotation thread, the agent could not see it because:

  1. The SSE watcher only listened for annotation.created events, ignoring thread.message entirely
  2. get_pending filtered by status='pending', so once acknowledged, any human reply was invisible

Test plan

  • New test: human reply to acknowledged annotation is visible via get_pending
  • New test: watch_annotations detects thread.message events from humans
  • New test: thread messages are included in get_session response
  • New test: multiple human replies all surface to the agent
  • New test: agent reply does NOT re-surface annotation as needing attention
  • New test: resolved annotation with human reply resurfaces for agent
  • All 825 existing package tests pass (no regressions)
  • MCP package builds successfully with no TypeScript errors

🤖 Generated with Claude Code

The MCP server's `agentation_watch_annotations` tool only watched for
`annotation.created` SSE events, ignoring `thread.message` events
entirely. Additionally, `agentation_get_pending` filtered by
status='pending', making human replies to acknowledged/resolved
annotations invisible to the agent.

Changes:
- Add `thread.message` event handling to `watchForAnnotations` so agents
  are notified when a human replies to a thread (agent replies are
  correctly filtered out)
- Add `getAnnotationsNeedingAttention` store method that returns both
  pending annotations AND non-pending annotations where the last thread
  message is from a human
- Update `/pending` HTTP endpoints and SSE initial sync to use the new
  method
- Add `ThreadMessage` and `thread` to the local Annotation type in
  mcp.ts for type safety
- Add integration tests covering all scenarios: acknowledged annotations
  with human replies, resolved annotations with human replies, agent
  replies not resurfacing, and SSE watcher detecting thread.message
  events

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alexgorbatchev alexgorbatchev merged commit bddc05a into main Mar 10, 2026
1 check passed
@alexgorbatchev alexgorbatchev deleted the fix/mcp-thread-replies branch March 10, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant