feat: add mempalace_sync_status MCP tool and freshness hook#256
feat: add mempalace_sync_status MCP tool and freshness hook#256rusel95 wants to merge 6 commits intoMemPalace:developfrom
Conversation
PR Review: feat: add mempalace_sync_status MCP tool and freshness hookExecutive Summary
Affected Areas: Business Impact: AI agents calling Flow Changes: Adds a new read-only MCP tool in the SYNC/FRESHNESS section (between graph tools and write tools). No existing flows are modified. The tool scans all drawers via Ratings
PR Health
High Priority Issues(Must fix before merge) 🐛 #1:
|
| Feature | Depends On | Status |
|---|---|---|
tool_sync_status freshness detection |
content_hash in drawer metadata |
Missing — no miner writes it |
| Generated re-mine commands | --force CLI flag |
Missing — not in cli.py |
mempal_freshness_hook.sh |
mempalace sync --dry-run CLI |
PR #251 (not merged) |
| Shell hook on macOS | grep -P (GNU grep) |
Incompatible — macOS uses BSD grep |
Created by Octocode MCP https://octocode.ai 🔍🐙
8a3a542 to
a8f08fa
Compare
|
@bgauryy Rebased onto main and addressed all high-priority review items: Fixed:
All 124 tests pass. |
|
@bgauryy Pushed security and correctness fixes (99f0d4d):
All 135 tests pass. |
|
Updated with sync skill for Claude Code and Codex plugins. Here's the MCP sync status flow: flowchart TD
A[mempalace_sync_status MCP tool] --> B[Get palace collection]
B --> C[Scan drawers in batches of 500]
C --> D[Collect unique source files + content hashes]
D --> E{For each source file}
E --> F{File exists on disk?}
F -->|no| G[Mark as missing]
F -->|yes| H{Has stored content_hash?}
H -->|no| I[Mark as legacy — no hash]
H -->|yes| J[Compare file_content_hash vs stored]
J -->|match| K[Fresh ✓]
J -->|mismatch| L[Stale]
G --> M[Return sync report]
I --> M
K --> M
L --> M
M --> N["{ fresh, stale, missing, legacy, total }"]
Also added Ready for re-review. |
Exposes palace freshness checking to any AI agent via MCP. The tool compares content_hash stored in drawer metadata against current file content and returns structured JSON with stale/fresh/missing counts plus actionable re-mine commands. Also adds a Stop hook (mempal_freshness_hook.sh) that automatically checks palace freshness once per session and prompts the AI to call mempalace_sync_status if stale files are detected. Changes: - New MCP tool: mempalace_sync_status (read-only, no modifications) - Scans all source files for content changes via hash comparison - Returns status (fresh/stale/orphaned), counts, stale file list - Generates grouped re-mine commands - Supports directory filter for scoped checks - New hook: mempal_freshness_hook.sh - Fires on Stop event, checks freshness once per session - Blocks AI if stale files found, suggesting sync_status call - Configurable CHECK_DIR and CHECK_INTERVAL - 7 new MCP test cases covering empty, fresh, stale, missing, legacy, and directory-filtered scenarios Relates to MemPalace#224 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1. Return "unknown" status when all drawers lack content_hash instead of misleading "fresh" 2. Remove non-existent --force flag from generated re-mine commands 3. Replace grep -P (GNU-only) with sed in shell hook for macOS compat 4. Fix directory filter prefix matching with path boundary separator 5. Sanitize SESSION_ID in hook to prevent path traversal 6. Quote $CHECK_DIR in hook to handle paths with spaces 7. Use full file path in stale_files output instead of ambiguous basename 8. Fix test compatibility with upstream _patch_mcp_server signature Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
… non-empty hash 1. Critical: removed eval-based command execution in freshness hook — now runs python3 directly with quoted args. Added EXIT trap for guaranteed JSON output. 2. Critical: added 'partial' status when some files are fresh but others lack content_hash — prevents misleading 'fresh' for partially-unknowable state. 3. Use first non-empty hash per file in pagination — mixed-hash drawers no longer produce non-deterministic results. 4. Removed dead code branch in directory filter (file path != dir path). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
99f0d4d to
ff159f2
Compare
web3guru888
left a comment
There was a problem hiding this comment.
✨ Review of #256 — feat: add mempalace_sync_status MCP tool and freshness hook
Scope: +427/−0 · 3 file(s) · touches core
hooks/mempal_freshness_hook.sh(added: +88/−0)⚠️ mempalace/mcp_server.py(modified: +155/−0)tests/test_mcp_server.py(modified: +184/−0)
Technical Analysis
- 🔌 MCP server dispatch changes — verify JSON-RPC compliance and backward compatibility
- 🪟 Windows compatibility — verify path handling works cross-platform
Issues
⚠️ Hardcoded filesystem path — breaks portability⚠️ Touchesmempalace/mcp_server.py— Core MCP server — maintainer guards this closely
Suggestions
- Magic number(s) 2025, 2026 — consider extracting to named constant(s)
Strengths
- ✅ Includes test coverage
🟡 Needs attention — touches guarded files and has items to address.
🏛️ Reviewed by MemPalace-AGI · Autonomous research system with perfect memory · Showcase: Truth Palace of Atlantis
|
@igorls @bensig @milla-jovovich This PR is ready for initial review. All issues from the Octocode bot review have been addressed:
This is the MCP companion to #251 — Note: CI isn't running because the workflow only triggers on PRs targeting |
|
Local CI results (GitHub CI doesn't trigger on The 1 failure is unrelated ( Ruff clean for this PR's files — the 7 errors are all in #251's code ( |
Brings in tunnel functions, ChromaBackend, closets, halls, entity metadata, and other v3.2.0 changes. Keeps sync_status MCP tool alongside new tunnel tools. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Closing and reopening as a clean rebase onto current develop. The branch had accumulated several merge commits from upstream syncs. The new branch (feat/sync-mcp-tool-v2) is a clean single commit on top of current develop with all the same changes and all review fixes from @bgauryy applied. Dependency note: This tool requires content_hash to be stored in drawer metadata. Without it the tool returns status: unknown for all drawers — intentionally honest rather than falsely reporting fresh. The companion PR (feat/content-hash-foundation) should merge first to make this tool fully functional. |
Summary
Relates to #224 — Adds a read-only MCP tool that lets any AI agent check whether palace memories are up to date before trusting search results. Combined with the freshness hook, this creates an automatic "staleness awareness" loop.
This is the companion to #251 (CLI sync command). While
mempalace syncis for humans,mempalace_sync_statusis for AI agents — structured JSON output, no side effects, MCP-native.Changes
MCP Tool:
mempalace_sync_statusRead-only — reports freshness without modifying the palace. AI agents can use this to:
Hook:
mempal_freshness_hook.shStop hook that checks palace freshness once per session. If stale files are detected, blocks the AI from stopping and prompts it to call
mempalace_sync_statusfor details.Configurable:
CHECK_DIR— scope to a specific directoryCHECK_INTERVAL— minimum seconds between checks (default: 3600)Test plan
test_sync_status_empty_palace— empty palace returns "empty" statustest_sync_status_no_palace— missing palace returns errortest_sync_status_fresh_files— unchanged files detected as freshtest_sync_status_stale_file— modified file detected with correct name and re-mine commandtest_sync_status_missing_file— deleted source file reported as orphanedtest_sync_status_legacy_no_hash— legacy drawers without hash handled gracefullytest_sync_status_directory_filter— directory filter scopes check correctly🤖 Generated with Claude Code