Id
160
Agent
Content
## Code Review: PR #88 - Add list_agent_logs MCP Tool
### Summary: **PASS AUDIT** ✅
All acceptance criteria met. Implementation is comprehensive, well-tested, and follows existing patterns.
---
### Acceptance Criteria Status
| Criterion | Status | Evidence |
|-----------|--------|----------|
| New MCP tool `list_agent_logs` exists | ✅ PASS | Tool definition added at line 355 |
| Supports filtering by agent_id, ticket_id, status, date range | ✅ PASS | All filters implemented in handler |
| Supports pagination (limit, offset) | ✅ PASS | Limit/offset with defaults (50/0) |
| Supports sorting (created_at, duration_ms) | ✅ PASS | Sort by with asc/desc options |
| Tool available to orchestrator and researcher | ✅ PASS | Added to `session_tools` permission group |
| Returns structured log data | ✅ PASS | Response includes action, status, duration_ms, details |
---
### Changes Reviewed
**1. `app/controllers/api/v1/mcp_controller.rb`**
- Lines 355-376: New tool definition `list_agent_logs` with comprehensive parameters
- Lines 1072-1148: Handler `handle_list_agent_logs` with full implementation:
- Project-scoped query (prevents cross-project access)
- Filter by agent_id, ticket_id, status, action
- Date range filtering with error handling
- Sorting by created_at or duration_ms
- Pagination with limit/offset
- Rich response with metadata and structured log data
**2. `config/tinker/mcp_permissions.yml`**
- Added `list_agent_logs` to `session_tools` permission group
- Available to orchestrator, researcher, worker, reviewer
**3. `spec/requests/api/v1/mcp_spec.rb`**
- 16 new test examples covering all features:
- Basic listing scoped to project
- Filters: agent_id, ticket_id, status, action
- Date range filtering (from_date, to_date)
- Error handling for invalid dates
- Sorting by created_at and duration_ms
- Pagination (limit, offset)
- Structured data verification
- Worker access via session_tools
- Error when agent has no project
---
### Quality Assessment
**Code Quality:** ✅ EXCELLENT
- Follows existing MCP tool patterns
- Proper error handling for invalid date formats
- Clean parameterized queries (no SQL injection risk)
- Rich response structure with metadata (total_count, offset, returned_count, filter)
**Security:** ✅ PASS
- **Project-scoped query** - Critical security feature preventing cross-project access
- Uses parameterized queries throughout
- Permission group properly configured
- Validates agent has project_id
**Test Coverage:** ✅ COMPREHENSIVE
- 16 new test examples (PR reports 108 total, 16 new)
- Tests cover all filters, sorting, pagination
- Edge cases tested (invalid dates, no project, etc.)
- Permission tests verify access controls
**API Design:** ✅ EXCELLENT
- Flexible filtering options
- Intuitive pagination (limit + offset)
- Sensible defaults (limit: 50, offset: 0, sort_by: created_at desc)
- Rich response with filter echo and metadata
---
### Test Results
- **MCP specs:** 92 examples passed (on main branch, PR adds 16 more)
- **Full suite:** 690 examples, 2 pre-existing failures (unrelated dashboard UI issues)
---
### Implementation Highlights
**1. Project Scoping (Security Critical)**
```ruby
logs = AgentLog.where(agent_id: Agent.where(project_id: current_agent.project_id).select(:id))
```
This ensures agents can only view logs from their own project.
**2. Rich Response Structure**
```ruby
{
total_count:, # Total matching records
offset:, # Pagination offset used
returned_count:, # Number of records returned
filter: {...}, # Echo of applied filters
logs: [...] # Array of log entries
}
```
**3. Error Handling**
- Invalid date formats return clear error messages
- Agent without project returns meaningful error
---
### Recommendation
**PASS AUDIT** - This PR is ready to merge. The implementation is comprehensive, well-tested, secure, and follows all existing patterns. The `list_agent_logs` tool provides valuable functionality for the orchestrator and researcher to view agent activity history.
Comment type
code_review
Avo · © 2026 AvoHQ · v3.27.0