Add search_messages MCP tool and CLI command#23
Conversation
Exposes the existing FTS5 search capability via: - MCP tool: search_messages(query, limit) - CLI command: session-analytics-cli search <query> This completes the user message search functionality added in Phase 1, enabling consumers to find discussions about specific topics across sessions using full-text search. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Review: Add search_messages MCP tool and CLI commandOverall, this is a well-structured PR that exposes the existing FTS5 infrastructure to consumers. The implementation follows the project's established patterns. Here's my detailed feedback: ✅ What's Good
🔍 Suggestions for Improvement1. Missing CLI test coverageThe PR adds a test for the MCP tool but no dedicated test for the CLI
2. Error handling for malformed FTS5 queriesFTS5 queries can fail with syntax errors (e.g., unbalanced quotes, invalid operators). The current implementation will propagate SQLite exceptions directly. Consider: # In server.py or cli.py
try:
results = storage.search_user_messages(query, limit=limit)
except sqlite3.OperationalError as e:
if "fts5" in str(e).lower() or "syntax" in str(e).lower():
return {"status": "error", "error": f"Invalid FTS5 query syntax: {e}"}
raise3. Truncation in formatter could lose contextIn text = msg.get("message", "")[:60] if msg.get("message") else ""Consider adding text = msg.get("message", "") if msg.get("message") else ""
if len(text) > 60:
text = text[:57] + "..."4. Minor inconsistency in default limit
This is fine, but worth noting. The lower defaults for the exposed interfaces make sense for typical use. 5. Consider adding
|
- Add error handling for malformed FTS5 queries (catches sqlite3.OperationalError) - Update CLAUDE.md with search_messages and get_user_journey tools - Add ... suffix when truncating messages in formatters - Add CLI test coverage for search command (4 new tests) - Add --project filter to search command (CLI, MCP, and storage layer) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Review: Add search_messages MCP tool and CLI commandOverall, this is a well-structured PR that exposes the existing FTS5 infrastructure in a clean and consistent way. Here is my detailed feedback: Strengths
Issues & Suggestions1. Missing
|
PR Review: Add search_messages MCP tool and CLI commandOverall, this is a well-structured PR that properly exposes the FTS5 search capability. The implementation follows the existing patterns in the codebase and includes good test coverage. Here's my detailed review: Code Quality ✅Strengths:
Minor suggestion:
Potential Issues
|
- Add docstring note that search_messages only searches user messages, not assistant responses - Add explicit project = None to all test Args classes for completeness - Add test for --project filter in cmd_search 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Review: Add search_messages MCP tool and CLI commandOverall this is a well-structured PR that properly exposes the existing FTS5 infrastructure. The code follows the project's established patterns and includes good test coverage. ✅ Strengths
💡 Suggestions
|
Summary
search_messages(query, limit)MCP tool for full-text search on user messagessession-analytics-cli search <query>CLI command.gitignoreto exclude.worktrees/directoryMotivation
The FTS5 infrastructure was added in Phase 1 (PR #20), but wasn't exposed to consumers. This enables LLMs to search for specific topics, decisions, or patterns across session messages.
Example usage:
Test plan
search_messagesMCP tool🤖 Generated with Claude Code