# MCP Monitoring Patterns

## Event Polling vs. Event Wait

### `events_poll`
- Returns all queued events since last cursor
- Use for checking recent activity
- Returns: `{"result": "events: N", "structuredContent": {"events": [...]}}`
- Each event has: `messageSeq`, `role`, `raw`, `cursor`

### `events_wait`
- Blocks until a new event arrives or timeout
- Use when waiting for FRIDAY to complete a task
- Recommended timeout: 60000-120000ms (1-2 minutes)
- Returns: `{"result": "event 1", "structuredContent": {"event": {...}}}`

## Message Reading

### `messages_read(session_key)`
- Returns all messages in a conversation
- Can be very large (100KB+) — FRIDAY's search results include full web content
- Use when you need to see FRIDAY's complete thought process and results
- Structure: `{"result": "messages: N", "structuredContent": {"messages": [...]}}`
- Each message has: `role` (assistant/user/toolResult), `__openclaw.seq`, `timestamp`

### Interpreting FRIDAY's Activity
- `role: "assistant"` with `toolCall` → FRIDAY is executing a tool
- `role: "toolResult"` → FRIDAY got results from a tool
- `role: "assistant"` with `text` → FRIDAY is explaining or responding
- Look for `seq` numbers increasing to track progress

## Conversation Discovery

### `conversations_list(limit=10)`
- Returns active conversations with their `sessionKey`
- Typical session key format: `agent:main:main`
- The `to` field shows the channel (e.g., `telegram:1344779884`)
- Use the `sessionKey` from here for all subsequent operations

## Common Patterns

### Pattern 1: Send Task and Monitor
```
1. conversations_list → get sessionKey
2. messages_send(sessionKey, text="task")
3. events_wait(timeout_ms=120000) → wait for activity
4. events_poll → check for new events
5. messages_read → get complete results
```

### Pattern 2: Check if FRIDAY is Busy
```
1. events_poll(limit=10) → check last few events
2. If last event is assistant toolCall → FRIDAY is still working
3. If last event is toolResult → FRIDAY got results, may be processing
4. If last event is assistant text → FRIDAY may have completed
```

### Pattern 3: Follow-up After Timeout
```
1. If CLI command timed out, don't assume failure
2. Use events_poll to check if FRIDAY is actually processing
3. FRIDAY's web_search results may contain the data you need
```
