Skip to content

fix(mcp): remove DefaultProject from reads, add date filters and input validation (#146)#213

Open
CTRQuko wants to merge 3 commits intoGentleman-Programming:mainfrom
CTRQuko:fix/mcp-search-date-filters-audit
Open

fix(mcp): remove DefaultProject from reads, add date filters and input validation (#146)#213
CTRQuko wants to merge 3 commits intoGentleman-Programming:mainfrom
CTRQuko:fix/mcp-search-date-filters-audit

Conversation

@CTRQuko
Copy link
Copy Markdown

@CTRQuko CTRQuko commented Apr 21, 2026

Summary

  • Fix MCP server search returns empty results while CLI works correctly (data exists in database) #146: mem_search and mem_context no longer fallback to DefaultProject on reads — searches across all projects when project is omitted
  • Date filters: since/until parameters for mem_search, mem_context, and new mem_sessions tool
  • Input validation: empty query guard (FTS5 crash), invalid date rejection, empty title/content in handleSave
  • HTTP API: /search now passes since/until to store (were silently dropped)
  • Import normalization: project names from external data are normalized on import

Bug Fixes

Bug Root Cause Fix
#146 — MCP search empty while CLI works handleSearch/handleContext replaced empty project with DefaultProject DefaultProject only applies to writes
FTS5 crash on blank query sanitizeFTS("") produces MATCH "" Guard rejects blank queries
Silent date filter bypass SQLite datetime("not-a-date") returns NULL validateDate() rejects invalid formats
SQL alias typo in topic_key path o.created_at but query has no o alias Removed alias prefix
HTTP /search drops date params since/until not passed to store.Search Added to SearchOptions
Import ignores project case Sessions/observations imported with original case NormalizeProject() on import

New Features

  • mem_sessions tool — list sessions by date range with observation counts
  • CLI --since/--until flags for engram search

Tests

28 new tests across 5 files:

  • mcp_bug146_test.go — 2 regression tests for MCP server search returns empty results while CLI works correctly (data exists in database) #146
  • mcp_date_test.go — 4 date filter tests
  • mcp_audit_test.go — 8 tests (empty input, concurrency, MCP-layer validation)
  • store_audit_test.go — 12 tests (FTS5, dates, private tags, normalization, SQL alias)
  • store_phase2_test.go — 9 tests (import normalize, export, merge, truncation)
  • server_phase2_test.go — 2 tests (HTTP date filter passthrough)

Breaking Changes

None for MCP clients. Three store functions now return errors where they previously silently ignored bad input:

  • Search() — rejects empty query and invalid dates
  • RecentSessions() — rejects invalid dates
  • RecentObservations() — rejects invalid dates

All callers (MCP handlers, HTTP handlers, CLI) already handle errors from these functions.

CTRQuko added 3 commits April 22, 2026 01:06
…t validation (Gentleman-Programming#146)

Bug fixes:
- mem_search/mem_context no longer fallback to DefaultProject on reads
- Empty FTS5 query guard prevents SQLite crash on blank search
- Invalid date strings (since/until) now return explicit error instead of silent bypass
- handleSave rejects empty title/content with clear error message
- SQL alias typo in topic_key search path with date filters (o.created_at -> created_at)
- HTTP /search now passes since/until params to store (were silently dropped)
- Import normalizes project names for sessions and observations

New features:
- mem_search: since/until date filters (YYYY-MM-DD or RFC3339)
- mem_context: since/until date filters
- mem_sessions: new tool to list sessions by date range
- CLI: --since/--until flags for search command

Tests: 28 new tests across 5 files
- mcp_bug146_test.go: 2 regression tests for Gentleman-Programming#146
- mcp_date_test.go: 4 date filter tests
- mcp_audit_test.go: 8 tests (empty input, concurrency, MCP-layer validation)
- store_audit_test.go: 12 tests (FTS5, dates, private tags, normalization)
- store_phase2_test.go: 9 tests (import normalize, export, merge, truncation)
- server_phase2_test.go: 2 tests (HTTP date filter passthrough)

Fixes Gentleman-Programming#146
…lete endpoints

- MCP Tools: 15 → 16 (added mem_sessions)
- mem_search: document since/until params and empty query guard
- mem_context: document since/until params
- mem_sessions: new tool section with all parameters
- HTTP API: added since/until to GET /search
- HTTP API: added DELETE /sessions/{id} and DELETE /prompts/{id}
- New section: Input Validation (dates, empty queries, required fields, import)
- FTS5 section: updated to include topic_key column and special char handling
…external KB)

New skill: engram-knowledge-recall
- 4-level retrieval chain: mem_context → mem_search → external KB → explicit 'not found'
- Agent-agnostic: works with any Obsidian MCP, Notion MCP, or file-based MCP
- Rehidration pattern: findings from KB are saved back to Engram for faster future recall
- Compaction recovery extended to include KB fallback

Integrated into all agent plugins:
- plugin/opencode/engram.ts — MEMORY_INSTRUCTIONS updated
- plugin/claude-code/skills/memory/SKILL.md — search section updated
- internal/setup/setup.go — memoryProtocolMarkdown updated (Gemini CLI, Codex)
- skills/catalog.md — registered
- AGENTS.md — registered with trigger description
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.

MCP server search returns empty results while CLI works correctly (data exists in database)

1 participant