Skip to content

Add Gmail thread ID to queries, harden cache validation, and clean up API layer#104

Merged
wesm merged 1 commit intomainfrom
add-thread-id-to-mcp
Feb 7, 2026
Merged

Add Gmail thread ID to queries, harden cache validation, and clean up API layer#104
wesm merged 1 commit intomainfrom
add-thread-id-to-mcp

Conversation

@wesm
Copy link
Owner

@wesm wesm commented Feb 7, 2026

Summary

This started as adding Gmail thread IDs to MCP responses but grew to include cache validation hardening and API cleanup that came up along the way.

1. Gmail Thread ID (source_conversation_id) in query layer

  • Add SourceConversationID field to MessageSummary and MessageDetail models
  • DuckDB engine joins conversations parquet table; SQLite engine joins conversations table
  • Export conversations table to Parquet in build-cache (including Windows CSV fallback path)
  • MCP tools (list_messages, get_message, search_messages) now return source_conversation_id

2. Cache validation hardening

  • Shared RequiredParquetDirs list used by cache builder, TUI, and MCP startup
  • HasCompleteParquetData() checks all required tables exist (not just messages)
  • TUI and MCP use HasCompleteParquetData instead of HasParquetData — prevents DuckDB errors when tables like conversations are missing
  • missingRequiredParquet() detects partial/broken caches and triggers full rebuild (handles hive-partitioned messages layout)
  • buildCacheMu mutex prevents concurrent cache writes from parallel syncs
  • maxID > 0 gate avoids infinite rebuild loops for zero-message accounts
  • +482 lines of test coverage for cache edge cases

3. Remove dead config field and eliminate DTO duplication

  • Remove unused server.mcp_enabled config field (MCP is always available via msgvault mcp)
  • Replace duplicate APIMessage, APIAttachment, StoreStats, AccountStatus structs in internal/api with type aliases to store/scheduler types
  • Collapse ~80 lines of field-by-field adapter boilerplate in serve.go to direct pass-throughs
  • Add backward-compat test for old configs that still contain mcp_enabled

Test plan

  • All existing tests pass
  • New cache tests cover: backfill missing conversations, backfill missing messages, zero-message skip, incremental no-duplicates, hive-partitioned detection
  • MCP tests verify source_conversation_id in search/get/list responses
  • Config backward-compat test for deprecated mcp_enabled

Originally PR #76 (from @robelkin), squashed and rebased cleanly.

🤖 Generated with Claude Code

… API layer

1. Gmail Thread ID (source_conversation_id) in query layer:
   - Add SourceConversationID to MessageSummary and MessageDetail
   - DuckDB joins conversations parquet; SQLite joins conversations table
   - Export conversations to Parquet (including Windows CSV fallback)
   - MCP tools now return source_conversation_id

2. Cache validation hardening:
   - Shared RequiredParquetDirs for cache builder, TUI, and MCP startup
   - HasCompleteParquetData checks all required tables, not just messages
   - missingRequiredParquet detects partial caches and triggers rebuild
   - buildCacheMu mutex prevents concurrent cache writes
   - maxID > 0 gate avoids rebuild loops for zero-message accounts
   - +482 lines of cache edge-case tests

3. Remove dead config and eliminate DTO duplication:
   - Remove unused server.mcp_enabled config field
   - Replace duplicate API structs with type aliases to store/scheduler
   - Collapse ~80 lines of adapter boilerplate to pass-throughs
   - Add backward-compat test for old configs with mcp_enabled

Co-Authored-By: Rob Elkin <187335+robelkin@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wesm wesm force-pushed the add-thread-id-to-mcp branch from cff1256 to c934a99 Compare February 7, 2026 21:33
@wesm wesm merged commit d24c017 into main Feb 7, 2026
3 checks passed
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